Our Shopify app now works to track marketing attribution for payments made via CartHook. To get this working you need to follow a few steps.

This script works with the GA cross domain linker, picking up a cookie ID from your website which we can link with the order once it’s purchased on Shopify.

1. Go to your CartHook ‘integrations’ page

2. Find the ‘checkout scripts’ box

3. Paste in the following script, after any other scripts which are already present.

var jQ = $;

CH.event(function(event, data) {
  if (event == 'INITIATED_PAGE') {
    //Littledata tracking script
    (function($) {
      if (!$) {
        console.warn('Littledata script could not find jQuery on this page');
        return
      }
      var queryParams = location.search.split(/&/);
      var clientIDMatches = queryParams.filter(function(param) {
        return param.match(/_ga/)
      });
      if (!clientIDMatches || !clientIDMatches.length) {
        console.warn('Littledata script could not find _ga query parameter. Is cross-domain tracking enabled ?');
        return
      }
      if (clientIDMatches.length > 1) {
        console.warn('Littledata script found two _ga parameters. You have a GA setup issue');
        return
      }
      clientIDMatches = clientIDMatches[0];
      clientIDMatches = clientIDMatches.slice(4);
      var clientIDGroups = clientIDMatches.split(/[.-]/);
      console.log(clientIDGroups);
      if (clientIDGroups.length !== 6) {
        console.warn('Littledata script could not recognise clientID format. You have a GA setup issue');
        return
      }
      clientID = clientIDGroups[4] + '.' + clientIDGroups[3];
      var cartTokenMatch = queryParams.filter(function(param) {
        return param.match(/cart_token/)
      });
      if (!cartTokenMatch || !cartTokenMatch.length || cartTokenMatch.length > 1) {
        console.warn('Littledata script could not find cart token');
        return
      }
      cartTokenMatch = cartTokenMatch[0];
      var cartToken = cartTokenMatch.split('=');
      if (!cartToken[1]) {
        console.warn('Littledata script could not find cart token');
        return
      }
      cartToken = cartToken[1];
      $.post('https://transactions.littledata.io/clientID', {
        clientID: clientID,
        cartID: cartToken
      })
    })(jQ)
  }
});

4. Save the changes

One Response

  • Pratik 7 days ago

    Seems like Cart Hook has moved this section to the “global scripts” section which has a text area for “Checkout page scripts”

Leave a Reply