Analytics.
Adding Google Analytics to a Gatsby site is very straight forward.
- Go to Google Analytics and setup an account, get a Trackingid for your website.
Install Gatsby analytics plugin.
- Install Gatsby google analytics plugin.
npm install --save gatsby-plugin-google-analytics
- Add plugin in gatsby-config.js
{
resolve: `gatsby-plugin-google-analytics`,
options: {
trackingId: "UA-XXXXXXXXX-X",
},
},
Submit Site to Google.
- Add Gatsby sitemap plugin.
npm install --save gatsby-plugin-sitemap
- 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.
- 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