Source Code Placement of Website Statistics Software

I was so excited when Google Analytics was released to the public. At that time, I was a regular reader of ProBlogger.net – helping bloggers earn money. Darren Rowse broke the news to the blogging community that Google Analytics was offering free accounts on a first-come-first served basis. When I finally received my invitation from Google, I immediately added all of my websites to be tracked and painstakingly followed each and every instruction -that is, every instruction except for this one:

“It [the source code] should be immediately before the [ending] body tag of your page, and should look exactly as it was provided to you.”


Server Slowdowns
Why was that important. When I learned JavaScript, I understood that most code belongs in the starting “head” tag so that you can be sure that the code is executed – and I wanted to make sure that this code was executed for statistical purposes. So, that’s exactly where I put it. In the next week, I noticed that my site’s latency was increasing; loading every page took about a second more in the beginning. I also noticed that pages on my server that did not require the Google Analytics code had very short latency. So, I changed the source code so that the Google Analytics script ran right before the ending “body” tag. And of course, loading time was significantly increased.

analytics.gifFrom this discovery we can learn an important lesson about script placement, be it a client-side script like JavaScript or a server-side script like PHP. Any scripts that are not necessary for users to “normally” access your web site need to be placed right before the ending “body” tag. Usability should take precedence over statistics. Otherwise, visitors will leave because these scripts slow things down and make it appear that the server is disconnected.

Many people commit the crime of putting this software in the tag. One prime example is (ironically) the ProBlogger site. I’ve already emailed Darren Rowse to move his Google Analytics code but he still hasn’t replied or changed his source code. Don’t be one of those people!

If you enjoyed this post, make sure you subscribe to hacker not cracker via RSS feed or email update!

Additional Reading

Comment View Comments from Other Readers

Popular Posts

Featured Posts

Related Posts

Recent Posts

What's Your Reaction?

Subscribe to this Blog:

Reader Reactions Elsewhere


3 Responses to “Source Code Placement of Website Statistics Software”

  1. simpsons tapped out donut hack Says:

    Hey there would you mind letting me know which web host you’re
    utilizing? I’ve loaded your blog in 3 completely different browsers and I must say this blog loads a lot faster then most.
    Can you recommend a good web hosting provider
    at a reasonable price? Thanks, I appreciate it!

  2. learn Piano easy Says:

    After looking at a few of the blog posts on your
    website, I honestly appreciate your technique of blogging.

    I bookmarked it to my bookmark webpage list and will be checking back in the near
    future. Take a look at my website too and tell me
    what you think.

  3. Despicable Me Minion Rush Hack Says:

    Thanks for sharing your thoughts about minion rush
    hack tool. Regards

    Here is my blog :: Despicable Me Minion Rush Hack

© 2006 and web design of Allan Ray Barizo from [art] [⁄app].
This site is best viewed with FF and at least 1024x768 resolution.