I am trying to figure out where to place the Google Analytics .js code. The site is using templates and i want to track the whole site including the uCommerce part of the site. I have read the Google advise on where to place the .js code, but the site is not tracked by Google Analytics.
Is there a Best Practice for placing the .js script in umbraco/uCommerce?
Michael, Although it should be fairly easy to implement GA code (it should be placed just below the opening of the body tag), you should consider installing Google Tag Manager. This allows more flexibility for marketeers... and you don't have to fiddle in your code anymore for adding extra tags.
Thanks for your prompt reply. My next question is please have a look at the sourcecode of the www.ufc-gear.se site i have experimented with different insertions of the .js script with no luck. According to google the script should be placed just before the HEAD closing tag?
The Google Analytics script should sit just before the closing head tag - not inside the body. The Google Tag manager scriipt however, *does* sit inside the body.
Looking at your site, I notice you have two instances of the script in the head tag, and one inside the body tag. Remove the one from the body tag, and remove the extra one from the head tag, and you should be ok. Note Google sometimes takes a while (a couple of days) before it will indicate that your site has the analytics installed correctly, don't expect it to update instantly.
Thnx for the reply. It seems to be working :) Although i have one more question. There are 2 sites (ufc-gear.dk/.se) based on the same template. Is it possible to add 2 Google .js scripts in the same template which will refer to two different sites - UA id's?
Google Analytics Code (UA)
Hi,
I am trying to figure out where to place the Google Analytics .js code. The site is using templates and i want to track the whole site including the uCommerce part of the site. I have read the Google advise on where to place the .js code, but the site is not tracked by Google Analytics.
Is there a Best Practice for placing the .js script in umbraco/uCommerce?
Thnx,
Michael
Michael,
Although it should be fairly easy to implement GA code (it should be placed just below the opening of the body tag), you should consider installing Google Tag Manager. This allows more flexibility for marketeers... and you don't have to fiddle in your code anymore for adding extra tags.
Thanks for your prompt reply. My next question is please have a look at the sourcecode of the www.ufc-gear.se site i have experimented with different insertions of the .js script with no luck. According to google the script should be placed just before the HEAD closing tag?
Where can i find/install Google Tag Manager?
Rgds,
Michael
Hi Michael,
The Google Analytics script should sit just before the closing head tag - not inside the body. The Google Tag manager scriipt however, *does* sit inside the body.
Looking at your site, I notice you have two instances of the script in the head tag, and one inside the body tag. Remove the one from the body tag, and remove the extra one from the head tag, and you should be ok. Note Google sometimes takes a while (a couple of days) before it will indicate that your site has the analytics installed correctly, don't expect it to update instantly.
Cheers,
HJR
Thnx for the reply. It seems to be working :) Although i have one more question. There are 2 sites (ufc-gear.dk/.se) based on the same template. Is it possible to add 2 Google .js scripts in the same template which will refer to two different sites - UA id's?
Rgds,
Michael
Hi Michael,
What I would do in this situation is
Your google script should then look something like this:
<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', '//www.google-analytics.com/analytics.js', 'ga'); ga('create', '@Model.Content.AncestorOrSelf(1).GetPropertyValue("GoogleAnalyticsID")', 'auto'); ga('send', 'pageview'); </script>
Hope this helps!
Cheers,
HJR
Sorry, the formatting messed up so I made a screenshot:
Cheers
Thnx a lot i will try that.
rgds,
Michael
is working on a reply...