Google Analytics Suggestion

I just ran into an issue with Google Analytics.

  1. I added a new account / property in Google as normal
  2. I added the GA property ID into lib\config.php
  3. I checked in Google Analytics real-time and it was showing me as a

All seemed fine, however when I checked my Google Analytics a couple of days later there were no visitors.

I think I have found what my issue is. When creating a property in Google Analytics you’re given a choice “Universal Analytics” or “Classic Analytics”. I chose classic but js code in roots assumes universal.

I have now created a 2nd Analytics property, chose Universal and used that ID - I will have to wait 24 hours to see if that fixes it. Looking at the js I think it will

I think the same issue may arise with other choices in Google Analytics that cause GA to generate different JavaScript e.g. subdomains, eCommerce. Google also rolls out different features across different countries at different times. So I think it would be very difficult to try and support every combination in roots over time.

My suggestion: instead of the just adding the GA property ID into lib\config.php cut/paste all the JS from Google Analytics.

We’re using HTML5 Boilerplate’s optimized GA snippet. Even prior to Universal Analytics it differed from what GA tells you to use, so we won’t be making it so that people copy and paste the snippet from GA into Roots (if we were doing that we might as well completely remove any mention of GA in Roots).

We could add a note mentioning that it needs to be a Universal Analytics property in lib/config.php

1 Like

Thanks Ben makes sense. The note in lib/config.php would definitely help.

The way it worked for only GA real-time certainly had me confused

So does it take 24 hours for GA to detect your tracking code is working?

Google says it can take up to 24 hours. I have seen it working within 12 hours but seems to vary

There is an extension “Google Analytics Debugger” on Google Chrome Web Store that shows what Google Analytics is capturing - but still worth checking in GA the next day

Still waiting for the tracking to kick in. Strangely the Real Time stuff works.

I’ll look into the debugger. Off the bat though, I notice there is a site name parameter missing in the Boilerplate stuff, compared to the snippet GA provides, on the ga.create function:

ga('create', '<tracking ID>', '<site name>');

Could that possibly be it?

Any idea if this will work?

  1. New account in GA is created with the Universal Analytics (UA) option selected.
  2. The javascript code to embed GA in the html is pasted in the head.php file within the tag.
  3. The UA property is pasted In lib->config.php

Thanks a lot!

Is there a way to completely remove the Analytics script that is built into the theme? I prefer to use the Google Tag Manager to deploy Analytics tags which requires the code to be installed after the opening tag. Any advice on this would be greatly appreciated.


The function is here. Delete or set the define (in lib.config.php) to false.


I think its a good idea to implement tag manager instead of GA by default. Tag manager gives you a lot more flexibility and you only have to implement one tag, in one place.

I personally use GTM, but the markup in Roots comes from H5BP. As long as H5BP continues to have a GA snippet, so will Roots.

Fair enough. GTM is easily added.