Is it better to have the Google Analytics tag in the <head> or <body>?
I'm asking because putting it in the Master Page is so very convenient (and much cleaner), but places the tag into the body.
I've seen posts from power users who say using the Master Page is just fine. Will it still be fine with Google Analytics 4?
Best location for Google Analytics tag? Considering GA 4?
-
- Propeller Head
- Posts: 65
- Joined: Fri Mar 01, 2019 9:14 am
Best location for Google Analytics tag? Considering GA 4?
"I'm a technical writer, not a developer," she said...
Re: Best location for Google Analytics tag? Considering GA 4
I put the analytics code in the body of the master page, just before the closing </body> tag.
I also include it as a snippet, so I can re-use it in multiple master pages. And you can't use snippets in the head.
Google will suggest putting it in the head, but the only reason they say that is to ensure that the script runs early, in case someone leaves the page before it has fully loaded and runs the script.
But the analytics script works just fine in the body, it just runs a bit later than it would in the head.
I also include it as a snippet, so I can re-use it in multiple master pages. And you can't use snippets in the head.
Google will suggest putting it in the head, but the only reason they say that is to ensure that the script runs early, in case someone leaves the page before it has fully loaded and runs the script.
But the analytics script works just fine in the body, it just runs a bit later than it would in the head.