ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Analytics Code: In Header or Footer?

December 22, 2010 6:25am

Subscribe [5]
  • #1 / Dec 22, 2010 6:25am

    Hi all,

    I use a theme from WooThemes at one of my sites, and they place the Google Analytics tracking-code at the very bottom of the pages, just before the closing body-tag as shown at the end of this post.

    However Google says the tracking-code should be placed just before the closing head-tag, when you read their documentation on the Analytics website.

    I see EllisLab places the code at the bottom here on the forum-pages, just like the WooTheme does, but they place it at the top as Google recommends on the front-page for example.

    So my question is: Is there anything special when running EE, that makes it better to have the tracking-code at the bottom? Or does it not matter the least? If it doesn’t matter, it seems strange that so many EE-sites have it in another place than Google recommends. So I bet there is a good reason behind this, and I’d love to learn more about it.

    So if anyone has the time to explain this to me, I’d be very grateful 😊


    EXAMPLE FROM A WOO-THEME:

    ... footer code above this ...
    
    [removed]
    
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-TEST-X']);
      _gaq.push(['_trackPageview']);
    
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s[removed].insertBefore(ga, s);
      })();
    
    [removed]
    </body>
    </html>
  • #2 / Dec 22, 2010 9:45am

    Boyink!

    5011 posts

    IMHO there is no “EE-requirement” in this case.  I was just looking at this issue for a client and it looks like the header was considered a more accurate view.

  • #3 / Dec 22, 2010 3:50pm

    OK, thank you very much for making me stop wondering about this one 😊

    Cheers,
    Thomas

  • #4 / Jan 06, 2011 1:38pm

    scottb

    348 posts

    Google used to recommend putting it in the footer because it wanted to log only those pages that fully displayed in a browser. It now recommends the header. But that leaves open the question of whether you want to log pages that are only part-way open before someone leaves them again.

  • #5 / Jan 28, 2011 8:15pm

    mhughes73

    60 posts

    I’d say it’s always best to do what Google tells you to do, or else suffer the consequences… 😉

  • #6 / Jan 30, 2011 9:57am

    bottleboot

    54 posts

    Does this not depend on what type of tracking you use?


    With the traditional snippet, you have two options depending on how your site is built:

    We generally recommend that you place the Google Analytics tracking code immediately before the closing </body> tag of your pages in order to avoid any issues with page loading delays for visitors with slow connection speeds.

    http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55574
    http://code.google.com/apis/analytics/docs/tracking/asyncTracking.html

    While when hen using asynchronous JavaScript the recommendation is before </head>:
    http://code.google.com/apis/analytics/docs/tracking/asyncTracking.html

    So since you use the latter the answer is to put it before </head>.

    Correct me if I am wrong.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases