Add Rebuy to your Tracking Page

Updated 2 weeks ago by Jordan Graham

Rebuy Engine allows you to make AI driven upsell recommendations to customers. Here's how to enable it on your tracking page.

This integration requires tracking pages that are built through the Shopify Theme Editor. For help migrating from the legacy tracking page, just reach out.
Add the Enquire Snippet.
  1. Open the Shopify code editor for the theme you'd like you use. You can find this in the 'Actions' drop down.
  2. On the left, you'll find all of your theme files. Under 'Sections' select 'Add a new section'.
  3. Call it rebuy in the field that appears and hit 'create section'.
  4. In the file you just created, replace all of the default code with the following and hit save:
<script type="text/javascript">
document.addEventListener('wonderment:shipments_loaded', function(event) {
console.log('Shipments loaded event fired with shipments: ', event.shipments);

document.addEventListener('rebuy.ready', function(event){
const widget = event.detail.widget;
const orderId = window.wonderment.shipments[0].order.id;
if (orderId) {
widget.data.shopify_order_ids = [orderId];
widget.getWidgetProducts()
}
});

let rebuyContainer = document.createElement('div');
rebuyContainer.dataset.rebuyId = "{{section.settings.rebuy-widget-id}}";
rebuyContainer.dataset.rebuyShopifyOrderIds = event.shipments[0].order.id;

document.getElementById('wonderment-rebuy').appendChild(rebuyContainer);

Rebuy.init();
})
</script>

<div id="wonderment-rebuy"></div>


{% schema %}
{
"name": "Rebuy for Wonderment",
"tag": "section",
"settings": [
{
"type": "text",
"id": "rebuy-widget-id",
"label": "Rebuy Widget ID"
}
],
"presets": [
{
"name": "Rebuy for Wonderment"
}
]
}
{% endschema %}


{% stylesheet %}
{% endstylesheet %}

{% javascript %}
{% endjavascript %}

Add Rebuy to your Tracking Page

When editing the tracking template in the Shopify Theme Editor, click 'Add Section' select 'Rebuy for Wonderment' and add your Rebuy Widget ID in the field on the right of that section's settings. Be sure to save and you're good to go!

Happy upselling!


How did we do?