Gatsby plugin to add Google Analytics gtag.js (replacement for analytics.js) to a site. Includes Outbound Links.
npm install gatsby-plugin-gtagDoes the same thing as
gatsby-plugin-google-analytics,
but instead of adding deprecated analytics.js
script, it uses
gtag.js. Includes Outbound Link module.
``bash`
npm install --save gatsby-plugin-gtag
`js
// In your gatsby-config.js
module.exports = {
plugins: [
{
resolve: gatsby-plugin-gtag,UA-XXXXXXXX-X
options: {
// your google analytics tracking id
trackingId: ,
// Puts tracking script in the head instead of the body
head: false,
// enable ip anonymization
anonymize: true,
},
},
],
}
`import { OutboundLink } from 'gatsby-plugin-gtag'Outbound Links
Use like any other anchor tag in your component:
#### head
Puts tracking script in the head instead of the body. Default is false (render in the body)
#### anonymize
Adds anonymize_ip flag when calling gtag. More info
here.
By default gatsby-plugin-gtag will only load and run google analytics when process.env.NODE_ENV === 'production'.GATSBY_GTAG_DEBUG=true gatsby develop`.
To enable gtag in development mode set the environment variable
MIT