Analytics.

Adding Google Analytics to a Gatsby site is very straight forward.

  1. Go to Google Analytics and setup an account, get a Trackingid for your website.

Install Gatsby analytics plugin.

  1. Install Gatsby google analytics plugin.
npm install --save gatsby-plugin-google-analytics
  1. Add plugin in gatsby-config.js
    {
      resolve: `gatsby-plugin-google-analytics`,
      options: {
        trackingId: "UA-XXXXXXXXX-X",
      },
    },

Submit Site to Google.

  1. Add Gatsby sitemap plugin.
npm install --save gatsby-plugin-sitemap
  1. Add Plugin in gatsby config file.
gatsby-config.js
siteMetadata: {
  siteUrl: `https://www.example.com`,
},
plugins: [`gatsby-plugin-sitemap`]

This will generate a sitemap.xml file in the website. www.kennethau.com/sitemap.xml In order for Google to crawl the website, I will have to submit sitemap to Google Search Console.

  1. Submit sitemap to Google Search Console

About Me

I am a self-taught developer who is passionate about software development, entrepreneurship and finance. I love to write about my daily life at work and outside work.

You can find more about me on  Kenneth Au LinkedIn