3

I've setup a new property (universal, not classic) and I've copied and pasted the tracking code directly before the on my pages.

When I view the source, I see the tracking code BUT modPagespeed is automatically minifying the inline JS.

If I go to my tracking code details in Analytics, it says my tracking code isn't installed. Been trying for 2 hours.

Is google's pagespeed module breaking the analytics script? How can I work around this?

Beka
  • 41
  • 3

1 Answers1

0

Maybe this can help if you are still looking for an answer or may help someone that is having the same problem now.

If I minify my html with a minification I get page speed 93 but Chrome Console says Unexpected token. It is the GA code that does it. There is one line break that causes it in my ga code. Maybe same problem you are having?

If I put:

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ <!--L I N E B R E A K-->
(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-XXXXXX-1', 'auto'); ga('send', 'pageview');

it works and I get page speed 92

BUT if I deleted the line break and put

(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-XXXXXX-1', 'auto'); ga('send', 'pageview');</script>

Google Console says js invalid token but I get page speed 93...sigh. Seems pagespeed can spot that the code is not completely minified with that one line break that seems to break the analytics script.

Ideas how to fix welcome!

/Johan

Teepeemm
  • 4,331
  • 5
  • 35
  • 58
Johan
  • 1