views:

32

answers:

3

after signing up google gives me a piece of javascript and tells me to include it in the head.

Can i put it at the end of body or will some side effects occur if i do that?

A: 

When they say put it in the <head>, they mean it.

If placed in the <body>, the code may not function correctly. Better safe than sorry.

esqew
Have you *actually* had any problems?
casablanca
I've never had an issue when placing scripts inside the <body>
Marko
+2  A: 

You can put it anywhere you want. I always put tracking code at the end of the page and I've never had any problems.

casablanca
+1  A: 

Putting it at the end of the <head> section helps ensure the your metrics are tracked even when a user doesn't let the page finish loading.

They used to tell you to put it at the bottom of the page, before they added support for handling partial loading of pages.

Directly from Google:

One of the main advantages of the asynchronous snippet is that you can position it at the top of the HTML document. This increases the likelihood that the tracking beacon will be sent before the user leaves the page. It is customary to place JavaScript code in the section, and we recommend placing the snippet at the bottom of the section for best performance.

Chris Arguin
So it is fine if i put it at the bottom? I rather have my pages load fast by putting everything at the bottom (and css at the top for proper rendering) -edit- its gross to put js up there.
acidzombie24
Yes, it's fine to do so; I actually have a mix, but have mostly migrated to putting it on the top for the reasons mentioned.
Chris Arguin