4

I am using a webapp for my website which has an option in the settings to add my UA tracking code from google analytics. However, when I view my source, it places the tracking code in the <body> tag. Google states it should be placed in the <head> although it still works as intended. I'm not sure if I should edit the source myself and place it in the <head> or just leave it as-is.

Are there downsides to having it in the <body> versus the <head>. Or does it not really matter?

  • 5
    As Google indicates here, it should be placed before the closing </head> tag. Your webapp might render differently between clients, depending on your code (i.e., JavaScript), and page views might not register if they bounce early... See this related question: webmasters.stackexchange.com/questions/721/… – dan Feb 11 '16 at 2:45
2

Why Google wants you to place it in head, is to ensure high availability of tracking in order to track bounce rates better.

To elaborate on that: when the tracking script tag is placed into body tag, and user leaves the site before it is fully loaded, Analytics would not be able to track the visit and the visit will not affect your bounce rate.

So the upside of placing into head, is the better tracking of users who leave the site for performance reasons.

The downside of placing into head, however, is slower loading of the page itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.