vincentdnl.com

Add a Gatsby site to the Google Search Console with Google Analytics

June 28, 2019#GatsbyJS, #SEO

There are several methods to add a website to the Google Search Console and claim its ownership. If you are using GatsbyJS for your static site, you might already be using the gatsby-plugin-google-analytics plugin. It is installed by default on the most popular blog starter.

This is the default configuration in the gatsby-config.js file:

{
resolve: `gatsby-plugin-google-analytics`,
options: {
trackingId: `<trackingId>`
}
}

When you go on the Google Search Console to add a new property and click on “Alternate Method” for validation, you have the “Google Analytics”. Clicking on it will result in an error telling you that the javascript analytics javascript must be placed in the header of the site.

Just add head: true to the configuration:

{
resolve: `gatsby-plugin-google-analytics`,
options: {
trackingId: `<trackingId>`,
head: true
}
}

Now you might want to associate your Analytics and Search Console properties for additional information in Analytics.

I hope this simple tip saved you some time!

Hey 👋! If you enjoy this article, please consider buying me a coffee!
Buy Me A Coffee

Subscribe to my newsletter for web development news!

Did this article bring you value? Why not subscribe to my newsletter then!

It's completely spam-free (I'll send it less than once a month) and you can unsubscribe whenever you want!


Hi 👋, I’m Vincent Déniel. I’m a 💻 web developer, a ✍️ cartoonist and a 📝 blogger! You can follow me on Twitter where I’m @vincentdnl or check my about page to learn more about what I do!