Jan
09

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!





Additional Reading

Comment View Comments from Other Readers

Popular Posts

Featured Posts

Related Posts

No Related Posts!

Recent Posts

What's Your Reaction?


Subscribe to this Blog:

Recent Reactions Elsewhere


 

Leave a Reply

This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)

You must read and type the 4 chars within 0..9 and A..F, and submit the form.

  

Oh no, I cannot read this. Please, generate a

 
Latest Post on Loading...: Please Wait...
admin admin
© 2006 and web design of Allan Ray Barizo from [art] [⁄app].
This site is best viewed with FF and at least 1024x768 resolution.