18F / analytics-standards

WIP: Team standards for implementing website and API analytics.
Other
9 stars 12 forks source link

Explain GA tracking code should be inserted in <head>, not at bottom of the page #31

Closed bensheldon closed 9 years ago

bensheldon commented 9 years ago

When using the latest Google Universal Analytics code, the code snippet should be inserted in the <head> for best performance and comprehensiveness of data:

https://support.google.com/analytics/answer/1008080?hl=en#GA

Modern Google Analytics tracking code loads asynchronously and will not affect website performance; placing it higher in page load order will also better ensure that the pageview is tracked. With older tracking code it was encouraged to place at the bottom of the page for performance reasons, but this is no longer necessary.

jackiekazil commented 9 years ago

Ty for the update @bensheldon!

konklone commented 9 years ago

I'll just take this opportunity to note that the DAP team is working on making the DAP code work properly with async usage, which would mean encouraging that to be used in the <head> tag as well.