I think you're mixing things up here. Generally speaking you put non-critical code at the end of body to not prevent the loading of the website. I guess what you mean is the Google Analytics verification itself.
You can put that meta tag in your
static folder.
Yeah — could you screenshot the warning google webmasters is giving? Everything I've ever seen says put the script after body
Google's recommendations depend on the analytics script you are using. They recommended the older synchronous ga.js be placed at the end of BODY. They recommend the newer analytics.js and the even newer gtag.js be placed at the top of HEAD. I don't know that it really makes much difference, but this is from the the analytics docs for the method being used in the plugin.

This has recently been raised as an issue within our company too. I found this explanation as to why it's recommended for the <head> - https://stackoverflow.com/questions/3173571/should-i-put-the-google-analytics-js-in-the-head-or-at-the-end-of-body
Perhaps the plugin options can allow the developer to choose support for adding it to the <head>. If nothing is set, it would fallback to the <body> as it does now?
@crgeary yeah this sounds great! Would love a PR adding this.
Sweet.. Just been speaking to @endymion1818 and he wants to take a shot at implementing this :)
Hah, thanks @crgeary ;-)
Having trouble setting this up, I've got the tooling right (I think!) but can't see the GA tracking code on my local build, either using gatsby develop or npm run develop --NODE_ENV=production
Chris, if you have any more ideas about this please let me know ...
Even with the merged PR (https://github.com/gatsbyjs/gatsby/pull/3995), the script is still being added to the end of the body for me.
The head component never gets the script.
{
resolve: `gatsby-plugin-google-analytics`,
options: {
trackingId: "id",
head: true,
},
}
Any ideas on what I'm doing wrong here?
@cmwall can You confirm your gatsby-plugin-google-analytics version is at least 1.0.19 ?
That was the problem. Thanks! @pieh
Most helpful comment
Even with the merged PR (https://github.com/gatsbyjs/gatsby/pull/3995), the script is still being added to the end of the body for me.
The head component never gets the script.
Any ideas on what I'm doing wrong here?