Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/flpvsk/gatsby-plugin-gtag
Gatsby plugin to add Google Analytics gtag.js (replacement for analytics.js) to a site.
https://github.com/flpvsk/gatsby-plugin-gtag
gatsby gatsby-plugin
Last synced: about 1 month ago
JSON representation
Gatsby plugin to add Google Analytics gtag.js (replacement for analytics.js) to a site.
- Host: GitHub
- URL: https://github.com/flpvsk/gatsby-plugin-gtag
- Owner: flpvsk
- License: mit
- Created: 2018-08-31T20:40:45.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-02T10:36:01.000Z (about 2 years ago)
- Last Synced: 2024-11-15T11:02:04.954Z (2 months ago)
- Topics: gatsby, gatsby-plugin
- Language: JavaScript
- Size: 151 KB
- Stars: 28
- Watchers: 2
- Forks: 12
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gatsby-plugin-gtag
### Add Google Analytics gtag.js to a siteDoes the same thing as
[gatsby-plugin-google-analytics](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-google-analytics),
but instead of adding [deprecated analytics.js](https://developers.google.com/analytics/devguides/collection/gtagjs/migration)
script, it uses
[gtag.js](https://developers.google.com/analytics/devguides/collection/gtagjs/). Includes Outbound Link module.## Install
```bash
npm install --save gatsby-plugin-gtag
```## Use
```js
// In your gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-gtag`,
options: {
// your google analytics tracking id
trackingId: `UA-XXXXXXXX-X`,
// Puts tracking script in the head instead of the body
head: false,
// enable ip anonymization
anonymize: true,
},
},
],
}```
## Outbound Links
`import { OutboundLink } from 'gatsby-plugin-gtag'`Use like any other anchor tag in your component:
`Check out this site!`## Options
#### 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](https://developers.google.com/analytics/devguides/collection/gtagjs/ip-anonymization).## Testing in development mode
By default `gatsby-plugin-gtag` will only load and run google analytics when `process.env.NODE_ENV === 'production'`.
To enable gtag in development mode set the environment variable `GATSBY_GTAG_DEBUG=true gatsby develop`.## License
MIT