Streaming live at 10am (PST)

Google Analytics to track purchases with Shopify Buy Button


#1

I’ve made an e-commerce site using Shopify Buy-buttons. Everything is working fine, except that my purchases are not being tracked with google analytics. I believe I’ve set up cross-domain tracking correctly. Now, not only is it not tracking the sales, but when I switched to this rather than just using the integration for GA in Webflow, now no site traffic is being tracked at all. Is there a step I’m missing other than adding these two scripts, one on each site? I’ve used the info on the link here - https://ecommerce.shopify.com/c/ecommerce-marketing/t/using-a-custom-google-analytics-code-with-buy-button-426022

On Webflow I’ve added this code to my site header (and replaced the UA with my correct one)-

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', ''UA-xxxxxxxxx-x'', 'auto', {'allowLinker': true}); ga('require', 'linker'); ga('linker:autoLink', ['checkout.shopify.com'] ); ga('send', 'pageview');

On Shopify in the additional scripts section of the checkout I’ve added -

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXXXXX-X', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', [‘togethergoods.com’] );
ga('send', 'pageview');

ga('require', 'ecommerce');

var checkoutObj = window.Shopify.checkout,
    lineItems = checkoutObj.line_items

if (checkoutObj)
    ga('ecommerce:addTransaction', {
      'id': checkoutObj.order_id,
      'affiliation': '',
      'revenue': checkoutObj.subtotal_price,
      'shipping': checkoutObj.shipping_rate.price,
      'tax': checkoutObj.total_tax
    })

if (lineItems)
  for (var i = 0; i < lineItems.length; i++){
      var line_item = lineItems[i]
      ga('ecommerce:addItem', {
          'id': line_item.product_id,
          'name': line_item.title,
          'sku': line_item.sku,
          'category': '',
          'price': line_item.price,
          'quantity': line_item.quantity
      });
  }

ga('ecommerce:send');

Any help would be much appreciaited!

Here is my public share link: https://preview.webflow.com/preview/togethergoods?utm_source=togethergoods&preview=505e96bd06dd8c6153eaa0f509f29ec0