{"_id":"@analytics/google-analytics-v3","_rev":"3-1a7efb8ff64688987fd82b908daa1ed3","name":"@analytics/google-analytics-v3","dist-tags":{"latest":"0.7.0"},"versions":{"0.5.4":{"name":"@analytics/google-analytics-v3","version":"0.5.4","keywords":["analytics","analytics-project","analytics-plugin","GA","google-analytics","Google Analytics"],"author":{"name":"David Wells"},"license":"MIT","_id":"@analytics/google-analytics-v3@0.5.4","maintainers":[{"name":"davidwells","email":"davidgregorywells@gmail.com"}],"homepage":"https://github.com/DavidWells/analytics#readme","bugs":{"url":"https://github.com/DavidWells/analytics/issues"},"dist":{"shasum":"bbeff78f20041df211695fac97bc390a0b9d7a73","tarball":"https://registry.npmjs.org/@analytics/google-analytics-v3/-/google-analytics-v3-0.5.4.tgz","fileCount":8,"integrity":"sha512-X93lI4T/OTEy9T83qvnInl21fkMKsUfh+4UvVtKZEfXz00t1tps/Qm8/kHBqDIwV06oFp10cR995Zl5MT9hLYQ==","signatures":[{"sig":"MEYCIQCmCzkB7ixk5IG6OKXDhvnPo4GH7mvfYi+2rDcvr4OizAIhAMXz+mkhhEM4i/bpntusRlj+rg9+8IgU/2XtGk53ifV8","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":92472,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJi2dafACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq0VQ/+MeDWMXv8QCHbnNKa++7gHrsQgbeubAxvxVxW0vKNjtZAIrJX\r\nwIZAN8xf4Lch4PnJOCwdFcboEMABPPUGxB6qAhex1ZDjnTuRXYGK819i4gN9\r\n+RpgsJDCIH4wiueFM7xZPab/4O56BTMJs/FCnGgp3DInZC76Ellt/mtYPfB0\r\n8JXkW/oUyrVo/I7QnJLhAejCtMdRzWNYwDjNQZYzDFNqm4wj40FbpASggK/a\r\nU18oTZxCM++2DHEAlaolOygmJMiKG849i+ADonj5uq/ZKKoIn/tVvdklibgw\r\ny7CAqcsSEWRFFmEh0M8kaftwjbmM2/FXumEwnBJtsm9Bj2jUolXMBqyTrO5A\r\n6lopF8P5+v8wfD1Tk5BNWU/sCq/cc7Y2XDHFja2KeKe3kasbZSkqmvZNdQwU\r\nWQXh6RvsNdt5Sw42K42kvrprqUC+IntP2N4Puj7vhotjwoCMwKkQpK0fB9Pr\r\nR11WJTIOpMe6uD89eN/5whFWY6mzIaUtW4sXN5U40fhGzrEgPe0KjAgffqua\r\nbj2AL06ZjOdbqHdX8z2xl+Kz0nmwgC6ql7O51w7m0ORQYWR0grpYI6MEoNMn\r\nNxp5iYsgFYY1XXJ7U/OdZcdz1fczAn2iMxncsgtZ6FuIC6ml6dGFyMN13quN\r\nSPiHozbz7tQ08aA2v67+8ShEF3IJ+LkMcrs=\r\n=w5yV\r\n-----END PGP SIGNATURE-----\r\n"},"main":"lib/analytics-plugin-ga.cjs.js","module":"lib/analytics-plugin-ga.es.js","browser":{"./lib/analytics-plugin-ga.es.js":"./lib/analytics-plugin-ga.browser.es.js","./lib/analytics-plugin-ga.cjs.js":"./lib/analytics-plugin-ga.browser.cjs.js"},"scripts":{"es":"../../node_modules/.bin/babel-node ./testBabel.js","build":"node ../../scripts/build/index.js","types":"../../node_modules/.bin/jsdoc -t ../../node_modules/tsd-jsdoc/dist -r ./src/ -d temp-types","watch":"node ../../scripts/build/_watch.js","release:major":"npm version major && npm publish","release:minor":"npm version minor && npm publish","release:patch":"npm version patch && npm publish"},"_npmUser":{"name":"davidwells","email":"davidgregorywells@gmail.com"},"globalName":"analyticsGa","repository":{"url":"git+https://github.com/DavidWells/analytics.git","type":"git"},"_npmVersion":"7.20.3","description":"Google analytics v3 plugin for 'analytics' module","directories":{},"jsnext:main":"lib/analytics-plugin-ga.es.js","projectMeta":{"provider":{"url":"https://analytics.google.com/analytics/web/","name":"Google Analytics"},"platforms":{"node":"./src/node.js","browser":"./src/browser.js"},"windowGlobal":"analyticsGa3"},"_nodeVersion":"16.6.1","dependencies":{"universal-analytics":"^0.4.20"},"_hasShrinkwrap":false,"devDependencies":{"@babel/core":"^7.2.2","@babel/preset-env":"^7.3.1"},"_npmOperationalInternal":{"tmp":"tmp/google-analytics-v3_0.5.4_1658443423562_0.21693928936566254","host":"s3://npm-registry-packages"}},"0.6.0":{"name":"@analytics/google-analytics-v3","version":"0.6.0","keywords":["analytics","analytics-project","analytics-plugin","GA","google-analytics","Google Analytics"],"author":{"name":"David Wells"},"license":"MIT","_id":"@analytics/google-analytics-v3@0.6.0","maintainers":[{"name":"davidwells","email":"davidgregorywells@gmail.com"}],"homepage":"https://github.com/DavidWells/analytics#readme","bugs":{"url":"https://github.com/DavidWells/analytics/issues"},"dist":{"shasum":"80a191c25e6d3095ff7b52201af91327aa9c2670","tarball":"https://registry.npmjs.org/@analytics/google-analytics-v3/-/google-analytics-v3-0.6.0.tgz","fileCount":10,"integrity":"sha512-v4c47UN3yzm6P1BaJJxw2+KBRTU5tVYPdNEJVb0S6tktDDlFjjVHK+9OA4WSmdFPcTacyp2QC+BIq1t2trcpSQ==","signatures":[{"sig":"MEUCIBrb2mw0F306K4tvfJ26nKNJlEz97jo0Pc3rNEaRuD7zAiEAkrLW/lScmd1Mr3d21p7BsNnuPwTLwcwHUVOE0PGWMVU=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":97330,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJi2df1ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpSKg/9FpTpjNdsBCWi+QrJIFFwmJW5pmo2pIj3c+RUyyKTsuHdlkcc\r\nSVTyous0m+Afd4jIkOhKC3Db7cZoD9YEDbpTdzVi2Qy/yN6IdUqIa+5N1b7T\r\nwRSyLJoQC0YmHGPZTqmIkDAnzN7OQnl74WO+5OXO6q84j2gkwO5XpN+TocjQ\r\n4lh0lbmcnUaHvms5SbsD28oDf7UJSyOEgeYev7VK2f1VMXXqIVqfediBDR6K\r\ns3rKyEL9ftAqaum+gEcCmyY89pLURJzlvZHCONDFwCr8psEXR4y4B1vBBm1L\r\n1meuUW5wJg0ln8a/DAB0zzcPuPGbJQavDELHP3p9KJV5Rr8R46mCoKlnXqS0\r\nN1OWJtQrQENM5pyigIn94hS2b8gOZDaxU3ooY1CVhS7BTf0wi+hcsd8CDjpK\r\nZ5Ugzi827Tzsx9xfWjY/Hni0oKWFzZKJh8DcSBTKpK01AKGJ8wmpmVnasBVD\r\nMcq1kd9RgCGsodTZ64LQYH818ukBryRZX6hdxrQUG130CQeEH4ZqDFJZgnkT\r\nldXt7bt9zRjqWpSSiu8pPMvbCoSemXmELn7ro3sDXr53H2YTdGunwV3i1wAn\r\nn5SbLB/IvJ143iGitXgVhnJNAUTN9ilcuP5NCTQYajrJCQFUgrqxWxGc76lT\r\nBrKegDASd8CwkqOk5MPpOUeSb4PY1Xg3ARw=\r\n=xvu5\r\n-----END PGP SIGNATURE-----\r\n"},"main":"lib/analytics-plugin-ga.cjs.js","module":"lib/analytics-plugin-ga.es.js","browser":{"./lib/analytics-plugin-ga.es.js":"./lib/analytics-plugin-ga.browser.es.js","./lib/analytics-plugin-ga.cjs.js":"./lib/analytics-plugin-ga.browser.cjs.js"},"gitHead":"10f3cd37e9c0868729c7c3d344b8985d17657069","scripts":{"es":"../../node_modules/.bin/babel-node ./testBabel.js","build":"node ../../scripts/build/index.js","types":"../../node_modules/.bin/jsdoc -t ../../node_modules/tsd-jsdoc/dist -r ./src/ -d temp-types","watch":"node ../../scripts/build/_watch.js","release:major":"npm version major && npm publish","release:minor":"npm version minor && npm publish","release:patch":"npm version patch && npm publish"},"_npmUser":{"name":"davidwells","email":"davidgregorywells@gmail.com"},"globalName":"analyticsGa","repository":{"url":"git+https://github.com/DavidWells/analytics.git","type":"git"},"_npmVersion":"lerna/3.22.1/node@v16.6.1+x64 (darwin)","description":"Google analytics v3 plugin for 'analytics' module","directories":{},"jsnext:main":"lib/analytics-plugin-ga.es.js","projectMeta":{"provider":{"url":"https://analytics.google.com/analytics/web/","name":"Google Analytics"},"platforms":{"node":"./src/node.js","browser":"./src/browser.js"},"windowGlobal":"analyticsGa3"},"_nodeVersion":"16.6.1","dependencies":{"universal-analytics":"^0.4.20"},"_hasShrinkwrap":false,"devDependencies":{"@babel/core":"^7.2.2","@babel/preset-env":"^7.3.1"},"_npmOperationalInternal":{"tmp":"tmp/google-analytics-v3_0.6.0_1658443765317_0.5652722349885062","host":"s3://npm-registry-packages"}},"0.6.1":{"name":"@analytics/google-analytics-v3","version":"0.6.1","keywords":["analytics","analytics-project","analytics-plugin","GA","google-analytics","Google Analytics"],"author":{"name":"David Wells"},"license":"MIT","_id":"@analytics/google-analytics-v3@0.6.1","maintainers":[{"name":"davidwells","email":"davidgregorywells@gmail.com"}],"homepage":"https://github.com/DavidWells/analytics#readme","bugs":{"url":"https://github.com/DavidWells/analytics/issues"},"dist":{"shasum":"8145bf548929cebd41af964f050577b186516fda","tarball":"https://registry.npmjs.org/@analytics/google-analytics-v3/-/google-analytics-v3-0.6.1.tgz","fileCount":10,"integrity":"sha512-CE0oBPK30TegytLS505t1ixesznO4Nx6VD9X8GjJC+bgqwQ1HdCbuILZcOnhVVpH9UyHDYWCgaAbJ0eGim3dVA==","signatures":[{"sig":"MEUCIQDDIzaVAkWfZglKRGVpr0jizQYZFN/vXa/PMWcm80G8lgIgY2z2u9ak9uhj2MBv5kwg+4r3UvHv/CUO7mqvjJzTV6c=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":97556,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJi2tOJACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqS0Q//VCWkhdFtmpA0sOshfzRtXA+wt8XXx8L2IOB0qKgzM/BsiH9v\r\n62Vj6mTT2oByD+ROHXVBaorh04wceqGYEa6gSkna5Eqe56lrV1qCEdukxnIv\r\n8QfIPcnuI45RWLPG+2mNj0ZYm1ehQOWR8JznKiLi9XqiE020s9ih0hKSijHI\r\n6plNmquQ2S8oqwAbOb6J2GhsPf8SDZjCeux5aclaQZfI1ETuzvYHfCDwUmiD\r\n175EoAhPEPVkVCh17VkwZunmPMM/3oUQ4KVQBJof1oeEut8em6Kd93LNkP7S\r\ndcKjCi8BoZ2i+rKroAINMYZXEEwyHHFJsL0x+dshTf0q4rWDbpeSP1zqSsL4\r\nIaUipKZickSoA22kkFTnhxinArAi2ptMIwXPu1dyHyHnCdkfu23flFzFE5+I\r\nFKd0sQh9+YvQBpbTC0CUCrEKsPEl9covaASSwrrG4z3Uka+ABalXh4CHlLsQ\r\nepVOor3fGMNElpNWS/ciVBwkeppSaKltQTA2gxpEPUEqI3P1NJeIPilDEp0z\r\nrvIevsH7HW46CxHBJ+PFN2UliL0dhl3IbJr1/dP0HbSf9mjHrAyM1nkv/paG\r\nNPoSkRSa62W0zCEKTiExX0x8WY1vxNC7EmA4s+Fq7OT4X71DWPb/r2eeDHf/\r\nFIRuB2d38urd0eLg3iM1cmC2zWrkGjvHclM=\r\n=tMKH\r\n-----END PGP SIGNATURE-----\r\n"},"main":"lib/analytics-plugin-ga.cjs.js","module":"lib/analytics-plugin-ga.es.js","browser":{"./lib/analytics-plugin-ga.es.js":"./lib/analytics-plugin-ga.browser.es.js","./lib/analytics-plugin-ga.cjs.js":"./lib/analytics-plugin-ga.browser.cjs.js"},"gitHead":"cce14c45bd1aeb666627e77945623f2e6603cb6d","scripts":{"es":"../../node_modules/.bin/babel-node ./testBabel.js","build":"node ../../scripts/build/index.js","types":"../../node_modules/.bin/jsdoc -t ../../node_modules/tsd-jsdoc/dist -r ./src/ -d temp-types","watch":"node ../../scripts/build/_watch.js","release:major":"npm version major && npm publish","release:minor":"npm version minor && npm publish","release:patch":"npm version patch && npm publish"},"_npmUser":{"name":"davidwells","email":"davidgregorywells@gmail.com"},"globalName":"analyticsGa","repository":{"url":"git+https://github.com/DavidWells/analytics.git","type":"git"},"_npmVersion":"lerna/3.22.1/node@v16.15.1+arm64 (darwin)","description":"Google analytics v3 plugin for 'analytics' module","directories":{},"jsnext:main":"lib/analytics-plugin-ga.es.js","projectMeta":{"provider":{"url":"https://analytics.google.com/analytics/web/","name":"Google Analytics"},"platforms":{"node":"./src/node.js","browser":"./src/browser.js"},"windowGlobal":"analyticsGa3"},"_nodeVersion":"16.15.1","dependencies":{"universal-analytics":"^0.4.20"},"_hasShrinkwrap":false,"devDependencies":{"@babel/core":"^7.2.2","@babel/preset-env":"^7.3.1"},"_npmOperationalInternal":{"tmp":"tmp/google-analytics-v3_0.6.1_1658508169602_0.4163612558241778","host":"s3://npm-registry-packages"}},"0.7.0":{"name":"@analytics/google-analytics-v3","version":"0.7.0","description":"Google analytics v3 plugin for 'analytics' module","projectMeta":{"provider":{"name":"Google Analytics","url":"https://analytics.google.com/analytics/web/"},"windowGlobal":"analyticsGa3","platforms":{"browser":"./src/browser.js","node":"./src/node.js"}},"keywords":["analytics","analytics-project","analytics-plugin","GA","google-analytics","Google Analytics"],"author":{"name":"David Wells"},"license":"MIT","scripts":{"types":"../../node_modules/.bin/jsdoc -t ../../node_modules/tsd-jsdoc/dist -r ./src/ -d temp-types","build":"node ../../scripts/build/index.js","watch":"node ../../scripts/build/_watch.js","release:patch":"npm version patch && npm publish","release:minor":"npm version minor && npm publish","release:major":"npm version major && npm publish","es":"../../node_modules/.bin/babel-node ./testBabel.js"},"main":"lib/analytics-plugin-ga.cjs.js","globalName":"analyticsGa","jsnext:main":"lib/analytics-plugin-ga.es.js","module":"lib/analytics-plugin-ga.es.js","browser":{"./lib/analytics-plugin-ga.cjs.js":"./lib/analytics-plugin-ga.browser.cjs.js","./lib/analytics-plugin-ga.es.js":"./lib/analytics-plugin-ga.browser.es.js"},"homepage":"https://github.com/DavidWells/analytics#readme","repository":{"type":"git","url":"git+https://github.com/DavidWells/analytics.git"},"devDependencies":{"@babel/core":"^7.2.2","@babel/preset-env":"^7.3.1"},"dependencies":{"universal-analytics":"^0.4.20"},"gitHead":"8730d1b0e462f7bd2ae1b4cadd175c166ea5ffef","bugs":{"url":"https://github.com/DavidWells/analytics/issues"},"_id":"@analytics/google-analytics-v3@0.7.0","_nodeVersion":"16.20.2","_npmVersion":"lerna/3.22.1/node@v16.20.2+arm64 (darwin)","dist":{"integrity":"sha512-t8QcC9SZ4c/vFa329eLfxx6I83TkeeEo8622Dqvfk6zecrPFb6pP33t3e//2IRJ+d6n6XXTNSl8AIQWOLBWHIA==","shasum":"e3e23f429f2b29e4c6ef3d4a0364e6d5e6cbb16c","tarball":"https://registry.npmjs.org/@analytics/google-analytics-v3/-/google-analytics-v3-0.7.0.tgz","fileCount":10,"unpackedSize":99256,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICECLaOHWBcNwl2zggPODotLAJYJIRAk74wX1Ezg90nIAiBKbj7nsmYhBFWJAhpRnAVldOTN1FOkw64HjEgRfvhAxA=="}]},"_npmUser":{"name":"davidwells","email":"davidgregorywells@gmail.com"},"directories":{},"maintainers":[{"name":"davidwells","email":"davidgregorywells@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/google-analytics-v3_0.7.0_1733954926759_0.3100163573127914"},"_hasShrinkwrap":false}},"time":{"created":"2022-07-21T22:43:43.481Z","modified":"2024-12-11T22:08:47.230Z","0.5.4":"2022-07-21T22:43:43.721Z","0.6.0":"2022-07-21T22:49:25.466Z","0.6.1":"2022-07-22T16:42:49.812Z","0.7.0":"2024-12-11T22:08:47.059Z"},"bugs":{"url":"https://github.com/DavidWells/analytics/issues"},"author":{"name":"David Wells"},"license":"MIT","homepage":"https://github.com/DavidWells/analytics#readme","keywords":["analytics","analytics-project","analytics-plugin","GA","google-analytics","Google Analytics"],"repository":{"type":"git","url":"git+https://github.com/DavidWells/analytics.git"},"description":"Google analytics v3 plugin for 'analytics' module","maintainers":[{"name":"davidwells","email":"davidgregorywells@gmail.com"}],"readme":"<!--\ntitle: Adding Google Analytics v3 (Universal analytics) to your app using open source analytics\ndescription: Connect Google Analytics v3 to the analytics library\npageTitle: Google Analytics v3\n-->\n\n# Google Analytics v3 (Universal analytics)\n\nThis library exports the `@analytics/google-analytics-v3` plugin for the [`analytics`](https://www.npmjs.com/package/analytics) package & standalone methods for any project to use to make it easier to interact with [Google Analytics](https://analytics.google.com/analytics/web/).\n\nThis analytics plugin will load google analytics into your application.\n\nFor more information [see the docs](https://getanalytics.io/plugins/google-analytics-v3/).\n\n## Upgrading to google analytics v4\n\n**Note:** GA3 will be deprecated starting in July of 2023. You may probably want to change to Google Analytics 4. \n\nFor the newer version of google analytics please see the [`@analytics/google-analytics` package](https://www.npmjs.com/package/@analytics/google-analytics) or the [GA4 plugin docs](https://getanalytics.io/plugins/google-analytics/)\n\n<!-- AUTO-GENERATED-CONTENT:START (TOC:collapse=true&collapseText=Click to expand) -->\n<details>\n<summary>Click to expand</summary>\n\n- [Upgrading to google analytics v4](#upgrading-to-google-analytics-v4)\n- [Installation](#installation)\n- [How to use](#how-to-use)\n- [Platforms Supported](#platforms-supported)\n- [Browser usage](#browser-usage)\n  - [Browser API](#browser-api)\n  - [Configuration options for browser](#configuration-options-for-browser)\n- [Server-side usage](#server-side-usage)\n  - [Server-side API](#server-side-api)\n  - [Configuration options for server-side](#configuration-options-for-server-side)\n- [Additional examples](#additional-examples)\n- [Anonymize Visitor IPs](#anonymize-visitor-ips)\n- [Customizing event payloads](#customizing-event-payloads)\n- [Using GA Custom Dimensions](#using-ga-custom-dimensions)\n  - [Set the \"customDimensions\" option](#set-the-customdimensions-option)\n- [Using multiple instances](#using-multiple-instances)\n- [Custom Proxy Endpoint](#custom-proxy-endpoint)\n- [Electron Apps & Browser Extensions](#electron-apps--browser-extensions)\n- [Custom GA Tasks](#custom-ga-tasks)\n- [Cookie Config](#cookie-config)\n\n</details>\n<!-- AUTO-GENERATED-CONTENT:END -->\n\n## Installation\n\n```bash\nnpm install analytics\nnpm install @analytics/google-analytics-v3\n```\n\n<!-- AUTO-GENERATED-CONTENT:START (PLUGIN_DOCS) -->\n\n## How to use\n\nThe `@analytics/google-analytics-v3` package works in [the browser](#browser-usage) and [server-side in Node.js](#server-side-usage). To use, install the package, include in your project and initialize the plugin with [analytics](https://www.npmjs.com/package/analytics).\n\nBelow is an example of how to use the browser plugin.\n\n```js\nimport Analytics from 'analytics'\nimport googleAnalyticsV3 from '@analytics/google-analytics-v3'\n\nconst analytics = Analytics({\n  app: 'awesome-app',\n  plugins: [\n    googleAnalyticsV3({\n      trackingId: 'UA-1234567'\n    })\n  ]\n})\n\n/* Track a page view */\nanalytics.page()\n\n/* Track a custom event */\nanalytics.track('playedVideo', {\n  category: 'Videos',\n  label: 'Fall Campaign',\n  value: 42\n})\n\n/* Identify a visitor */\nanalytics.identify('user-id-xyz', {\n  firstName: 'bill',\n  lastName: 'murray'\n})\n\n```\n\nAfter initializing `analytics` with the `googleAnalyticsV3` plugin, data will be sent into Google Analytics whenever [analytics.page](https://getanalytics.io/api/#analyticspage), [analytics.track](https://getanalytics.io/api/#analyticstrack), or [analytics.identify](https://getanalytics.io/api/#analyticsidentify) are called.\n\nSee [additional implementation examples](#additional-examples) for more details on using in your project.\n\n## Platforms Supported\n\nThe `@analytics/google-analytics-v3` package works in [the browser](#browser-usage) and [server-side in Node.js](#server-side-usage)\n\n## Browser usage\n\nThe Google Analytics client side browser plugin works with these analytic api methods:\n\n- **[analytics.page](https://getanalytics.io/api/#analyticspage)** - Sends page views into Google Analytics\n- **[analytics.track](https://getanalytics.io/api/#analyticstrack)** - Track custom events and send to Google Analytics\n- **[analytics.identify](https://getanalytics.io/api/#analyticsidentify)** - Identify visitors and send details to Google Analytics\n\n### Browser API\n\n```js\nimport Analytics from 'analytics'\nimport googleAnalyticsV3 from '@analytics/google-analytics-v3'\n\nconst analytics = Analytics({\n  app: 'awesome-app',\n  plugins: [\n    googleAnalyticsV3({\n      trackingId: 'UA-1234567'\n    })\n  ]\n})\n\n```\n\n### Configuration options for browser\n\n| Option                                                | description |\n|:------------------------------------------------------|:-----------|\n| `trackingId` <br/>**required** - string               | Google Analytics site tracking Id |\n| `debug` <br/>_optional_ - boolean                     | Enable Google Analytics debug mode |\n| `anonymizeIp` <br/>_optional_ - boolean               | Enable [Anonymizing IP addresses](https://bit.ly/3c660Rd) sent to Google Analytics. [See details below](#anonymize-visitor-ips) |\n| `customDimensions` <br/>_optional_ - object           | Map [Custom dimensions](https://bit.ly/3c5de88) to send extra information to Google Analytics. [See details below](#using-ga-custom-dimensions) |\n| `resetCustomDimensionsOnPage` <br/>_optional_ - object| Reset custom dimensions by key on analytics.page() calls. Useful for single page apps. |\n| `setCustomDimensionsToPage` <br/>_optional_ - boolean | Mapped dimensions will be set to the page & sent as properties of all subsequent events on that page. If false, analytics will only pass custom dimensions as part of individual events |\n| `instanceName` <br/>_optional_ - string               | Custom tracker name for google analytics. Use this if you need multiple googleAnalytics scripts loaded |\n| `customScriptSrc` <br/>_optional_ - string            | Custom URL for google analytics script, if proxying calls |\n| `cookieConfig` <br/>_optional_ - object               | Additional cookie properties for configuring the [ga cookie](https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id#configuring_cookie_field_settings) |\n| `tasks` <br/>_optional_ - object                      | [Set custom google analytic tasks](https://developers.google.com/analytics/devguides/collection/analyticsjs/tasks) |\n| `nonce` <br/>_optional_ - string                      | Content-Security-Policy nonce value                            |\n\n## Server-side usage\n\nThe Google Analytics server-side node.js plugin works with these analytic api methods:\n\n- **[analytics.page](https://getanalytics.io/api/#analyticspage)** - Sends page views into Google Analytics\n- **[analytics.track](https://getanalytics.io/api/#analyticstrack)** - Track custom events and send to Google Analytics\n- **[analytics.identify](https://getanalytics.io/api/#analyticsidentify)** - Identify visitors and send details to Google Analytics\n\n### Server-side API\n\n```js\nimport Analytics from 'analytics'\nimport googleAnalytics from '@analytics/google-analytics-v3'\n\nconst analytics = Analytics({\n  app: 'awesome-app',\n  plugins: [\n    googleAnalytics({\n      trackingId: '123-xyz'\n    })\n  ]\n})\n\n```\n\n### Configuration options for server-side\n\n| Option | description |\n|:---------------------------|:-----------|\n| `trackingId` <br/>**required** - string| Google Analytics site tracking Id |\n\n\n## Additional examples\n\nBelow are additional implementation examples.\n\n<details>\n  <summary>Server-side ES6</summary>\n\n  ```js\n  import Analytics from 'analytics'\n  import googleAnalytics from '@analytics/google-analytics-v3'\n\n  const analytics = Analytics({\n    app: 'awesome-app',\n    plugins: [\n      googleAnalytics({\n        trackingId: '123-xyz'\n      })\n      // ...other plugins\n    ]\n  })\n\n  /* Track a page view */\n  analytics.page()\n\n  /* Track a custom event */\n  analytics.track('cartCheckout', {\n    item: 'pink socks',\n    price: 20\n  })\n\n  /* Identify a visitor */\n  analytics.identify('user-id-xyz', {\n    firstName: 'bill',\n    lastName: 'murray'\n  })\n\n  ```\n\n</details>\n\n<details>\n  <summary>Server-side Node.js with common JS</summary>\n\n  If using node, you will want to import the `.default`\n\n  ```js\n  const analyticsLib = require('analytics').default\n  const googleAnalytics = require('@analytics/google-analytics-v3').default\n\n  const analytics = analyticsLib({\n    app: 'my-app-name',\n    plugins: [\n      googleAnalytics({\n        trackingId: '123-xyz'\n      })\n    ]\n  })\n\n  /* Track a page view */\n  analytics.page()\n\n  /* Track a custom event */\n  analytics.track('cartCheckout', {\n    item: 'pink socks',\n    price: 20\n  })\n\n  /* Identify a visitor */\n  analytics.identify('user-id-xyz', {\n    firstName: 'bill',\n    lastName: 'murray'\n  })\n\n  ```\n\n</details>\n\n<details>\n  <summary>Using in HTML</summary>\n\n  Below is an example of importing via the unpkg CDN. Please note this will pull in the latest version of the package.\n\n  ```html\n  <!DOCTYPE html>\n  <html>\n    <head>\n      <title>Using @analytics/google-analytics-v3 in HTML</title>\n      <script src=\"https://unpkg.com/analytics/dist/analytics.min.js\"></script>\n      <script src=\"https://unpkg.com/@analytics/google-analytics-v3/dist/@analytics/google-analytics-v3.min.js\"></script>\n      <script type=\"text/javascript\">\n        /* Initialize analytics */\n        var Analytics = _analytics.init({\n          app: 'my-app-name',\n          plugins: [\n            analyticsGa.init({\n              trackingId: 'UA-1234567'\n            })\n          ]\n        })\n\n        /* Track a page view */\n        analytics.page()\n\n        /* Track a custom event */\n        analytics.track('playedVideo', {\n          category: 'Videos',\n          label: 'Fall Campaign',\n          value: 42\n        })\n\n        /* Identify a visitor */\n        analytics.identify('user-id-xyz', {\n          firstName: 'bill',\n          lastName: 'murray'\n        })\n      </script>\n    </head>\n    <body>\n      ....\n    </body>\n  </html>\n\n  ```\n\n</details>\n\n<details>\n  <summary>Using in HTML via ES Modules</summary>\n\n  Using `@analytics/google-analytics-v3` in ESM modules.\n\n  ```html\n  <!DOCTYPE html>\n  <html>\n    <head>\n      <title>Using @analytics/google-analytics-v3 in HTML via ESModules</title>\n      <script>\n        // Polyfill process.\n        // **Note**: Because `import`s are hoisted, we need a separate, prior <script> block.\n        window.process = window.process || { env: { NODE_ENV: 'production' } }\n      </script>\n      <script type=\"module\">\n        import analytics from 'https://unpkg.com/analytics/lib/analytics.browser.es.js?module'\n        import analyticsGa from 'https://unpkg.com/@analytics/google-analytics-v3/lib/analytics-plugin-ga.browser.es.js?module'\n        /* Initialize analytics */\n        const Analytics = analytics({\n          app: 'analytics-html-demo',\n          debug: true,\n          plugins: [\n            analyticsGa({\n              trackingId: 'UA-1234567'\n            })\n            // ... add any other third party analytics plugins\n          ]\n        })\n\n        /* Track a page view */\n        analytics.page()\n\n        /* Track a custom event */\n        analytics.track('playedVideo', {\n          category: 'Videos',\n          label: 'Fall Campaign',\n          value: 42\n        })\n\n        /* Identify a visitor */\n        analytics.identify('user-id-xyz', {\n          firstName: 'bill',\n          lastName: 'murray'\n        })\n      </script>\n    </head>\n    <body>\n      ....\n    </body>\n  </html>\n\n  ```\n\n</details>\n\n\n<!-- AUTO-GENERATED-CONTENT:END (PLUGIN_DOCS) -->\n\n\n## Anonymize Visitor IPs\n\nGoogle analytics allows you to [anonymize visitor IP addresses](https://developers.google.com/analytics/devguides/collection/analyticsjs/ip-anonymization).\n\nTo anonymize the IP addresses of your visitors set the `anonymizeIp` configuration option.\n\n```js\nimport Analytics from 'analytics'\nimport googleAnalytics from '@analytics/google-analytics-v3'\n\n/* initialize analytics */\nconst analytics = Analytics({\n  app: 'awesome-app',\n  plugins: [\n    googleAnalytics({\n      trackingId: 'UA-1223141231',\n      /* Anonymize the IP addresses */\n      anonymizeIp: true\n    }),\n  ]\n})\n```\n\n## Customizing event payloads\n\nTo send tracking custom events to Google Analytics with `eventLabel`, `eventCategory`, and `eventValue` [fields](https://developers.google.com/analytics/devguides/collection/analyticsjs/events#event_fields), add the `label`, `category`, and `value` keys to the event properties.\n\n```js\nanalytics.track('play', {\n  category: 'Videos',\n  label: 'Fall Campaign',\n  value: 42\n})\n```\n\n## Using GA Custom Dimensions\n\nTo use [Google Analytics custom dimensions](https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets), use the `customDimensions` configuration option and map the values to the custom dimension slots.\n\n### Set the \"customDimensions\" option\n\nWhen initializing `analytics`, make sure you set `customDimensions` and map your values.\n\n```js\nimport Analytics from 'analytics'\nimport googleAnalytics from '@analytics/google-analytics-v3'\n\n/* initialize analytics */\nconst analytics = Analytics({\n  app: 'awesome-app',\n  plugins: [\n    googleAnalytics({\n      trackingId: 'UA-1223141231',\n      /* Map your Google Analytics custom dimensions here */\n      customDimensions: {\n        baz: 'dimension1',\n        foo: 'dimension2',\n        flam: 'dimension3',\n      },\n    }),\n  ]\n})\n```\n\nThe above config will map **baz** to `dimension1`, **foo** to `dimension2`, and **flam** to `dimension3`\n\nWhen `track`, `page`, or `identify` calls are made, the mapped values will automatically set to Google Analytics custom dimensions.\n\n```js\n/* Tracking example */\nanalytics.track('buttonClicked', {\n   baz: 'hello', // baz is mapped to GA custom dimension \"dimension1\"\n   foo: 'cool'   // foo is mapped to GA custom dimension \"dimension2\"\n})\n```\n\nUnder the hood, analytics automatically sets the custom dimensions in Google Analytics like so:\n\n```js\nwindow.ga('set', {dimension1: 'hello', dimension2: 'cool'})\n```\n\nThis also works with page & identify calls.\n\n```js\n/* Identify example */\nanalytics.identify('user123', {\n   flam: 'wow' // flam is mapped to GA custom dimension \"dimension3\"\n})\n\n// This is mapped to window.ga('set', {  dimension3: 'wow' })\n```\n\n## Using multiple instances\n\nWhile not advised, it's possible to use [multiple Google Analytics instances](https://developers.google.com/analytics/devguides/collection/analyticsjs/creating-trackers#working_with_multiple_trackers) on a single site.\n\nTo use more than one google analytics instance in an app use the `instanceName` config field and make sure to override the default plugin `name`.\n\nHere is an example of using 2 Google Analytics instances in an app.\n\n```js\nimport Analytics from 'analytics'\nimport googleAnalytics from '@analytics/google-analytics-v3'\n\n// Normal google analytics instance\nconst instanceOne = googleAnalytics({\n  trackingId: '123-xyz',\n})\n\n// Second google analytics instance with override for 'name' field of the plugin\nconst instanceTwo = {\n  // initialize the 2nd instance with 'instanceName' field set\n  ...googleAnalytics({\n    trackingId: '567-abc',\n    instanceName: 'two'\n  }),\n  // change 'name' plugin to avoid namespace collisions\n  ...{\n    name: 'google-analytics-two'\n  }\n}\n\n/* Object.assign example\nconst instanceTwo = Object.assign({}, googleAnalytics({\n    trackingId: '567-abc',\n    instanceName: 'two'\n  }), {\n    name: 'google-analytics-two'\n  }\n}) */\n\nconst analytics = Analytics({\n  app: 'awesome-app',\n  plugins: [\n    // Instance 1 of Google Analytics\n    instanceOne,\n    // Instance 2 of Google Analytics\n    instanceTwo\n  ]\n})\n```\n\nUsing the above configuration all tracking, page views, and identify calls will flow into both Google Analytics accounts.\n\n## Custom Proxy Endpoint\n\nIn specific [scenarios](https://www.freecodecamp.org/news/save-your-analytics-from-content-blockers-7ee08c6ec7ee/), you might want to load your own version of google analytics to send requests to a proxy.\n\nTo do this, you can add the `customScriptSrc` option pointing to your custom Google Analytics script.\n\n```js\nimport Analytics from 'analytics'\nimport googleAnalytics from '@analytics/google-analytics-v3'\n\nconst analytics = Analytics({\n  app: 'awesome-app',\n  plugins: [\n    googleAnalytics({\n      trackingId: '123-xyz',\n      customScriptSrc: 'https://my-url.com/to-custom-ga.js'\n    })\n  ]\n})\n```\n\nIf using a proxied endpoint, it is recommended to combine this technique with the [do-not-track](https://getanalytics.io/plugins/do-not-track/) plugin to ensure website visitors privacy.\n\n## Electron Apps & Browser Extensions\n\nElectron apps bundle and serve their code from the `file://` extension. Likewise, browser extensions serve files from `chrome-extension://`. This causes issues like [this](https://github.com/DavidWells/analytics/issues/77) & [this](https://github.com/DavidWells/analytics/issues/72#issuecomment-681320271) with Google Analytics.\n\nTo fix chrome extensions, use the `tasks` configuration and set `checkProtocolTask` to `null`.\n\nTo fix electron apps, use the `tasks` configuration option described below and set `checkProtocolTask`, `checkStorageTask`, & `historyImportTask` to `null`.\n\nHere is an example:\n\n```js\nimport Analytics from 'analytics'\nimport googleAnalytics from '@analytics/google-analytics-v3'\n\n/* initialize analytics and load plugins */\nconst analytics = Analytics({\n  app: 'my-app',\n  plugins: [\n    googleAnalytics({\n      trackingId: '123-xyz',\n      // Override or disable GA Tasks https://bit.ly/31Xetmg\n      tasks: {\n        // Set checkProtocolTask, checkStorageTask, & historyImportTask for electron apps\n        checkProtocolTask: null,\n        checkStorageTask: null,\n        historyImportTask: null,\n      }\n    }),\n  ]\n})\n```\n\n## Custom GA Tasks\n\nIn specific scenarios, you might need to disable or alter the [default Google Analytic Tasks](https://bit.ly/31Xetmg).\n\nFor example, you might want to cancel a request or enrich it. You can do this via [analytics plugins](https://getanalytics.io/plugins/writing-plugins/) or use the `tasks` config option on GA plugin for access to the `tracker` instance for GA only.\n\nThe tasks that can be hooked into are listed below & in the [GA task docs](https://bit.ly/31Xetmg)\n\n- `customTask` By default, this task does nothing. Override it to provide custom behavior.\n- `previewTask`\tAborts the request if the page is only being rendered to generate a 'Top Sites' thumbnail for Safari.\n- `checkProtocolTask`\tAborts the request if the page protocol is not http or https.\n- `validationTask` Aborts the request if required fields are missing or invalid.\n- `checkStorageTask` Aborts the request if the tracker is configured to use cookies but the user's browser has cookies disabled.\n- `historyImportTask` Imports info from ga.js/urchin.js cookies to preserve history when a site migrates to Universal Analytics.\n- `samplerTask` Samples out visitors based on the sampleRate setting for this tracker.\n- `buildHitTask` Builds a measurement protocol request string and stores it in the hitPayload field.\n- `sendHitTask` Transmits the measurement protocol request stored in the hitPayload field to Google Analytics servers.\n- `timingTask` Automatically generates a site speed timing hit based on the siteSpeedSampleRate setting for this tracker.\n- `displayFeaturesTask` Sends an additional hit if display features is enabled & a previous hit has not been sent within the timeout period set by the advertising features cookie (_gat).\n\n```js\nimport Analytics from 'analytics'\nimport googleAnalytics from '@analytics/google-analytics-v3'\n\n/* initialize analytics and load plugins */\nconst analytics = Analytics({\n  app: 'cool-app',\n  plugins: [\n    googleAnalytics({\n      trackingId: '123-xyz',\n      // Override or disable GA Tasks https://bit.ly/31Xetmg\n      tasks: {\n        // https://developers.google.com/analytics/devguides/collection/analyticsjs/tasks#adding_to_a_task\n        sendHitTask: function (tracker) {\n          // Save original Task\n          var originalTask = tracker.get('sendHitTask')\n          // Modifies sendHitTask to send a copy of the request to a local server after\n          tracker.set('sendHitTask', function (model) {\n            // 1. Send the normal request to www.google-analytics.com/collect.\n            originalTask(model);\n            // 2. Send to local server\n            var xhr = new XMLHttpRequest();\n            xhr.open('POST', '/localhits', true);\n            xhr.send(model.get('hitPayload'));\n          })\n        },\n        // https://developers.google.com/analytics/devguides/collection/analyticsjs/tasks#aborting_task_processing\n        buildHitTask: (tracker) => {\n          // Save original Task\n          const originalBuildHitTask = tracker.get('buildHitTask')\n          // Set custom buildHitTask with abort\n          tracker.set('buildHitTask', function (model) {\n            if (document.cookie.match(/testing=true/)) {\n              throw new Error('Aborted tracking for test user.')\n            }\n            originalBuildHitTask(model);\n          })\n        },\n      }\n    }),\n  ]\n})\n```\n\n## Cookie Config\n\nSome situations require changing the [cookie properties](https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id#configuring_cookie_field_settings) of the Google Analytics cookie itself.\n\nThe GA Cookie fields that are available are:\n\n| Field Name | Value Type | Default value | Description |\n|:---------------------------|:-----------|:------------------|:---------------------|\n| `cookieName`| text| _ga | Name of the cookie used to store analytics data |\n| `cookieDomain`| text| The result of the following JavaScript expression: *document.location.hostname* | Specifies the domain used to store the analytics cookie. Setting this to 'none' sets the cookie without specifying a domain. |\n| `cookieExpires`| integer| *63072000* (two years, in seconds) | Specifies the cookie expiration, in seconds. |\n| `cookieUpdate`| boolean| true | When cookieUpdate is set to true (the default value), analytics.js will update cookies on each page load. This will update the cookie expiration to be set relative to the most recent visit to the site. |\n| `cookieFlags`| text | | Specifies additional flags to append to the cookie. Flags must be separated by semicolons. |\n\nYou can add these properties in the `cookieConfig` on the plugin config.\n\n```js\nimport Analytics from 'analytics'\nimport googleAnalytics from '@analytics/google-analytics-v3'\n\nconst analytics = Analytics({\n  app: 'awesome-app',\n  plugins: [\n    googleAnalytics({\n      trackingId: 'UA-1234567',\n      cookieConfig: {\n        cookieName: 'gaCookie',\n        cookieDomain: 'blog.example.co.uk',\n        cookieExpires: 60 * 60 * 24 * 28,  // Time in seconds.\n        cookieUpdate: 'false',\n        cookieFlags: 'SameSite=None; Secure',\n      }\n    })\n  ]\n})\n```\n","readmeFilename":"README.md"}