项目作者: flpvsk

项目描述 :
Gatsby plugin to add Google Analytics gtag.js (replacement for analytics.js) to a site.
高级语言: JavaScript
项目地址: git://github.com/flpvsk/gatsby-plugin-gtag.git
创建时间: 2018-08-31T20:40:45Z
项目社区:https://github.com/flpvsk/gatsby-plugin-gtag

开源协议:MIT License

下载


gatsby-plugin-gtag

Add Google Analytics gtag.js to a site

Does the same thing as
gatsby-plugin-google-analytics,
but instead of adding deprecated analytics.js
script, it uses
gtag.js. Includes Outbound Link module.

Install

  1. npm install --save gatsby-plugin-gtag

Use

  1. // In your gatsby-config.js
  2. module.exports = {
  3. plugins: [
  4. {
  5. resolve: `gatsby-plugin-gtag`,
  6. options: {
  7. // your google analytics tracking id
  8. trackingId: `UA-XXXXXXXX-X`,
  9. // Puts tracking script in the head instead of the body
  10. head: false,
  11. // enable ip anonymization
  12. anonymize: true,
  13. },
  14. },
  15. ],
  16. }

import { OutboundLink } from 'gatsby-plugin-gtag'

Use like any other anchor tag in your component:
<OutboundLink href='yourwebsite.example'>Check out this site!</OutboundLink>

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.

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