Skip to main content

Custom webshop integration guide

You want to see the Retraced widgets in your custom webshop? Find out how to get started!


Prerequisites

You must first send us your actual store URL like mybrand.com to be whitelisted. You can either write us directly here via message or contact your dedicated Customer Success Manager.

Further, there must be already one product with an active product story on the Retraced dashboard, which is publicly available on your website.

Your products don’t need an SKU. You can use the SKU, variant or style code you already have in Retraced.

Additionally, you must grant us access to your web shop to facilitate issue diagnosis and troubleshooting. Please note that debugging and investigative support within your shop is not included in your standard service fee and will be billed separately.


Installation

We have 2 methods of product identification to enable you to get your product data. Using product code OR productExtendedIdentifier :

Using product code:

You can use the code of the SKU, the variant or the style. Retraced looks for the code in this order: SKU → Variant → Style, among products with an active product story. The first match is shown.

The basic data layer

To get started, you can:

<script name="retraced-tag"> 
window.retraced = {
shop: "<?php echo $your_domain; ?>",
initialSku: "<?php echo $your_sku; ?>",
locale: "<?php echo $detected_locale; ?>" || (window.navigator ? window.navigator.language : "en") };
</script>
<script async src="https://rtcd.me/shop-components.js"></script>

To fill out the correct information follow this table:

Variable

Explanation

Type

Example

window.retraced.initialSku

The first selected product code (SKU, variant or style code) when entering the product page.

String

0736347156260

window.retraced.shop

The host (not the full URL) of your shop. Typically what's in the browser URL bar, like mybrand.com, or www.otherbrand.com.

String

mybrand.com

window.retraced.locale

The locale of your shop. You can fallback to the window.navigator locale.

String

en

This will already give you a solid result for the initial page view.

The extended data layer

This is necessary if you want to implement variation changes for Retraced. For example, in case the colours of a product are showing different supply chains, you must use this approach.

Besides the basic data layer, we need the following:

For PHP:

<script name="retraced-tag"> 
window.retraced = {
...
variants: <?php echo json_encode($your_variants); ?>
};
</script>

For templated HTML like Shopify it looks like this:

<script name="retraced-tag">
window.retraced = {
...
variants: {{product.variants | json}}
};
</script>

Have a look at what the data structure must look like.

Variable

Explanation

Type

Example

window.retraced.variants

The variants of the shop.
It contains objects of variant ID and the matching product code (SKU, variant or style code).

Array

[
{id: "123", sku: "mysku-123"},
{id: "456", sku: "m4y5s6k7u"},
{id: "999", sku: "999-othersku"}]

The extended data layer also requires you to change the URL on variation selection with the following query param style with the variant ID mapped in the previous variable.

https://mybrand.com/products/tshirt-cotton?variant=32568148885548

You can also look at the tag in our example Shopify store. If you inspect the DOM, you can see the values filled out.

Updating the components without a page reload

If your shop changes the product or variant without reloading the page, update the code and send the retraced:product-changed event. The components then load the data for the new code.

window.retraced.initialSku = "new-code"; window.dispatchEvent(new Event("retraced:product-changed"));

This is the most reliable way. The ?variant= method only works when the variant is selected through a form on the page and the variant ID is in the URL.


Using product Extended Identifier:

If you can use your product code as described above, you don’t need this method.

To get your product info using the product extended identifier, your product should have product code property set on our side and have at least one variation with color and other attribute set as well. Then use a combination of the 3 of them productCode.productColor.otherAttribute to be set as a value for productExtendedIdentifier key as follows:

<script name="retraced-tag"> 
window.retraced = {
shop: "<?php echo $your_domain; ?>",
productExtendedIdentifier: "<?php echo $yourProductCode . '.' . $yourProductColor . '.' . $yourProductOtherAttribute; ?>",
locale: "<?php echo $detected_locale; ?>" || (window.navigator ? window.navigator.language : "en") };
</script>
<script async src="https://rtcd.me/shop-components.js"></script>

To fill out the correct information follow this table:

Variable

Explanation

Type

Example

window.retraced.productExtendedIdentifier

A string of your product identifier in this format productCode.color.otherAttribute

String

1234.red.45

window.retraced.shop

The host (not the full URL) of your shop. Typically what's in the browser URL bar, like mybrand.com, or www.otherbrand.com.

String

mybrand.com

window.retraced.locale

The locale of your shop. You can fallback to the window.navigator locale.

String

en

The Retraced component

You can now place the Retraced tags or components anywhere. An example is:

<retraced-cards></retraced-cards>

Or use any other (or multiple or all!):
<retraced-icons></retraced-icons>
<retraced-button-verified></retraced-button-verified>

Debug installation

In order to find out what went wrong, you can always just set hard-coded values for the Retraced basic data layer. So, the shop, initial product code / productExtendedIdentifier and locale can be fixed set to e.g.:

for product code:

window.retraced.initialSku = "mysku001"
window.retraced.shop = "www.mybrand.com"
window.retraced.locale = "en"

for productExtendedIdentifier:

window.retraced.productExtendedIdentifier = "myProductCode.color.otherAttribute"
window.retraced.shop = "www.mybrand.com"
window.retraced.locale = "en"

This way, you can eliminate any parsing problems and you can force a specific product code / productExtendedIdentifier to appear to be matched with Retraced.

If nothing shows up, check that:

  • the code exists in Retraced as an SKU, variant or style code

  • the product story is active

  • the code is unique in Retraced


Concerned about loading time?

We distribute the loader component for the snippets through CloudFlare CDN, which is the fastest CDN worldwide. That script determines if there must be anything loaded from the components. We have a variety of components and only the necessary snippets are loaded afterwards.

To reduce any additional traffic, the component scripts are cached for at least several hours in the browser cache of the user. Thus, a reload of any component snippet will occur earliest 4h after the first product page visit.

Did this answer your question?