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?
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?
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.
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.
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.