{"name":"gatsby-plugin-google-analytics","version":"5.18.0-react19.0","keywords":["gatsby","gatsby-plugin","google analytics"],"author":{"name":"Kyle Mathews","email":"mathews.kyle@gmail.com"},"license":"MIT","_id":"gatsby-plugin-google-analytics@5.18.0-react19.0","maintainers":[{"name":"pieh","email":"misiek.piechowiak@gmail.com"},{"name":"kathmbeck","email":"katherine.beck@netlify.com"},{"name":"serhalp-netlify","email":"philippe.serhal@netlify.com"},{"name":"mlgualtieri-gatsby","email":"mike.gualtieri@netlify.com"},{"name":"tylerbarnes","email":"tyler@known.design"}],"homepage":"https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-google-analytics#readme","bugs":{"url":"https://github.com/gatsbyjs/gatsby/issues"},"dist":{"shasum":"734a80d6ed701fb6feb80f3b09d21178aed5006a","tarball":"http://registry-npm.ywwl.com/gatsby-plugin-google-analytics/download/gatsby-plugin-google-analytics-5.18.0-react19.0.tgz","fileCount":10,"integrity":"sha512-Y7ZSDank+Xzk6x2kzA7jSHe6APLbcxccO3P2iQdM3Kezzxf3jEzuXuYc1OWdwq61gD8QIVKBWaUmzfYI/evyKg==","signatures":[{"sig":"MEUCIAxyD3fxLFZWe+os805siQu4PLkU4tCR8i8Rhnu5Um+wAiEA4ceTG6zDTtfipfRyxcwiyp6bk17mdcDlyNsSOwNM0Gg=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":76183,"size":16405,"noattachment":false,"key":"/gatsby-plugin-google-analytics/-/gatsby-plugin-google-analytics-5.18.0-react19.0.tgz"},"main":"index.js","types":"./index.d.ts","engines":{"node":">=18.0.0"},"gitHead":"ad34f2199560f6c212ff45c2ebaf33273fc837f0","scripts":{"build":"babel src --out-dir . --ignore \"**/__tests__\"","watch":"babel -w src --out-dir . --ignore \"**/__tests__\"","prepare":"cross-env NODE_ENV=production npm run build"},"_npmUser":{"name":"serhalp-netlify","email":"philippe.serhal@netlify.com"},"deprecated":"This React 19 prerelease version may be selected unexpectedly by npm when resolving version ranges. Please use the latest stable version, or use @next to install React 19 compatible prerelease version.","repository":{"url":"git+https://github.com/gatsbyjs/gatsby.git","type":"git","directory":"packages/gatsby-plugin-google-analytics"},"_npmVersion":"lerna/3.22.1/node@v22.19.0+arm64 (darwin)","description":"Gatsby plugin to add google analytics onto a site","directories":{},"_nodeVersion":"22.19.0","dependencies":{"minimatch":"^3.1.2","web-vitals":"^1.1.2","@babel/runtime":"^7.20.13"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"cross-env":"^7.0.3","@babel/cli":"^7.20.7","@babel/core":"^7.20.12","@testing-library/react":"^11.2.7","babel-preset-gatsby-package":"^3.16.0-next.0"},"peerDependencies":{"react":"^18.0.0 || ^19.0.0 || ^0.0.0","gatsby":"^5.0.0","react-dom":"^18.0.0 || ^19.0.0 || ^0.0.0"},"_npmOperationalInternal":{"tmp":"tmp/gatsby-plugin-google-analytics_5.18.0-react19.0_1764189500059_0.6840760482629513","host":"s3://npm-registry-packages-npm-production"},"readme":"# gatsby-plugin-google-analytics\n\nEasily add Google Analytics to your Gatsby site.\n\n## Deprecation Notice\n\nThis plugin uses Google's `analytics.js` file under the hood. Google has a [guide recommending users upgrade to `gtag.js` instead](https://developers.google.com/analytics/devguides/collection/upgrade/analyticsjs). There is another plugin [`gatsby-plugin-google-gtag`](https://gatsbyjs.com/plugins/gatsby-plugin-google-gtag/) which uses `gtag.js` and we recommend it.\n\n## Install\n\n```shell\nnpm install gatsby-plugin-google-analytics\n```\n\n## How to use\n\n```javascript\n// In your gatsby-config.js\nmodule.exports = {\n  plugins: [\n    {\n      resolve: `gatsby-plugin-google-analytics`,\n      options: {\n        // The property ID; the tracking code won't be generated without it\n        trackingId: \"YOUR_GOOGLE_ANALYTICS_TRACKING_ID\",\n        // Defines where to place the tracking script - `true` in the head and `false` in the body\n        head: false,\n        // Setting this parameter is optional\n        anonymize: true,\n        // Setting this parameter is also optional\n        respectDNT: true,\n        // Avoids sending pageview hits from custom paths\n        exclude: [\"/preview/**\", \"/do-not-track/me/too/\"],\n        // Delays sending pageview hits on route update (in milliseconds)\n        pageTransitionDelay: 0,\n        // Enables Google Optimize using your container Id\n        optimizeId: \"YOUR_GOOGLE_OPTIMIZE_TRACKING_ID\",\n        // Enables Google Optimize Experiment ID\n        experimentId: \"YOUR_GOOGLE_EXPERIMENT_ID\",\n        // Set Variation ID. 0 for original 1,2,3....\n        variationId: \"YOUR_GOOGLE_OPTIMIZE_VARIATION_ID\",\n        // Defers execution of google analytics script after page load\n        defer: false,\n        // Any additional optional fields\n        sampleRate: 5,\n        siteSpeedSampleRate: 10,\n        cookieDomain: \"example.com\",\n        // defaults to false\n        enableWebVitalsTracking: true,\n      },\n    },\n  ],\n}\n```\n\nSee below for the complete list of [optional fields](#optional-fields).\n\nNote that this plugin is disabled while running `gatsby develop`. This way, actions are not tracked while you are still developing your project. Once you run `gatsby build` the plugin is enabled. Test it with `gatsby serve`.\n\n## `<OutboundLink>` component\n\nTo make it easy to track clicks on outbound links in Google Analytics,\nthe plugin provides a component.\n\nTo use it, simply import it and use it like you would the `<a>` element e.g.\n\n```jsx\nimport React from \"react\"\nimport { OutboundLink } from \"gatsby-plugin-google-analytics\"\n\nconst Component = () => (\n  <div>\n    <OutboundLink href=\"https://www.gatsbyjs.com/plugins/gatsby-plugin-google-analytics/\">\n      Visit the Google Analytics plugin page!\n    </OutboundLink>\n  </div>\n)\n\nexport default Component\n```\n\n## Options\n\n### `trackingId`\n\nHere you place your Google Analytics tracking id.\n\n### `head`\n\nWhere do you want to place the GA script? By putting `head` to `true`, it will be placed in the \"&lt;head&gt;\" of your website. By setting it to `false`, it will be placed in the \"&lt;body&gt;\". The default value resolves to `false`.\n\n### `anonymize`\n\nSome countries (such as Germany) require you to use the\n[\\_anonymizeIP](https://support.google.com/analytics/answer/2763052) function for\nGoogle Analytics. Otherwise you are not allowed to use it. The option adds two\nblocks to the code:\n\n```javascript\nfunction gaOptout(){document.cookie=disableStr+'=true; expires=Thu, 31 Dec 2099 23:59:59 UTC;path=/',window[disableStr]=!0}var gaProperty='UA-XXXXXXXX-X',disableStr='ga-disable-'+gaProperty;document.cookie.indexOf(disableStr+'=true')>-1&&(window[disableStr]=!0);\n\n...\n\nga('set', 'anonymizeIp', 1);\n```\n\nIf your visitors should be able to set an Opt-Out-Cookie (No future tracking)\nyou can set a link e.g. in your imprint as follows:\n\n`<a href=\"javascript:gaOptout();\">Deactivate Google Analytics</a>`\n\n### `respectDNT`\n\nIf you enable this optional option, Google Analytics will not be loaded at all for visitors that have \"Do Not Track\" enabled. While using Google Analytics does not necessarily constitute Tracking, you might still want to do this to cater to more privacy oriented users.\n\nIf you are testing this, make sure to disable Do Not Track settings in your own browser.\nFor Chrome, Settings > Privacy and security > More\nThen disable `Send a \"Do Not Track\" request with your browsing traffic`\n\n### `exclude`\n\nIf you need to exclude any path from the tracking system, you can add it (one or more) to this optional array as glob expressions.\n\n### `pageTransitionDelay`\n\nIf your site uses any custom transitions on route update (e.g. [`gatsby-plugin-transition-link`](https://www.gatsbyjs.com/blog/2018-12-04-per-link-gatsby-page-transitions-with-transitionlink/)), then you can delay processing the page view event until the new page is mounted.\n\n### `optimizeId`\n\nIf you need to use Google Optimize for A/B testing, you can add this optional Optimize container id to allow Google Optimize to load the correct test parameters for your site.\n\n### `experimentId`\n\nIf you need to set up SERVER_SIDE Google Optimize experiment, you can add the experiment ID. The experiment ID is shown on the right-hand panel on the experiment details page. [Server-side Experiments](https://developers.google.com/optimize/devguides/experiments)\n\n### `variationId`\n\nBesides the experiment ID you also need the variation ID for SERVER_SIDE experiments in Google Optimize. Set 0 for original version.\n\n### `enableWebVitalsTracking`\n\nOptimizing for the quality of user experience is key to the long-term success of any site on the web. Capturing Real user metrics (RUM) helps you understand the experience of your user/customer. By setting `enableWebVitalsTracking` to `true`, Google Analytics will get [\"core-web-vitals\"](https://web.dev/vitals/) events with their values.\n\nWe send three metrics:\n\n- **Largest Contentful Paint (LCP)**: measures loading performance. To provide a good user experience, LCP should occur within 2.5 seconds of when the page first starts loading.\n- **First Input Delay (FID)**: measures interactivity. To provide a good user experience, pages should have a FID of 100 milliseconds or less.\n- **Cumulative Layout Shift (CLS)**: measures visual stability. To provide a good user experience, pages should maintain a CLS of 1 or less.\n\n## Optional Fields\n\nThis plugin supports all optional Create Only Fields documented in [Google Analytics](https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#create):\n\n- `name`: string, tracker name\n- `clientId`: string\n- `sampleRate`: number\n- `siteSpeedSampleRate`: number\n- `alwaysSendReferrer`: boolean\n- `allowAnchor`: boolean\n- `cookieName`: string\n- `cookieFlags`: string\n- `cookieDomain`: string, defaults to `'auto'` if not given\n- `cookieExpires`: number\n- `storeGac`: boolean\n- `legacyCookieDomain`: string\n- `legacyHistoryImport`: boolean\n- `allowLinker`: boolean\n- `storage`: string\n\nThis plugin also supports several optional General fields documented in [Google Analytics](https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#general):\n\n- `allowAdFeatures`: boolean\n- `dataSource`: string\n- `queueTime`: number\n- `forceSSL`: boolean\n- `transport`: string\n\nThese fields can be specified in the plugin's `options` as shown in the [How to use](#how-to-use) section.\n\n## TrackCustomEvent Function\n\nTo allow custom events to be tracked, the plugin exposes a function to include in your project.\n\nTo use it, import the package and call the event within your components and business logic.\n\n```jsx\nimport React from \"react\"\nimport { trackCustomEvent } from \"gatsby-plugin-google-analytics\"\n\nconst Component = () => (\n  <div>\n    <button\n      onClick={e => {\n        // To stop the page reloading\n        e.preventDefault()\n        // Lets track that custom click\n        trackCustomEvent({\n          // string - required - The object that was interacted with (e.g.video)\n          category: \"Special Button\",\n          // string - required - Type of interaction (e.g. 'play')\n          action: \"Click\",\n          // string - optional - Useful for categorizing events (e.g. 'Spring Campaign')\n          label: \"Gatsby Plugin Example Campaign\",\n          // number - optional - Numeric value associated with the event. (e.g. A product ID)\n          value: 43,\n        })\n        //... Other logic here\n      }}\n    >\n      Tap that!\n    </button>\n  </div>\n)\n\nexport default Component\n```\n\n### All Fields Options\n\n- `category`: string - required\n- `action`: string - required\n- `label`: string\n- `value`: integer\n- `nonInteraction`: bool\n- `transport`: string\n- `hitCallback`: function\n\nFor more information see the [Google Analytics](https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#events) documentation.\n\n#### hitCallback\n\nA timeout is included by default incase the Analytics library fails to load. For more information see [Google Analytics - Handling Timeouts](https://developers.google.com/analytics/devguides/collection/analyticsjs/sending-hits#handling_timeouts)\n\n## Troubleshooting\n\n### No actions are tracked\n\n#### Check the tracking ID\n\nMake sure you supplied the correct Google Analytics tracking ID. It should look like this: `trackingId: \"UA-111111111-1\"`\n\n#### Make sure plugin and script are loaded first\n\nThe analytics script tag is not properly loaded into the DOM. You can fix this by moving the plugin to the top of your `gatsby-config.js` and into the head of the DOM:\n\n```javascript\nmodule.exports = {\n  siteMetadata: {\n    /* your metadata */\n  },\n  plugins: [\n    // Make sure this plugin is first in the array of plugins\n    {\n      resolve: `gatsby-plugin-google-analytics`,\n      options: {\n        trackingId: \"UA-111111111-1\",\n        // this option places the tracking script into the head of the DOM\n        head: true,\n        // other options\n      },\n    },\n  ],\n  // other plugins\n}\n```\n","publish_time":1764189500237,"_cnpm_publish_time":1764189500237,"dist-tags":{"alpha-9689ff":"4.23.0-alpha-9689ff.25","alpha-a5-peer":"4.23.0-alpha-a5-peer.70","alpha-qe-sm":"3.14.0-alpha-qe-sm.46","alpha-transformer-json":"4.14.0-alpha-transformer-json.26","alpha-ts-jit":"4.6.0-alpha-ts-jit.60","alpha-v5":"5.0.0-alpha-v5.d20221012t101120.57","dev-ssr-2":"2.3.14-dev-ssr-2.390","drupal-proxyurl":"5.0.0-alpha-drupal-proxyurl.14","drupal-self-reference":"4.18.0-alpha-drupal-self-reference.18","image-helpers":"2.6.0-image-helpers.58","image-service":"4.8.0-alpha-image-service.24","latest":"5.16.0","latest-v3":"3.15.0","latest-v4":"4.25.0","next":"5.17.0-next.0","otp-test":"2.1.12-otp-test.31","preview-gh-api":"4.23.0-alpha-preview-gh-api.26","reach-router":"3.0.0-reach-router.143","react19":"5.18.0-react19.1","unifiedroutes":"2.2.4-unifiedroutes.76","v3rc":"3.0.0-v3rc.0","wp-image-cdn-auth":"4.15.0-alpha-wp-image-cdn-auth.48"}}