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

June 28, 2019

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. In fact it’s 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’ve 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 informations in Analytics.

I hope this simple tip saved you some time!

Hi, I'm Vincent Déniel,

developer and 🛠 maker.

I made Crypto & Coin, Ma Raclette and Astenote. I also play guitar, do some running and draw comics!

What I'm working on 🛠:

₿ Crypto & coin

Bitcoin and cryptocurrencies, simply explained

You can find me on:

twitter where I talk about programming and technology
github where I post and discuss code
Indie Hackers
indieHackers where I post about my products and interact with the makers community