Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Michael 10 posts 30 karma points
    Oct 13, 2014 @ 14:42
    Michael
    0

    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

     

  • Koen Kemseke 3 posts 23 karma points
    Oct 13, 2014 @ 15:14
    Koen Kemseke
    0

    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.

  • Michael 10 posts 30 karma points
    Oct 13, 2014 @ 15:36
    Michael
    0

    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

     

  • Hywel Rees 56 posts 224 karma points
    Oct 13, 2014 @ 17:52
    Hywel Rees
    0

    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

  • Michael 10 posts 30 karma points
    Oct 15, 2014 @ 12:43
    Michael
    0

    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

     

  • Hywel Rees 56 posts 224 karma points
    Oct 15, 2014 @ 14:32
    Hywel Rees
    0

    Hi Michael,

    What I would do in this situation is

    1. Change your template to have a single instance of the Google Analytics JavaScript in it.
    2. In your associated Document Type, add a new property called something like "Google Analytics ID", of type textbox.
    3. Change your template code to use the new property instead of having a hardcoded ID, and change the hostname of your site (www.ufc-gear.se) to 'auto'.
    4. In your content tree, for your main page, add your Google Analytics ID to the new property.

    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

  • Hywel Rees 56 posts 224 karma points
    Oct 15, 2014 @ 14:35
    Hywel Rees
    0

    Sorry, the formatting messed up so I made a screenshot:

     

     

    Cheers

  • Michael 10 posts 30 karma points
    Oct 15, 2014 @ 15:12
    Michael
    0

    Thnx a lot i will try that.

     

    rgds,

    Michael

     

Please Sign in or register to post replies

Write your reply to:

Draft