Reputation: 13
i many time hear to put your google analytics code in head. Even google also suggest that. but why it's important to putting google analytics code in head tag
Upvotes: 0
Views: 2098
Reputation: 32760
You put the tracking code in the head tag so it get's executed as soon as possible. Else, if the elements on your page take a long time to load, users might leave your site before they are tracked in GA.
Also having a standard implementation makes tracking code marginally easier to debug, since you do not have to think about possible side effects of non standard code placement (in theory at least, in practice it hardly makes a difference).
Apart from that GA code will work no matter where in your HTML document you place it.
Upvotes: 1