Herb
Herb

Reputation: 11

Shopify no longer support Analytics

My Shopify Analytics flat-lined on October 8th, and I've been trying to determine the source of the problem. I've followed Digital Darts' post and Ahmad Kanani's step-by-step guide to see if I missed something.

Shopify's tech support notified me today that they don't currently support Analytics. What seems to happen is when you paste the new gtag.js code into Shopify's preference page box for Analytics, their back-end editor, called TinyMCE from what I've gathered, strips off the remaining code beginning with the first script close tag, leaving an unclosed script to bork your site. I haven't found a way to generate legacy code, so Shopify has effectively dropped support for Analytics with no announcement.

When you enter the code below in the box at Online Store >> Preferences >> Google Analytics >> Add custom JavaScript

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-1">
</script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-96981937-1');
</script>

...it gets truncated before the close script tag and becomes this code with an unclosed script:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-1">

Is there a way to update their .liquid code if they say they don't support gtag.js? Their technician recommended that I remove the gtag from my theme.liquid header.

This is from Keith at Shopify tech support:

"It's likely we will migrate to gtag.js in the future depending on how it progresses but for the time being gtag.js scripts would not be recommended for use with a Shopify (excluding stores on Shopify Plus who choose to work with it)"

Upvotes: 1

Views: 650

Answers (1)

Sarah Beeson
Sarah Beeson

Reputation: 11

I haven't found a way to get gtag.js working with theme.liquid yet but you can use the legacy analytics.js tracking still in Preferences:

<!-- Google Analytics -->
<script>
(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', 'GA_TRACKING_ID', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->

Upvotes: 1

Related Questions