{"id":16836513,"url":"https://github.com/orangecms/gatsby-plugin-google-analytics","last_synced_at":"2025-03-18T03:19:19.096Z","repository":{"id":84739221,"uuid":"178201183","full_name":"orangecms/gatsby-plugin-google-analytics","owner":"orangecms","description":"A Gatsby plugin for consensual Google Analytics tracking.","archived":false,"fork":false,"pushed_at":"2019-04-08T14:30:23.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-24T10:24:57.275Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/orangecms.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-28T12:41:33.000Z","updated_at":"2019-04-08T14:30:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"cb44a00e-9cc3-43b0-ba47-092b8a8182a3","html_url":"https://github.com/orangecms/gatsby-plugin-google-analytics","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orangecms%2Fgatsby-plugin-google-analytics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orangecms%2Fgatsby-plugin-google-analytics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orangecms%2Fgatsby-plugin-google-analytics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orangecms%2Fgatsby-plugin-google-analytics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orangecms","download_url":"https://codeload.github.com/orangecms/gatsby-plugin-google-analytics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244147343,"owners_count":20405942,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T12:13:40.644Z","updated_at":"2025-03-18T03:19:19.073Z","avatar_url":"https://github.com/orangecms.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gatsby-plugin-google-analytics\n\nEasily add Google Analytics to your Gatsby site.\n\n## Install\n\n`npm install --save gatsby-plugin-google-analytics`\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        trackingId: \"YOUR_GOOGLE_ANALYTICS_TRACKING_ID\",\n        // Puts tracking script in the head instead of 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        // 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        // Any additional create only fields (optional)\n        sampleRate: 5,\n        siteSpeedSampleRate: 10,\n        cookieDomain: \"example.com\",\n      },\n    },\n  ],\n}\n```\n\nSee below for the complete list of [Create Only Fields](#create-only-fields).\n\n## `\u003cOutboundLink\u003e` 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 `\u003ca\u003e` element e.g.\n\n```jsx\nimport React\nimport { OutboundLink } from 'gatsby-plugin-google-analytics'\n\nexport default () =\u003e {\n  \u003cdiv\u003e\n    \u003cOutboundLink\n      href=\"https://www.gatsbyjs.org/packages/gatsby-plugin-google-analytics/\"\n    \u003e\n      Visit the Google Analytics plugin page!\n    \u003c/OutboundLink\u003e\n  \u003c/div\u003e\n}\n```\n\n## The \"anonymize\" option\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')\u003e-1\u0026\u0026(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`\u003ca href=\"javascript:gaOptout();\"\u003eDeactivate Google Analytics\u003c/a\u003e`\n\n## The \"respectDNT\" option\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\n## The \"exclude\" option\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## The \"optimizeId\" option\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## The \"experimentId\" option\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## The \"variationId\" option\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## Create Only 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- `cookieDomain`: string, defaults to `'auto'` if not given\n- `cookieExpires`: number\n- `storeGac`: boolean\n- `legacyCookieDomain`: string\n- `legacyHistoryImport`: boolean\n- `allowLinker`: boolean\n\nThese fields can be specified in the plugin's `options` as shown in the [How to use](#how-to-use) section.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forangecms%2Fgatsby-plugin-google-analytics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forangecms%2Fgatsby-plugin-google-analytics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forangecms%2Fgatsby-plugin-google-analytics/lists"}