Installing Google Analytics g4 Tag in your Gatsby and Discourse Webservice
Discourse
Create your version 4 page property - or click the upgrade button in your existing v3 property. Then open the Admin panel and go to Data Streams:
Copy the Measurement ID:
Paste the Measurement ID into the GA Universal Tracking Code field and add the Universal Domain Name of your webpage (might also work if you keep it in auto):
Gatsby Webpage
Start by adding your version 4 property and copy your Measurement ID as described above. Then continue by installing the gatsby-plugin-gtag plugin into your Gatsby project:
npm install --save gatsby-plugin-gtag
Configure the plugin by adding the Measurement ID of your web property:
// In your gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-gtag`,
options: {
// your google Measurement ID
trackingId: `G-T5ASJKF3T`,
// Puts tracking script in the head instead of the body
head: true,
// enable ip anonymization
anonymize: true,
},
},
],
}