Install on Next.js
Add a 3D product configurator to Next.js in about fifteen minutes. It works with the App Router and the Pages Router, and with headless Shopify or BigCommerce products.
Before you start
- Access to the Next.js code and a deployment.
- A server or job that can send your products to our API, or a JSON or CSV file.
- Headless Shopify: send Shopify's numeric product and variant IDs in your feed (the Shopify app syncs them by itself once it is in the Shopify App Store).
Create your account
Choose a plan on the pricing page and copy your publishable key from the dashboard Install page.
Send your products
Push products with the connector API from your server, or upload a JSON or CSV feed.
Give your products their size
Send width, depth, height and unit with each product. Dashboard > Products > Estimated sizes lists what still needs a size.
Load the launcher
Add a next/script tag with type module to the root layout.
Render the element
Render ti-spatial-launcher with the product ID in the product page and declare its JSX type.
Connect the cart
Answer the ti-spatial:add-to-cart event in a client component with your cart.
Create your first 3D model
Dashboard > Scene editor, step 5 Exact 3D model: Create the 3D model from the product photo, Use this model, then Save scene.
Deploy and verify
Deploy, open a product page in the browser, then run Verify installation in the dashboard.
Load the launcher script on every page
app/layout.tsx. Pages Router: the same <Script> in pages/_app.tsx.
import Script from 'next/script';
export default function RootLayout({children}: {children: React.ReactNode}) {
return (
<html lang="en">
<body>
{children}
<Script src="https://spatialconfigurator.com/widget/v1/ti-spatial.js" type="module" strategy="afterInteractive" />
</body>
</html>
);
}
Declare the element for TypeScript
types/ti-spatial.d.ts. React 19 types shown; on React 18 put the same interface in declare global { namespace JSX { … } }.
// types/ti-spatial.d.ts
import type {DetailedHTMLProps, HTMLAttributes} from 'react';
type Launcher = DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement> & {
store: string; product?: string; sku?: string; handle?: string; variant?: string;
platform?: string; position?: string; 'cart-url'?: string;
};
declare module 'react' {
namespace JSX {
interface IntrinsicElements {
'ti-spatial-launcher': Launcher;
}
}
}
Place the launcher on product pages
Render the element in the product page (a server component is fine: it is plain markup).
// app/products/[handle]/page.tsx
<ti-spatial-launcher key={product.id} store="pk_your_publishable_key" product={String(product.id)} platform="universal" />
Connect the cart
In a client component, answer the add-to-cart event with your cart.
'use client';
import {useEffect} from 'react';
export function SpatialCart({addLines}: {addLines: (lines: any[]) => Promise<void>}) {
useEffect(() => {
const add = (event: any) => event.detail.respondWith(addLines(event.detail.lines).then(() => ({success: true})));
document.addEventListener('ti-spatial:add-to-cart', add);
return () => document.removeEventListener('ti-spatial:add-to-cart', add);
}, [addLines]);
return null;
}
Good to know
- With a nonce-based CSP in middleware, pass the nonce to <Script nonce={nonce}>.
Replace pk_your_publishable_key with your own key: the dashboard Install page shows these steps with your key filled in, scans your site and verifies the installation.
Stuck? Write to support@spatialconfigurator.com and we help you finish the setup.
Pages Router
Not on the App Router yet? Load the loader in pages/_app.tsx and render the element in the product page; the cart listener is the same client component.
// pages/_app.tsx
import type {AppProps} from 'next/app';
import Script from 'next/script';
export default function App({Component, pageProps}: AppProps) {
return (
<>
<Component {...pageProps} />
<Script src="https://spatialconfigurator.com/widget/v1/ti-spatial.js" type="module" strategy="afterInteractive" />
</>
);
}
// pages/products/[handle].tsx
<ti-spatial-launcher key={product.id} store="pk_your_publishable_key" product={String(product.id)} platform="universal" />
Server components, static pages and route changes
- The element is plain markup, so a server component can render it. Only the add-to-cart listener needs a client component ('use client').
- Static export (output: 'export'), ISR and the full-route cache work as they are: the markup is the same for every visitor and the launcher loads its product data in the browser.
- On a client-side route change the loader stays in the page; key={product.id} makes React create a new element, so the launcher never keeps the previous product.
- strategy="afterInteractive" loads the loader right after hydration. lazyOnload delays it until the browser is idle, and the launcher button with it.
- The launcher's pictures come from our service, so next.config.js needs no images.remotePatterns entry for them.
Headless Shopify: the Storefront API cart
With Shopify as the backend, send Shopify's numeric product and variant IDs in your feed. The studio's lines then carry the variant ID that cartLinesAdd needs; pass them to the function your storefront already uses for its cart.
// lib/spatial-cart.ts: give it to <SpatialCart addLines={addSpatialLines} />
import {addCartLines} from './shopify'; // your existing cartLinesAdd call
export async function addSpatialLines(lines: {variantId: string; qty: number}[]) {
await addCartLines(
lines.map((line) => ({
merchandiseId: `gid://shopify/ProductVariant/${line.variantId}`,
quantity: line.qty,
})),
);
}
Content Security Policy
- A CSP set in middleware.ts or next.config.js headers must allow our sources: the dashboard Install page lists them for script-src, style-src, connect-src and img-src (with data: and blob:).
- Nonce-based CSP: give the same nonce to <Script nonce={nonce}>. The loader adds the studio as a module from the allowed source, so 'strict-dynamic' needs no other change.
- After you deploy, open a product page with the browser console open: a blocked source shows up there as a Content Security Policy error naming the directive.
Give your products their real size
The launcher shows only on products with a 3D scene, and a product with a size gets an automatic 3D preview. So sizes come first.
- Send the outside size of each product: dimensions with width (left to right), depth (front to back), height and unit in the JSON feed, or the width, depth, height and unit columns of the CSV. The unit is cm or in; the CSV also takes mm, m, ft and yd.
- No size fields? A size written in the title or description, such as 180 x 90 x 75 cm, is read too. Otherwise the typical size of the product type is used and shoppers see an estimated size.
- Dashboard > Products > Estimated sizes lists the products to measure. Fix them in your feed, or open one in the Scene editor and fill in step 2, Measured product size.
- Settings > Automation > Products Without Measured Sizes decides whether a product without a size gets a preview at all.
Create your first 3D model
A measured product already shows a generated stand-in at its size. A model made from the product photo looks closer to the real product, also in AR (Android phones need one for AR); it is an approximation, so check it before you use it.
- Open the Scene editor and find the product by SKU or name.
- Check step 1, Experience, and step 2, Measured product size.
- In step 5, Exact 3D model, choose Create the 3D model. The free built-in generator makes an approximate model from the product photo in seconds. For the most realistic models, connect your own Meshy account (Settings > 3D Models from Photos): it builds a full 3D model with the sides and back completed by AI in one to five minutes, charged per model by Meshy.
- For the built-in generator, use a photo with a plain one-colour background (white or light) up to the edges and clearly different from the product, the product straight from the front, whole, alone and with a margin, at least about 1000 px on its longest edge. Enter the measured size and the right product type first: the depth comes only from the measurement. The scene editor lists these tips under Photo tips for the built-in generator.
- Turn the model in the preview. If it faces the wrong way, use the turn buttons. Then choose Use this model.
- Switch on Live for shoppers and choose Save scene. Step 5 also takes your own GLB file.
- Not a box? In step 3, Shape gives the product its outline seen from above: round, oval, L-shaped with the return on the left or right as seen from the front, or U-shaped. An L sofa then leaves its corner free for a coffee table and a round table touches others at its rim. With a 3D model the outline comes from the model unless you choose one.
Add a room planner page (Pro plan or higher)
Shoppers pick a room, start from a layout made of your products and add the whole room to the cart.
- Dashboard > Room planner: switch on Show the room planner to shoppers, choose the room types and copy the snippet.
- Paste the element on a page of its own. The loader is already on every page.
- Logged-in customers can save designs when your server signs a customer token with the signing secret (Install > Room planner signing secret). Without server code, add designs="off" to the element: shoppers plan and buy, but do not save.
- Add all to cart uses the same cart connection as the launcher.
- Enter the page address under Room planner > Planner page address, so the 3D studio links to it with Plan your room.
- Dashboard > Products for room objects: link your fireplaces, curtains and blinds, rugs, wall shelves and wall art to the planner's objects of the same kind, so shoppers place and buy them. Curtains hang at a window and take its width; a fireplace keeps the floor in front of it clear.
Let shoppers plan from a photo of their room (Pro plan or higher)
A shopper who wants a table photographs the room without it, from one to six angles: the studio rebuilds an estimate of the room in 3D with everything in the photos and places the table in it.
- Connect your own AI engine: Dashboard > Settings > AI Assistance, choose the engine, paste your API key and pick a text model that reads images. Your provider bills each photo to your account.
- Keep Settings > Shopper Tools > Plan from a Room Photo on (it is on by default); the two limits below it cap the photos per visitor and per day.
- The launcher then shows a second button, See it in your room, under Try it in 3D. It opens the 3D room view at the photo step: the shopper takes or chooses 1 to 6 photos of the room (one from each corner, the first facing the wall where the product goes), the room is rebuilt with their furniture, and the product stands in it (in the place of their old one of its kind, else against a wall or in a free spot). Settings > General > "See It in Your Room" Button hides the button; the studio keeps its Your room photo tab.
- Shoppers take the photos right in the studio: Take photos opens the camera of their phone, tablet or laptop (the rear camera on phones), says what to photograph next (first the wall where the product goes, then each corner) and shows the photos taken. See it in your room opens the photo card with its tips; the camera or the gallery opens only when the shopper chooses Take photos or Choose from gallery. Choose from gallery takes photos they already have. Where a page cannot use the camera (an old browser, a page over http, the theme editor preview), phones open their own camera app instead.
- More photos give a truer room: each wall in its own colour, the doors and windows of every wall (also the one behind the first photo; window walls, picture windows, sliding glass and French doors by their style), the floor, and furniture, fireplaces and stoves, rugs, curtains and blinds at their windows, wall art, lamps, plants and shelves in their colours, each piece once even when several photos show it. Before the room is built the shopper sees what was found on each wall and can correct the size. It stays an AI estimate built with the planner's own furniture models, not a scan, and shoppers see a note to measure walls, doors and windows before they buy.
- All photos of one room are read in one request: they count as one photo in the daily limits, and your AI provider bills one request with several images.
- Dashboard > Settings, Room planner and Install show Plan from a room photo: On or Off with the reason (plan, switched off, no AI key, no text model) and a link that fixes it.
- One launcher without the button: add room-photo="off" to its <ti-spatial-launcher> element.
Check the result
- Open a product page in a private window, logged out. A product with a 3D scene shows Try it in 3D.
- Open the studio: turn the product and check its size.
- On a phone, View in your space shows the product in your room at its real size (AR).
- Dashboard > Install > Verify installation with your home page and a product page. When every check passes, the store is marked as installed.
- Dashboard > Setup guide shows what is still missing.
- Try Add to cart in the studio: the product must arrive in your cart.
Updates and removal
- Updates need nothing from you: the loader always loads the current release, and nothing has to be purged after our releases.
- Change your plan on Dashboard > Billing. Paid plans start with a free trial; a cancelled plan runs to the end of the period, then the store is on the free plan.
- A secret key was exposed? Install > API keys > Create a new secret key. The old key stops working at once.
- To remove it, delete the loader and the launcher code (and a planner element, if you added one), publish, and purge your page cache.