Purchase Tracking (Cart Script + Confirmed Purchase Script)

Purchase tracking enables the Size Advisor algorithm to learn and improve the recommendations it gives. These 2 scripts track the in-cart activity of a shopper and then confirm which items were in the basket the moment the purchase was placed.

1. Purchase Tracking: Cart Script

The Cart Script needs to be implemented on the cart page or ajax cart section summarizing the items which the customer has added to their cart. Every time the cart is updated, the script must be executed again.

You'll need to populate the ShoeSizeShoppingCart Object with the properties of the items in the cart.

      <script type="text/javascript">
var ShoeSizeShoppingCart = {"shopID": "SHOP_ID","purchases": []};

// Loop throught the items in the cart
// and push their properties into the purchases object
ShoeSizeShoppingCart.purchases.push({
"shoeID": "SHOE_ID",
"size": "SIZE",
"scale": "SCALE", // downscale
"quantity": "QUANTITY",
"price": "PRICE"
"currency": "CUR"
});

// Do not modify
(function(){
var script = document.createElement('script');script.type = 'text/javascript';
script.src = 'https://shoesize.me/plugin/cart.js?'+
'shopid='+encodeURIComponent(ShoeSizeShoppingCart.shopID) +
'&sid=' + Math.round(new Date().getTime() / 1000);
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(script);
})();
</script>

 

If your cart is an Ajax cart and is dynamically available on your webshop, you will need to add the additional scripts:

      <script type="text/javascript">
(function() {

// Replace the following variable
var cartID= "cart"

// Loop throught the items in the cart
// and push their properties into the purchases object
ShoeSizeShoppingCart.purchases.push({
"shoeID": "SHOE_ID",
"size": "SIZE",
"scale": "SCALE", // downscale
"quantity": "QUANTITY",
"price": "PRICE"
"currency": "CUR"
});

// Do not modify
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://shoesize.me/plugin/cart.js?shopid=' + encodeURIComponent(ShoeSizeShoppingCart.shopID) +'&sid=' + Math.round(new Date().getTime() / 1000);
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(script);
var cart_target = document.getElementById(cartID);
var cart_params = {childList: true,subtree: true,characterData: true}
var cart_observer = new MutationObserver(function(mutations) {
cart_observer.disconnect();
if(typeof ssm_setCart == "function"){
ssm_trackCart();
cart_observer.observe(cart_target,cart_params);
}
});
cart_observer.observe(cart_target,cart_params);
})();
</script>

 

Once finished, check if the following requirements below are met:

  1. Make sure the shoeID matches with the shoeID (Article ID) you provided in the Product Feed.
  2. Make sure to set the size in the correct format, only containing the numeric value. Good examples: "40", "40.5", "40.33", "40 1/3", "40 ⅓", "8.5", "8". Bad examples: "40 EU", "Size 40", "EU 42".
  3. Make sure the scale is set correctly: (eu, uk, us, etc).
  4. Make sure to set the quantity correct. If having the same item twice in the shopping cart, send one item with quantity "2" instead of two items with quantity "1".
  5. Make sure the price is set in the format "100.00" or "100".
  6. Make sure the cart script is executed every time a change to the cart is done. A change to the cart is for example:
  • Add a shoe
  • Remove a shoe
  • Change the size
  • Change the quantity

7. If there is no order number yet, leave it empty - pass an empty string: "".

How to test if the Cart Script has been set up correctly:

After having the cart script implemented, test if everything was set up correctly by adding one or more shoes to the shopping cart and see if the script is executed.

There should be an AJAX call to shoesize.me/api/others/cart containing all the products in the cart. The response should be {"success" : true}.

If the response is {"success": false} or the server responds with status code 500, check if everything is set up correctly.

 

2. Purchase Tracking: Confirmed Purchase Script

The Confirmed Purchase Script needs to be implemented on the order confirmation page that is only reachable after the payment was made.

The confirm script needs to be implemented on the order confirmation page that is only reachable after the payment was made. Add this script tag to the body of your HTML:

      <script type="text/javascript">
var ShoeSizeShoppingCartConfirmation = {
shopID: "SHOP_ID",
orderID: ORDER_ID
};

// Do not modify
(function() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://shoesize.me/plugin/confirm.js?'+
'shopid='+encodeURIComponent(ShoeSizeShoppingCartConfirmation.shopID)+
'&sid='+Math.round(new Date().getTime()/1000);
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(script);
})();
</script>

Once finished, check if the following requirements are met:

  1. The Confirmation Script is executed after the order was paid.
  2. If you already sent an order number in the cart script, make sure to provide the same one here.
  3. You must provide the same order number in the purchase & return data feeds.

Here is how to test if the Confirmed Purchase Script has been set up correctly:

  1. Make sure you implemented the cart tacking script first.
  2. Test if everything was set up by executing a test purchase.
  3. On the order confirmation page, check the browser's console if there is a call to shoesize.me/api/others/confirm containing the shop id, order number, and the sid.
  4. The response should be {"success" : true}.
  5. If the response is {"success": false} or the server responds with status code 500, check if everything is set up correctly.