Note: 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 'Global Scripts' page

2. Find the 'Checkout page scripts' box

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

var jQ = window.$;

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');

        var queryParams =
            .replace('?', '')
        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');
        cartTokenMatch = cartTokenMatch[0];
        var cartToken = cartTokenMatch.split('=');
        if (!cartToken[1]) {
          console.warn('Littledata script could not find cart token');
        cartToken = cartToken[1];

        var clientID;
        var clientIDMatches = queryParams.filter(function(param) {
          return param.match(/_ga/)

        if (clientIDMatches && clientIDMatches.length) {
            if (clientIDMatches.length > 1) {
              console.warn('Littledata script found two _ga parameters. You have a GA setup issue');
            clientIDMatches = clientIDMatches[0];  
            clientIDMatches = clientIDMatches.slice(4);
            var clientIDGroups = clientIDMatches.split(/[.-]/);
            if (clientIDGroups.length !== 6) {
              console.warn('Littledata script could not recognise clientID format. You have a GA setup issue');
            clientID = clientIDGroups[4] + '.' + clientIDGroups[3];
        } else {
            var cookies = document.cookie
                .reduce(function(obj, item) {
                    var pair = item.trim().split('=');
                    return obj
                }, {})

            if (cookies && cookies._ga) {
                clientIDMatches = cookies._ga.split('.')
                clientID = clientIDMatches[2] + '.' + clientIDMatches[3]

        $.post('', {
          clientID: clientID,
          cartID: cartToken

4. Save the changes

5. Remove all Google Analytics tracking ID's from the CartHook dashboard

There are two places where the Google Analytics tracking ID can be placed in the CartHook platform and without their removal transactions would be double tracked.

  • First would be the tracker from 'Integrations and Tracking'. Just click Disable Google Analytics and the changes are saved.
  • Second would be the tracker placed in the Checkout funnel. Delete the tracker and click save.


You will start seeing sales being attributed to your marketing channels in Google Analytics.

Did this answer your question?