The ring builder's JavaScript SDK
Load ring-builder.js from your 3JD address and call RMJRingBuilder.mount with your builder's slug. The SDK draws the builder in an iframe, sizes it to its content, and calls your functions when the shopper changes the ring, shares it or adds it to the cart. Return false from onAddToCart to write the cart line yourself, or let the SDK do it on Shopify.
3D Jewelry Designer7 min read
Mount a builder
Copy your builder's slug from Dashboard → Embeds, then:
<div id="ring"></div>
<script src="https://3djewelrydesigner.com/ring-builder.js"></script>
<script>
var builder = RMJRingBuilder.mount("#ring", {
slug: "YOUR_EMBED_SLUG",
onSelection: function (s) { showPrice(s.priceCents, s.currency); },
onAddToCart: function (s, instruction, meta) { /* see below */ },
});
</script>
Without any JavaScript of your own, a container works too. The SDK finds it when the page loads:
<div data-rmj-ring-builder data-rmj-slug="YOUR_EMBED_SLUG" data-rmj-height="640px"></div>
<script src="https://3djewelrydesigner.com/ring-builder.js"></script>
The data attributes are data-rmj-slug, data-rmj-base, data-rmj-height,
data-rmj-min-height, data-rmj-max-height, data-rmj-fit,
data-rmj-datalayer and data-rmj-address ("off" keeps your page's address as
it is).
Options
| Option | What it does |
|---|---|
slug | Your builder's slug. Required. |
baseUrl | The 3JD address to load from. Defaults to the address the script came from. |
height | The starting height: a number of pixels, any CSS length, "auto", or { mobile, tablet, desktop }. |
minHeight, maxHeight | Limits on the height the builder asks for. |
autoResize | true or false to force resizing on or off. Left out, the builder decides from its own layout setting. |
fit | "viewport" keeps a frame you sized to the screen as it is. |
autoCart | false stops the SDK writing the cart line, so only your onAddToCart runs. |
loading | "eager" or "lazy". Left out, a builder near the top of the page loads at once and one far below waits until it is close. |
borderRadius, title | The frame's corner radius and its accessible title. |
resume | A shared-design token. Left out, the SDK reads ?c= from your page's address, so a shared link opens the shared ring. |
currency | The shopper's currency, such as "EUR". Left out on a Shopify store, the SDK passes the store's active currency. The builder prices from your price book in that currency when you have one, else from its default book. |
dataLayer | true, or the name of your own array: each builder event is also pushed to the page's dataLayer, for Google Tag Manager. |
address | false keeps your page's address as it is. Otherwise (2.14 and later), when the builder's Carry the ring in your page's address is on, your page's address names the ring as it is built (setting, metal, shape, carat, and e, the link that reopens it exactly), keeping your own parameters. A page opened with those words and no link opens that ring. |
previewTheme | A theme preview token, to show that theme's draft in the builder. Left out (2.15 and later), the SDK reads ?3jd_theme= from your page's address, so a preview link works on any page that shows the builder. |
theme | false ignores theme preview links on this page. |
inheritStyles | false stops the builder from taking your page's colours and font. It also stops Match my store (2.16 and later): the page's colours, fonts and font files the builder reports so you can make a theme from them in the editor. And it stops Look like my store (2.17 and later): with it on, the builder takes your page's fonts with their files, its colours and its buttons' colour, corners, capitals, letter spacing and weight by itself, starting from the look it last saw on your store. With false the builder keeps its own look. |
Callbacks
onReady(): the builder has loaded.onSelection(selection): every change the shopper makes.onAddToCart(selection, instruction, meta): the shopper pressed the cart button.metaholdsquoteToken,properties(the line-item properties),sku,priceCentsandcurrency. Returnfalseto stop the SDK from writing the cart itself.onShare(selection, url): the shopper shared the ring;urlreopens it.onEnquiry(selection): on a builder set to Send an enquiry, the shopper sent the form. The enquiry is already in your Leads.onResize(height, data): the frame changed height.onAdded(instruction)andonError(error): after the SDK wrote a Shopify cart line, or failed to.
The selection
{
"band": "classic-round",
"shape": "Round",
"setting": "cp",
"carat": 1,
"metal": "yellow_gold_14k",
"variant": null,
"engraving": { "text": "Always", "font": "serif", "position": "inside" },
"sku": "RB-RND-100-14Y",
"priceCents": 248000,
"currency": "USD"
}
shape, setting and carat are the values in your own catalogue, and gem
is there when the builder offers a gem choice. sku and priceCents come from
our server, not from the shopper's browser (price is the same total in whole
units, kept for older pages: use priceCents). On add to cart the selection also has quoteId, the lead
saved for that add. engraving is null when there is none.
Writing the cart yourself
On Shopify the SDK writes the cart line for you: it finds or makes the right
variant and adds it, then sends the shopper to the cart or checkout if your
builder is set to. A ring on your own variant with a chosen diamond can come
as instruction.mode "items": the setting and the diamond as two lines,
which the SDK (2.13 and later) adds in one request. With the builder's own checkout (hosted) or a Shopify draft
order (draft) it opens that page. Otherwise instruction.mode is "event"
and the add is yours to make. Use meta.sku and meta.priceCents, and put
meta.properties on the line so the order can be traced back to the builder.
If your server sets the line price, check it first: send meta.quoteToken to
POST /api/public/ring-builder/verify as { "token": "…" }. The answer is
{ "valid": true, "sku", "priceCents", "currency", "expiresAt" } for a genuine
quote, and { "valid": false } for a changed or expired one. When the price
includes a centre stone, the answer also has stone: feed: and the certified
stone's id, or set: and the quality tier with its carat. The same value is on
the cart line as _rmj_stone. No API key is needed: the token is the proof.
Each line also has _rmj_line, its own id, and _rmj_edit_url: your page with
the ring open on Review and rmj_line in its address. On a page opened from
that link the SDK (2.13 and later) tells the builder, whose button then reads
Update cart, and once the new line is added it takes the old one out of the
Shopify cart, keeping its quantity. A host that writes its own cart reads
rmj_line from its page address and the new line's id from
meta.properties._rmj_line. To show the links on the cart, see
Edit a ring from the cart.
A ring and its band
On a builder that offers matching bands, the shopper can add a band to the ring
and buy both as a set. onAddToCart then receives the whole set: its first
argument is { items, totalCents, discountCents, currency }, where each item
has key, sku, listCents, discountCents, priceCents and properties,
and meta.basketToken is the signed set. To check it, send it to the same
verify address as { "token": "…", "accept": ["basket"] }.
On Shopify the SDK adds every line at once, or opens one draft order or one checkout for the whole set. A set is never split: if one line can't be added, none is. The SDK tells the builder its version when it loads, so a page still running an older copy is never sent a set it can't add.
Google Tag Manager
With dataLayer: true the SDK pushes the builder's events to window.dataLayer
(or to the array you name), so your own analytics can count them. Each push has
event and rmj_embed (the builder's slug):
| Event | When | Also has |
|---|---|---|
rmj_ready | The builder has loaded. | |
rmj_selection | The shopper changed the ring. | rmj_sku, rmj_value, rmj_currency, rmj_shape, rmj_metal |
rmj_add_to_cart | The shopper pressed the cart button. | the same |
rmj_share | The shopper shared the ring. | the same |
rmj_enquiry | The shopper sent an enquiry (a builder set to Send an enquiry). | the same |
rmj_try_on | The shopper opened try-on. |
rmj_value is the price in whole units: 2480 where the selection's priceCents is 248000.
The names start with rmj_ so they never double your store's own events: map
them to your tags in Tag Manager. Nothing is pushed unless you turn this on.
The handle
mount returns an object with:
iframe: the frame element.remeasure(): ask the builder to report its height again, for example after a tab or an accordion around it opens.destroy(): remove the frame and every listener the SDK added.
RMJRingBuilder.version is the script's version.
Media Only embeds
A Media Only embed (a 360° hero and captured stills, no cart) mounts with
RMJRingBuilder.mountMedia("#media", { slug, fallback }), or with
<div data-rmj-media data-rmj-slug="…">. fallback is a selector for your
own product gallery: it is hidden while the 3D view loads and shown again if
the view cannot run. columns sets the number of still tiles in a row, and
onFail(reason) tells you when the fallback was used.
mountMedia returns a handle whose setSelection(selection) tells the view
which design the page shows, in the page's own words. A ring needs only its
design or SKU: { band: "50924", sku: "50924-14Y" }. Any other kind of jewelry
also names its category, with its design and its own options:
media.setSelection({ type: "Wedding band", design: "50924", root: { width: "6 mm", audience: "Women" } });
type takes the category's name as your store writes it ("Wedding band",
"Wedding bands", "wedding_band"). A page that names no category is a ring page
and only shows rings, so a ring and its matching band can share a number. The
same keys work in the embed's address: ?type=wedding_band&design=50924&width=6mm.
A band's selection then carries builderType, design and root (its options in
words, such as { "width": "6 mm" }) in place of a shape and carat, and its
caption can use {width} and {profile} where a ring's uses {carat} and {shape}.
With Matching bands on the product page on, onLook(look) (2.18 and later)
hears the bands the shopper stacks beside the ring, and an empty list when they
come off:
{
"ring": { "band": "50924", "sku": "50924-14Y" },
"items": [
{ "side": "proximal", "band": "50924-6-mm-women", "design": "50924", "type": "wedding_band",
"name": "50924 6 mm Women", "sku": "50924-6-MM-WOMEN", "width": "6 mm",
"metal": "yellow_gold_14k", "metalValue": "14K Yellow", "matched": true }
]
}
Use sku or design with width to find each band's own product on your store.
metalValue is your own word for the ring's metal when the band wears it.
On Shopify, RMJRingBuilder.shopifySelection(product, variant, { category, design })
(2.19 and later) builds that selection from Shopify's product JSON
({{ product | json }}): a ring by its SKU, with its metal, shape and carat in
your words; any other category by its type, its design and its width. A
selection set before the view has loaded is sent as soon as it is ready
(2.19 and later).
A frame you write yourself can put the band on without a tap: matching=1 in its
address stacks the ring's first matching band, and matching= with a band's SKU,
slug or name (two at most, comma-separated) stacks those. A band the ring isn't made
to match is left out, and onLook hears the band as if the shopper had added it.
Listening without the SDK
A plain <iframe> of the builder sends the same events with
window.postMessage. Each message has source: "rmj-ring-builder" and a
type: ready, selection, addToCart, share, resize, tryon-open or
tryon-close. Check event.origin is your 3JD address before you use one.
Related
Related
- How an integration fits together
From a shopper building a ring to the order in your systems: what runs where, which price to trust, and how products and 3D models stay in step.
- Webhooks: events, payloads and signatures
Send leads, saved designs, carts and orders to your CRM or backend as signed webhooks, and check each delivery with a few lines of code.
- What you sell: the jewelry on your dashboard
Tell us which jewelry you sell, so your dashboard shows the tools for those types. Change it at any time in Settings or over the API.