Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where to put google analytics code [duplicate]

Possible Duplicate:
google analytics at head? or end of body?

The google analytics code has to be put before the HEAD tag. Can anyone tell where do i put the ga code if there is no HEAD tag present in my jsp file?

like image 733
tin_tin Avatar asked Sep 16 '26 07:09

tin_tin


1 Answers

The correct answer here would be to add head tags to your file. You should be using valid html markup for all your pages, and including head tags (even if empty - though certain other tags within head tag are required, depending on what type of document you are serving. Like..title tag and some meta tags...) is part of a validly marked up document. Not to mention that it hurts your SEO efforts not to have it (with relevant info, like aforementioned title and meta tags..).

However if you insist on not having a head tag in your document, you can place the GA code anywhere; in the head tag is just the optimal place - according to some people.

The logic behind putting it higher up is to give it a chance to track, even if a person tries to leave the page before it is done loading (closing the browser, clicking the redirect button, maybe js on the page redirects, etc...).. However, in my experience, I do not really think these are valid reasons for putting the tracking code high up on the page.

In fact, I would argue against tracking hits such as those. My main question/thought about that is...how can you rightfully say a user viewed the page if they immediately left it, even before it was fully loaded? But that's just IMO.

like image 135
Crayon Violent Avatar answered Sep 20 '26 23:09

Crayon Violent



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!