{"id":13515299,"url":"https://github.com/DavidWells/analytics","last_synced_at":"2025-03-31T04:36:56.307Z","repository":{"id":37582557,"uuid":"154419993","full_name":"DavidWells/analytics","owner":"DavidWells","description":" Lightweight analytics abstraction layer for tracking page views, custom events, \u0026 identifying visitors         ","archived":false,"fork":false,"pushed_at":"2024-08-14T10:14:05.000Z","size":4165,"stargazers_count":2440,"open_issues_count":106,"forks_count":245,"subscribers_count":23,"default_branch":"master","last_synced_at":"2024-10-29T15:06:35.527Z","etag":null,"topics":["analytics","analytics-utils","gdpr-compliant","metrics","privacy","telemetry"],"latest_commit_sha":null,"homepage":"https://getanalytics.io","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/DavidWells.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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},"funding":{"github":["davidwells"]}},"created_at":"2018-10-24T01:29:28.000Z","updated_at":"2024-10-29T05:50:02.000Z","dependencies_parsed_at":"2023-02-09T16:16:35.009Z","dependency_job_id":"89cc9860-83e9-49fa-9d9d-6522621e547e","html_url":"https://github.com/DavidWells/analytics","commit_stats":{"total_commits":1662,"total_committers":77,"mean_commits":"21.584415584415584","dds":0.3838748495788207,"last_synced_commit":"505f0776845c07f1b15330e2c72db03c0bccbb99"},"previous_names":[],"tags_count":743,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavidWells%2Fanalytics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavidWells%2Fanalytics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavidWells%2Fanalytics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavidWells%2Fanalytics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DavidWells","download_url":"https://codeload.github.com/DavidWells/analytics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243796719,"owners_count":20349263,"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":["analytics","analytics-utils","gdpr-compliant","metrics","privacy","telemetry"],"created_at":"2024-08-01T05:01:09.066Z","updated_at":"2025-03-31T04:36:56.292Z","avatar_url":"https://github.com/DavidWells.png","language":"JavaScript","readme":"\u003ca href=\"https://getanalytics.io\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/532272/110860586-cc927e00-8271-11eb-95c7-44bdda78ab2a.png\" width=\"450\" /\u003e\n\u003c/a\u003e\n\n![npm](https://img.shields.io/npm/dm/analytics?style=flat-square) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/analytics?style=flat-square) ![GitHub](https://img.shields.io/github/license/davidwells/analytics?style=flat-square)\n\nA lightweight analytics abstraction library for tracking page views, custom events, \u0026 identify visitors. \n\nDesigned to work with any [third-party analytics tool](https://getanalytics.io/plugins/) or your own backend.\n\n[Read the docs](https://getanalytics.io/) or view the [live demo app](https://analytics-demo.netlify.app)\n\n## Table of Contents\n\u003c!-- AUTO-GENERATED-CONTENT:START (TOC:collapse=true\u0026collapseText=Click to expand) --\u003e\n\u003cdetails\u003e\n\u003csummary\u003eClick to expand\u003c/summary\u003e\n\n- [Features](#features)\n- [Why](#why)\n- [Install](#install)\n- [Usage](#usage)\n- [Demo](#demo)\n- [API](#api)\n  - [Configuration](#configuration)\n  - [analytics.identify](#analyticsidentify)\n  - [analytics.track](#analyticstrack)\n  - [analytics.page](#analyticspage)\n  - [analytics.user](#analyticsuser)\n  - [analytics.reset](#analyticsreset)\n  - [analytics.ready](#analyticsready)\n  - [analytics.on](#analyticson)\n  - [analytics.once](#analyticsonce)\n  - [analytics.getState](#analyticsgetstate)\n  - [analytics.storage](#analyticsstorage)\n  - [analytics.storage.getItem](#analyticsstoragegetitem)\n  - [analytics.storage.setItem](#analyticsstoragesetitem)\n  - [analytics.storage.removeItem](#analyticsstorageremoveitem)\n  - [analytics.plugins](#analyticsplugins)\n  - [analytics.plugins.enable](#analyticspluginsenable)\n  - [analytics.plugins.disable](#analyticspluginsdisable)\n- [Events](#events)\n- [Analytic plugins](#analytic-plugins)\n- [Community Plugins](#community-plugins)\n- [Creating analytics plugins](#creating-analytics-plugins)\n  - [React to any event](#react-to-any-event)\n  - [Custom methods](#custom-methods)\n- [Plugin Naming Conventions](#plugin-naming-conventions)\n- [Debugging analytics](#debugging-analytics)\n- [TypeScript support](#typescript-support)\n- [Contributing](#contributing)\n- [Setup \u0026 Install dependencies](#setup--install-dependencies)\n- [Development](#development)\n\n\u003c/details\u003e\n\u003c!-- AUTO-GENERATED-CONTENT:END --\u003e\n\n## Features\n\n- [x] [Extendable](#analytic-plugins) - Bring your own third-party tool \u0026 plugins\n- [x] Test \u0026 debug analytics integrations with time travel \u0026 offline mode\n- [x] Add functionality/modify tracking calls with baked in lifecycle hooks\n- [x] Isomorphic. Works in browser \u0026 on server\n- [x] Queues events to send when analytic libraries are loaded\n- [x] Conditionally load third party scripts\n- [x] Works offline\n- [x] [TypeScript support](https://getanalytics.io/tutorials/typesafe-analytics/)\n\n##  Why\n\nCompanies frequently change analytics requirements based on evolving needs. This results in a lot of complexity, maintenance, \u0026 extra code when adding/removing analytic services to a site or application.\n\nThis library aims to solves that with a simple pluggable abstraction layer.\n\n![how analytics works](https://user-images.githubusercontent.com/532272/68093602-42036880-fe4c-11e9-8bb9-008045da8a32.gif)\n\n**Driving philosophy:**\n\n- You should never be locked into an analytics tool\n- DX is paramount. Adding \u0026 removing analytic tools from your application should be easy\n- Respecting visitor privacy settings \u0026 allowing for opt-out mechanisms is crucial\n- A pluggable API makes adding new business requests easy\n\nTo add or remove an analytics provider, adjust the `plugins` you load into `analytics` during initialization.\n\n## Install\n\nThis module is distributed via [npm](https://npmjs.com/package/analytics), which is bundled with [node](https://nodejs.org/) and should be installed as one of your project's dependencies.\n\n```bash\nnpm install analytics --save\n```\n\nOr as a script tag:\n\n```html\n\u003cscript src=\"https://unpkg.com/analytics/dist/analytics.min.js\"\u003e\u003c/script\u003e\n```\n\n## Usage\n\n```js\nimport Analytics from 'analytics'\nimport googleAnalytics from '@analytics/google-analytics'\nimport customerIo from '@analytics/customerio'\n\n/* Initialize analytics */\nconst analytics = Analytics({\n  app: 'my-app-name',\n  version: 100,\n  plugins: [\n    googleAnalytics({\n      measurementIds: ['G-XXXXXXXX'],\n    }),\n    customerIo({\n      siteId: '123-xyz'\n    })\n  ]\n})\n\n/* Track a page view */\nanalytics.page()\n\n/* Track a custom event */\nanalytics.track('userPurchase', {\n  price: 20,\n  item: 'pink socks'\n})\n\n/* Identify a visitor */\nanalytics.identify('user-id-xyz', {\n  firstName: 'bill',\n  lastName: 'murray',\n  email: 'da-coolest@aol.com'\n})\n```\n\n\u003cdetails\u003e\n  \u003csummary\u003eNode.js usage\u003c/summary\u003e\n\n  For ES6/7 javascript you can `import Analytics from 'analytics'` for normal node.js usage you can import like so:\n\n  ```js\n  const { Analytics } = require('analytics')\n  // or const Analytics = require('analytics').default\n  const googleAnalytics = require('@analytics/google-analytics')\n  const customerIo = require('@analytics/customerio')\n\n  const analytics = Analytics({\n    app: 'my-app-name',\n    version: 100,\n    plugins: [\n      googleAnalytics({\n        measurementIds: ['G-XXXXXXXX'],\n      }),\n      customerIo({\n        siteId: '123-xyz'\n      })\n    ]\n  })\n\n  /* Track a page view */\n  analytics.page()\n\n  /* Track a custom event */\n  analytics.track('userPurchase', {\n    price: 20,\n    item: 'pink socks'\n  })\n\n  /* Identify a visitor */\n  analytics.identify('user-id-xyz', {\n    firstName: 'bill',\n    lastName: 'murray',\n    email: 'da-coolest@aol.com'\n  })\n  ```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003eBrowser usage\u003c/summary\u003e\n\n  When importing global `analytics` into your project from a CDN, the library exposes via a global `_analytics` variable.\n\n  Call `_analytics.init` to create an analytics instance.\n\n  ```html\n  \u003cscript src=\"https://unpkg.com/analytics/dist/analytics.min.js\"\u003e\u003c/script\u003e\n  \u003cscript\u003e\n    const Analytics = _analytics.init({\n      app: 'my-app-name',\n      version: 100,\n      plugins: []\n    })\n\n    /* Track a page view */\n    Analytics.page()\n\n    /* Track a custom event */\n    Analytics.track('userPurchase', {\n      price: 20,\n      item: 'pink socks'\n    })\n\n    /* Identify a visitor */\n    Analytics.identify('user-id-xyz', {\n      firstName: 'bill',\n      lastName: 'murray',\n      email: 'da-coolest@aol.com'\n    })\n  \u003c/script\u003e\n  ```\n\n\u003c/details\u003e\n\n## Demo\n\nSee [Analytics Demo](https://analytics-demo.netlify.app/) for a site example.\n\n## API\n\nThe core `analytics` API is exposed once the library is initialized with [configuration](#configuration).\n\nTypical usage:\n\n1. Initialize with [configuration](#configuration)\n2. Export the analytics instance with third-party providers (Google Analytics, HubSpot, etc)\n3. Use [`page`](#analyticspage), [`identify`](#analyticsidentify), [`track`](#analyticstrack) in your app\n4. [Plugin custom business logic](#creating-analytics-plugins)\n\n\u003c!-- AUTO-GENERATED-CONTENT:START (API_DOCS) --\u003e\n### Configuration\n\nAnalytics library configuration\n\nAfter the library is initialized with config, the core API is exposed \u0026 ready for use in the application.\n\n**Arguments**\n\n- **config** \u003ccode\u003eobject\u003c/code\u003e - analytics core config\n- **[config.app]** (optional) \u003ccode\u003estring\u003c/code\u003e - Name of site / app\n- **[config.version]** (optional) \u003ccode\u003estring\u003c/code\u003e|\u003ccode\u003enumber\u003c/code\u003e - Version of your app\n- **[config.debug]** (optional) \u003ccode\u003eboolean\u003c/code\u003e - Should analytics run in debug mode\n- **[config.plugins]** (optional) \u003ccode\u003eArray\u003c/code\u003e.\u0026lt;\u003ca href=\"https://getanalytics.io/plugins\"\u003eAnalyticsPlugin\u003c/a\u003e\u0026gt; - Array of analytics plugins\n\n**Example**\n\n```js\nimport Analytics from 'analytics'\nimport pluginABC from 'analytics-plugin-abc'\nimport pluginXYZ from 'analytics-plugin-xyz'\n\n// initialize analytics\nconst analytics = Analytics({\n  app: 'my-awesome-app',\n  plugins: [\n    pluginABC,\n    pluginXYZ\n  ]\n})\n```\n\n### analytics.identify\n\nIdentify a user. This will trigger `identify` calls in any installed plugins and will set user data in localStorage\n\n**Arguments**\n\n- **userId** \u003ccode\u003eString\u003c/code\u003e - Unique ID of user\n- **[traits]** (optional) \u003ccode\u003eObject\u003c/code\u003e - Object of user traits\n- **[options]** (optional) \u003ccode\u003eObject\u003c/code\u003e - Options to pass to identify call\n- **[callback]** (optional) \u003ccode\u003eFunction\u003c/code\u003e - Callback function after identify completes\n\n**Example**\n\n```js\n// Basic user id identify\nanalytics.identify('xyz-123')\n\n// Identify with additional traits\nanalytics.identify('xyz-123', {\n  name: 'steve',\n  company: 'hello-clicky'\n})\n\n// Fire callback with 2nd or 3rd argument\nanalytics.identify('xyz-123', () =\u003e {\n  console.log('do this after identify')\n})\n\n// Disable sending user data to specific analytic tools\nanalytics.identify('xyz-123', {}, {\n  plugins: {\n    // disable sending this identify call to segment\n    segment: false\n  }\n})\n\n// Send user data to only to specific analytic tools\nanalytics.identify('xyz-123', {}, {\n  plugins: {\n    // disable this specific identify in all plugins except customerio\n    all: false,\n    customerio: true\n  }\n})\n```\n\n### analytics.track\n\nTrack an analytics event. This will trigger `track` calls in any installed plugins\n\n**Arguments**\n\n- **eventName** \u003ccode\u003eString\u003c/code\u003e - Event name\n- **[payload]** (optional) \u003ccode\u003eObject\u003c/code\u003e - Event payload\n- **[options]** (optional) \u003ccode\u003eObject\u003c/code\u003e - Event options\n- **[callback]** (optional) \u003ccode\u003eFunction\u003c/code\u003e - Callback to fire after tracking completes\n\n**Example**\n\n```js\n// Basic event tracking\nanalytics.track('buttonClicked')\n\n// Event tracking with payload\nanalytics.track('itemPurchased', {\n  price: 11,\n  sku: '1234'\n})\n\n// Fire callback with 2nd or 3rd argument\nanalytics.track('newsletterSubscribed', () =\u003e {\n  console.log('do this after track')\n})\n\n// Disable sending this event to specific analytic tools\nanalytics.track('cartAbandoned', {\n  items: ['xyz', 'abc']\n}, {\n  plugins: {\n    // disable track event for segment\n    segment: false\n  }\n})\n\n// Send event to only to specific analytic tools\nanalytics.track('customerIoOnlyEventExample', {\n  price: 11,\n  sku: '1234'\n}, {\n  plugins: {\n    // disable this specific track call all plugins except customerio\n    all: false,\n    customerio: true\n  }\n})\n```\n\n### analytics.page\n\nTrigger page view. This will trigger `page` calls in any installed plugins\n\n**Arguments**\n\n- **[data]** (optional) \u003ca href=\"https://github.com/DavidWells/analytics/blob/master/packages/analytics-core/src/modules/page.js#L33\"\u003ePageData\u003c/a\u003e - Page data overrides.\n- **[options]** (optional) \u003ccode\u003eObject\u003c/code\u003e - Page tracking options\n- **[callback]** (optional) \u003ccode\u003eFunction\u003c/code\u003e - Callback to fire after page view call completes\n\n**Example**\n\n```js\n// Basic page tracking\nanalytics.page()\n\n// Page tracking with page data overrides\nanalytics.page({\n  url: 'https://google.com'\n})\n\n// Fire callback with 1st, 2nd or 3rd argument\nanalytics.page(() =\u003e {\n  console.log('do this after page')\n})\n\n// Disable sending this pageview to specific analytic tools\nanalytics.page({}, {\n  plugins: {\n    // disable page tracking event for segment\n    segment: false\n  }\n})\n\n// Send pageview to only to specific analytic tools\nanalytics.page({}, {\n  plugins: {\n    // disable this specific page in all plugins except customerio\n    all: false,\n    customerio: true\n  }\n})\n```\n\n### analytics.user\n\nGet user data\n\n**Arguments**\n\n- **[key]** (optional) \u003ccode\u003estring\u003c/code\u003e - dot.prop.path of user data. Example: 'traits.company.name'\n\n**Example**\n\n```js\n// Get all user data\nconst userData = analytics.user()\n\n// Get user id\nconst userId = analytics.user('userId')\n\n// Get user company name\nconst companyName = analytics.user('traits.company.name')\n```\n\n### analytics.reset\n\nClear all information about the visitor \u0026 reset analytic state.\n\n**Arguments**\n\n- **[callback]** (optional) \u003ccode\u003eFunction\u003c/code\u003e - Handler to run after reset\n\n**Example**\n\n```js\n// Reset current visitor\nanalytics.reset()\n```\n\n### analytics.ready\n\nFire callback on analytics ready event\n\n**Arguments**\n\n- **callback** \u003ccode\u003eFunction\u003c/code\u003e - function to trigger when all providers have loaded\n\n**Example**\n\n```js\nanalytics.ready((payload) =\u003e {\n  console.log('all plugins have loaded or were skipped', payload);\n})\n```\n\n### analytics.on\n\nAttach an event handler function for analytics lifecycle events.\n\n**Arguments**\n\n- **name** \u003ccode\u003eString\u003c/code\u003e - Name of event to listen to\n- **callback** \u003ccode\u003eFunction\u003c/code\u003e - function to fire on event\n\n**Example**\n\n```js\n// Fire function when 'track' calls happen\nanalytics.on('track', ({ payload }) =\u003e {\n  console.log('track call just happened. Do stuff')\n})\n\n// Remove listener before it is called\nconst removeListener = analytics.on('track', ({ payload }) =\u003e {\n  console.log('This will never get called')\n})\n\n// cleanup .on listener\nremoveListener()\n```\n\n### analytics.once\n\nAttach a handler function to an event and only trigger it once.\n\n**Arguments**\n\n- **name** \u003ccode\u003eString\u003c/code\u003e - Name of event to listen to\n- **callback** \u003ccode\u003eFunction\u003c/code\u003e - function to fire on event\n\n**Example**\n\n```js\n// Fire function only once per 'track'\nanalytics.once('track', ({ payload }) =\u003e {\n  console.log('This is only triggered once when analytics.track() fires')\n})\n\n// Remove listener before it is called\nconst listener = analytics.once('track', ({ payload }) =\u003e {\n  console.log('This will never get called b/c listener() is called')\n})\n\n// cleanup .once listener before it fires\nlistener()\n```\n\n### analytics.getState\n\nGet data about user, activity, or context. Access sub-keys of state with `dot.prop` syntax.\n\n**Arguments**\n\n- **[key]** (optional) \u003ccode\u003estring\u003c/code\u003e - dot.prop.path value of state\n\n**Example**\n\n```js\n// Get the current state of analytics\nanalytics.getState()\n\n// Get a subpath of state\nanalytics.getState('context.offline')\n```\n\n### analytics.storage\n\nStorage utilities for persisting data.\nThese methods will allow you to save data in localStorage, cookies, or to the window.\n\n**Example**\n\n```js\n// Pull storage off analytics instance\nconst { storage } = analytics\n\n// Get value\nstorage.getItem('storage_key')\n\n// Set value\nstorage.setItem('storage_key', 'value')\n\n// Remove value\nstorage.removeItem('storage_key')\n```\n\n### analytics.storage.getItem\n\nGet value from storage\n\n**Arguments**\n\n- **key** \u003ccode\u003eString\u003c/code\u003e - storage key\n- **[options]** (optional) \u003ccode\u003eObject\u003c/code\u003e - storage options\n\n**Example**\n\n```js\nanalytics.storage.getItem('storage_key')\n```\n\n### analytics.storage.setItem\n\nSet storage value\n\n**Arguments**\n\n- **key** \u003ccode\u003eString\u003c/code\u003e - storage key\n- **value** \u003ca href=\"any.html\"\u003eany\u003c/a\u003e - storage value\n- **[options]** (optional) \u003ccode\u003eObject\u003c/code\u003e - storage options\n\n**Example**\n\n```js\nanalytics.storage.setItem('storage_key', 'value')\n```\n\n### analytics.storage.removeItem\n\nRemove storage value\n\n**Arguments**\n\n- **key** \u003ccode\u003eString\u003c/code\u003e - storage key\n- **[options]** (optional) \u003ccode\u003eObject\u003c/code\u003e - storage options\n\n**Example**\n\n```js\nanalytics.storage.removeItem('storage_key')\n```\n\n### analytics.plugins\n\nAsync Management methods for plugins. \n\nThis is also where [custom methods](https://bit.ly/329vFXy) are loaded into the instance.\n\n**Example**\n\n```js\n// Enable a plugin by namespace\nanalytics.plugins.enable('keenio')\n\n// Disable a plugin by namespace\nanalytics.plugins.disable('google-analytics')\n```\n\n### analytics.plugins.enable\n\nEnable analytics plugin\n\n**Arguments**\n\n- **plugins** \u003ccode\u003estring\u003c/code\u003e|\u003ccode\u003eArray\u003c/code\u003e.\u0026lt;\u003ccode\u003estring\u003c/code\u003e\u0026gt; - name of plugins(s) to disable\n- **[callback]** (optional) \u003ccode\u003eFunction\u003c/code\u003e - callback after enable runs\n\n**Example**\n\n```js\nanalytics.plugins.enable('google-analytics').then(() =\u003e {\n  console.log('do stuff')\n})\n\n// Enable multiple plugins at once\nanalytics.plugins.enable(['google-analytics', 'segment']).then(() =\u003e {\n  console.log('do stuff')\n})\n```\n\n### analytics.plugins.disable\n\nDisable analytics plugin\n\n**Arguments**\n\n- **plugins** \u003ccode\u003estring\u003c/code\u003e|\u003ccode\u003eArray\u003c/code\u003e.\u0026lt;\u003ccode\u003estring\u003c/code\u003e\u0026gt; - name of integration(s) to disable\n- **callback** \u003ccode\u003eFunction\u003c/code\u003e - callback after disable runs\n\n**Example**\n\n```js\nanalytics.plugins.disable('google').then(() =\u003e {\n  console.log('do stuff')\n})\n\nanalytics.plugins.disable(['google', 'segment']).then(() =\u003e {\n  console.log('do stuff')\n})\n```\n\u003c!-- AUTO-GENERATED-CONTENT:END --\u003e\n\n## Events\n\nThe `analytics` library comes with a large variety of event listeners that can be used to fire custom functionality when a specific lifecycle event occurs.\n\nThese listeners can be fired using `analytics.on` \u0026 `analytics.once`\n\n```js\nconst eventName = 'pageEnd'\nanalytics.on(eventName, ({ payload }) =\u003e {\n  console.log('payload', payload)\n})\n```\n\nBelow is a list of the current available events\n\n\u003c!-- AUTO-GENERATED-CONTENT:START (EVENT_DOCS) --\u003e\n| Event | Description |\n|:------|:-------|\n| **`bootstrap`** | Fires when analytics library starts up.\u003cbr/\u003eThis is the first event fired. '.on/once' listeners are not allowed on bootstrap\u003cbr/\u003ePlugins can attach logic to this event |\n| **`params`** | Fires when analytics parses URL parameters |\n| **`campaign`** | Fires if params contain \"utm\" parameters |\n| **`initializeStart`** | Fires before 'initialize', allows for plugins to cancel loading of other plugins |\n| **`initialize`** | Fires when analytics loads plugins |\n| **`initializeEnd`** | Fires after initialize, allows for plugins to run logic after initialization methods run |\n| **`ready`** | Fires when all analytic providers are fully loaded. This waits for 'initialize' and 'loaded' to return true |\n| **`resetStart`** | Fires if analytic.reset() is called.\u003cbr/\u003eUse this event to cancel reset based on a specific condition |\n| **`reset`** | Fires if analytic.reset() is called.\u003cbr/\u003eUse this event to run custom cleanup logic (if needed) |\n| **`resetEnd`** | Fires after analytic.reset() is called.\u003cbr/\u003eUse this event to run a callback after user data is reset |\n| **`pageStart`** | Fires before 'page' events fire.\u003cbr/\u003e This allows for dynamic page view cancellation based on current state of user or options passed in. |\n| **`page`** | Core analytics hook for page views.\u003cbr/\u003e If your plugin or integration tracks page views, this is the event to fire on. |\n| **`pageEnd`** | Fires after all registered 'page' methods fire. |\n| **`pageAborted`** | Fires if 'page' call is cancelled by a plugin |\n| **`trackStart`** | Called before the 'track' events fires.\u003cbr/\u003e This allows for dynamic page view cancellation based on current state of user or options passed in. |\n| **`track`** | Core analytics hook for event tracking.\u003cbr/\u003e If your plugin or integration tracks custom events, this is the event to fire on. |\n| **`trackEnd`** | Fires after all registered 'track' events fire from plugins. |\n| **`trackAborted`** | Fires if 'track' call is cancelled by a plugin |\n| **`identifyStart`** | Called before the 'identify' events fires.\u003cbr/\u003eThis allows for dynamic page view cancellation based on current state of user or options passed in. |\n| **`identify`** | Core analytics hook for user identification.\u003cbr/\u003e If your plugin or integration identifies users or user traits, this is the event to fire on. |\n| **`identifyEnd`** | Fires after all registered 'identify' events fire from plugins. |\n| **`identifyAborted`** | Fires if 'track' call is cancelled by a plugin |\n| **`userIdChanged`** | Fires when a user id is updated |\n| **`registerPlugins`** | Fires when analytics is registering plugins |\n| **`enablePlugin`** | Fires when 'analytics.plugins.enable()' is called |\n| **`disablePlugin`** | Fires when 'analytics.plugins.disable()' is called |\n| **`online`** | Fires when browser network goes online.\u003cbr/\u003eThis fires only when coming back online from an offline state. |\n| **`offline`** | Fires when browser network goes offline. |\n| **`setItemStart`** | Fires when analytics.storage.setItem is initialized.\u003cbr/\u003eThis event gives plugins the ability to intercept keys \u0026 values and alter them before they are persisted. |\n| **`setItem`** | Fires when analytics.storage.setItem is called.\u003cbr/\u003eThis event gives plugins the ability to intercept keys \u0026 values and alter them before they are persisted. |\n| **`setItemEnd`** | Fires when setItem storage is complete. |\n| **`setItemAborted`** | Fires when setItem storage is cancelled by a plugin. |\n| **`removeItemStart`** | Fires when analytics.storage.removeItem is initialized.\u003cbr/\u003eThis event gives plugins the ability to intercept removeItem calls and abort / alter them. |\n| **`removeItem`** | Fires when analytics.storage.removeItem is called.\u003cbr/\u003eThis event gives plugins the ability to intercept removeItem calls and abort / alter them. |\n| **`removeItemEnd`** | Fires when removeItem storage is complete. |\n| **`removeItemAborted`** | Fires when removeItem storage is cancelled by a plugin. |\n\u003c!-- AUTO-GENERATED-CONTENT:END (EVENT_DOCS) --\u003e\n\n## Analytic plugins\n\nThe `analytics` has a robust plugin system. Here is a list of currently available plugins:\n\n\u003c!-- AUTO-GENERATED-CONTENT:START (PLUGINS) --\u003e\n| Plugin | Stats | Version |\n|:---------------------------|:---------------:|:-----------:|\n| **[@analytics/activity-utils](https://github.com/DavidWells/analytics/tree/master/packages/analytics-util-activity)** \u003cbr/\u003e User activity listener utilities | \u003ca href=\"https://www.npmjs.com/package/@analytics/activity-utils\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/activity-utils.svg\"\u003e\u003c/a\u003e |  **0.1.16** |\n| **[@analytics/amplitude](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-amplitude)** \u003cbr/\u003e Amplitude integration for 'analytics' module | \u003ca href=\"https://www.npmjs.com/package/@analytics/amplitude\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/amplitude.svg\"\u003e\u003c/a\u003e |  **0.1.3** |\n| **[@analytics/aws-pinpoint](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-aws-pinpoint)** \u003cbr/\u003e AWS Pinpoint integration for 'analytics' module | \u003ca href=\"https://www.npmjs.com/package/@analytics/aws-pinpoint\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/aws-pinpoint.svg\"\u003e\u003c/a\u003e |  **0.7.12** |\n| **[@analytics/cookie-utils](https://github.com/DavidWells/analytics/tree/master/packages/analytics-util-storage-cookie)** \u003cbr/\u003e Tiny cookie utility library | \u003ca href=\"https://www.npmjs.com/package/@analytics/cookie-utils\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/cookie-utils.svg\"\u003e\u003c/a\u003e |  **0.2.12** |\n| **[@analytics/core](https://github.com/DavidWells/analytics/tree/master/packages/analytics-core)** \u003cbr/\u003e Lightweight analytics library for tracking events, page views, \u0026 identifying users. Works with any third party analytics provider via an extendable plugin system. | \u003ca href=\"https://www.npmjs.com/package/@analytics/core\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/core.svg\"\u003e\u003c/a\u003e |  **0.12.9** |\n| **[@analytics/countly](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-countly)** \u003cbr/\u003e Countly plugin for 'analytics' module | \u003ca href=\"https://www.npmjs.com/package/@analytics/countly\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/countly.svg\"\u003e\u003c/a\u003e |  **0.21.12** |\n| **[@analytics/crazy-egg](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-crazy-egg)** \u003cbr/\u003e Crazy Egg integration for 'analytics' module | \u003ca href=\"https://www.npmjs.com/package/@analytics/crazy-egg\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/crazy-egg.svg\"\u003e\u003c/a\u003e |  **0.1.2** |\n| **[@analytics/custify](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-custify)** \u003cbr/\u003e Custify integration for 'analytics' module for browser \u0026 node | \u003ca href=\"https://www.npmjs.com/package/@analytics/custify\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/custify.svg\"\u003e\u003c/a\u003e |  **0.0.2** |\n| **[@analytics/customerio](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-customerio)** \u003cbr/\u003e Customer.io integration for 'analytics' module | \u003ca href=\"https://www.npmjs.com/package/@analytics/customerio\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/customerio.svg\"\u003e\u003c/a\u003e |  **0.2.2** |\n| **[@analytics/form-utils](https://github.com/DavidWells/analytics/tree/master/packages/analytics-util-forms)** \u003cbr/\u003e Form utility library for managing HTML form submissions \u0026 values | \u003ca href=\"https://www.npmjs.com/package/@analytics/form-utils\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/form-utils.svg\"\u003e\u003c/a\u003e |  **0.3.13** |\n| **[@analytics/fullstory](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-fullstory)** \u003cbr/\u003e Unofficial FullStory plugin for 'analytics' module | \u003ca href=\"https://www.npmjs.com/package/@analytics/fullstory\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/fullstory.svg\"\u003e\u003c/a\u003e |  **0.2.6** |\n| **[@analytics/global-storage-utils](https://github.com/DavidWells/analytics/tree/master/packages/analytics-util-storage-global)** \u003cbr/\u003e Tiny global storage utility library | \u003ca href=\"https://www.npmjs.com/package/@analytics/global-storage-utils\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/global-storage-utils.svg\"\u003e\u003c/a\u003e |  **0.1.7** |\n| **[@analytics/google-analytics](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-google-analytics)** \u003cbr/\u003e Google analytics v4 plugin for 'analytics' module | \u003ca href=\"https://www.npmjs.com/package/@analytics/google-analytics\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/google-analytics.svg\"\u003e\u003c/a\u003e |  **1.0.7** |\n| **[@analytics/google-tag-manager](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-google-tag-manager)** \u003cbr/\u003e Google tag manager plugin for 'analytics' module | \u003ca href=\"https://www.npmjs.com/package/@analytics/google-tag-manager\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/google-tag-manager.svg\"\u003e\u003c/a\u003e |  **0.5.5** |\n| **[@analytics/google-analytics-v3](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-google-analytics-v3)** \u003cbr/\u003e Google analytics v3 plugin for 'analytics' module | \u003ca href=\"https://www.npmjs.com/package/@analytics/google-analytics-v3\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/google-analytics-v3.svg\"\u003e\u003c/a\u003e |  **0.6.1** |\n| **[@analytics/gosquared](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-gosquared)** \u003cbr/\u003e GoSquared integration for 'analytics' module | \u003ca href=\"https://www.npmjs.com/package/@analytics/gosquared\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/gosquared.svg\"\u003e\u003c/a\u003e |  **0.1.3** |\n| **[@analytics/hubspot](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-hubspot)** \u003cbr/\u003e HubSpot plugin for 'analytics' module | \u003ca href=\"https://www.npmjs.com/package/@analytics/hubspot\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/hubspot.svg\"\u003e\u003c/a\u003e |  **0.5.1** |\n| **[@analytics/intercom](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-intercom)** \u003cbr/\u003e Intercom integration for 'analytics' module for browser \u0026 node | \u003ca href=\"https://www.npmjs.com/package/@analytics/intercom\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/intercom.svg\"\u003e\u003c/a\u003e |  **1.0.2** |\n| **[@analytics/listener-utils](https://github.com/DavidWells/analytics/tree/master/packages/analytics-util-listener)** \u003cbr/\u003e Backward compatible event listener library for attaching \u0026 detaching event handlers | \u003ca href=\"https://www.npmjs.com/package/@analytics/listener-utils\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/listener-utils.svg\"\u003e\u003c/a\u003e |  **0.4.0** |\n| **[@analytics/localstorage-utils](https://github.com/DavidWells/analytics/tree/master/packages/analytics-util-storage-local)** \u003cbr/\u003e Tiny LocalStorage utility library | \u003ca href=\"https://www.npmjs.com/package/@analytics/localstorage-utils\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/localstorage-utils.svg\"\u003e\u003c/a\u003e |  **0.1.10** |\n| **[@analytics/mixpanel](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-mixpanel)** \u003cbr/\u003e Mixpanel plugin for 'analytics' module | \u003ca href=\"https://www.npmjs.com/package/@analytics/mixpanel\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/mixpanel.svg\"\u003e\u003c/a\u003e |  **0.4.0** |\n| **[@analytics/original-source-plugin](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-original-source)** \u003cbr/\u003e Save original referral source of visitor plugin for 'analytics' pkg | \u003ca href=\"https://www.npmjs.com/package/@analytics/original-source-plugin\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/original-source-plugin.svg\"\u003e\u003c/a\u003e |  **1.0.11** |\n| **[@analytics/ownstats](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-ownstats)** \u003cbr/\u003e Ownstats integration for 'analytics' module for browser \u0026 node | \u003ca href=\"https://www.npmjs.com/package/@analytics/ownstats\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/ownstats.svg\"\u003e\u003c/a\u003e |  **0.1.2** |\n| **[@analytics/perfumejs](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-perfumejs)** \u003cbr/\u003e Send browser performance metrics to third-party analytics providers | \u003ca href=\"https://www.npmjs.com/package/@analytics/perfumejs\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/perfumejs.svg\"\u003e\u003c/a\u003e |  **0.2.1** |\n| **[@analytics/queue-utils](https://github.com/DavidWells/analytics/tree/master/packages/analytics-util-queue)** \u003cbr/\u003e Dependency free queue processor | \u003ca href=\"https://www.npmjs.com/package/@analytics/queue-utils\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/queue-utils.svg\"\u003e\u003c/a\u003e |  **0.1.2** |\n| **[@analytics/redact-utils](https://github.com/DavidWells/analytics/tree/master/packages/analytics-util-redact)** \u003cbr/\u003e Utility library for redacting event data | \u003ca href=\"https://www.npmjs.com/package/@analytics/redact-utils\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/redact-utils.svg\"\u003e\u003c/a\u003e |  **0.1.3** |\n| **[@analytics/remote-storage-utils](https://github.com/DavidWells/analytics/tree/master/packages/analytics-util-storage-remote)** \u003cbr/\u003e Storage utilities for cross domain localStorage access, with permissions | \u003ca href=\"https://www.npmjs.com/package/@analytics/remote-storage-utils\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/remote-storage-utils.svg\"\u003e\u003c/a\u003e |  **0.4.20** |\n| **[@analytics/router-utils](https://github.com/DavidWells/analytics/tree/master/packages/analytics-util-router)** \u003cbr/\u003e Route change utilities for single page apps | \u003ca href=\"https://www.npmjs.com/package/@analytics/router-utils\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/router-utils.svg\"\u003e\u003c/a\u003e |  **0.1.1** |\n| **[@analytics/scroll-utils](https://github.com/DavidWells/analytics/tree/master/packages/analytics-util-scroll)** \u003cbr/\u003e Scroll utility library to fire events on scroll | \u003ca href=\"https://www.npmjs.com/package/@analytics/scroll-utils\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/scroll-utils.svg\"\u003e\u003c/a\u003e |  **0.1.22** |\n| **[@analytics/segment](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-segment)** \u003cbr/\u003e Segment integration for 'analytics' module for browser \u0026 node | \u003ca href=\"https://www.npmjs.com/package/@analytics/segment\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/segment.svg\"\u003e\u003c/a\u003e |  **2.1.0** |\n| **[@analytics/session-storage-utils](https://github.com/DavidWells/analytics/tree/master/packages/analytics-util-storage-session)** \u003cbr/\u003e Tiny SessionStorage utility library | \u003ca href=\"https://www.npmjs.com/package/@analytics/session-storage-utils\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/session-storage-utils.svg\"\u003e\u003c/a\u003e |  **0.0.7** |\n| **[@analytics/session-utils](https://github.com/DavidWells/analytics/tree/master/packages/analytics-util-session)** \u003cbr/\u003e Tiny session utility library | \u003ca href=\"https://www.npmjs.com/package/@analytics/session-utils\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/session-utils.svg\"\u003e\u003c/a\u003e |  **0.2.0** |\n| **[@analytics/simple-analytics](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-simple-analytics)** \u003cbr/\u003e Simple analytics plugin for 'analytics' module for browser | \u003ca href=\"https://www.npmjs.com/package/@analytics/simple-analytics\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/simple-analytics.svg\"\u003e\u003c/a\u003e |  **0.4.0** |\n| **[@analytics/snowplow](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-snowplow)** \u003cbr/\u003e Snowplow integration for 'analytics' module for browser \u0026 node | \u003ca href=\"https://www.npmjs.com/package/@analytics/snowplow\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/snowplow.svg\"\u003e\u003c/a\u003e |  **0.3.3** |\n| **[@analytics/storage-utils](https://github.com/DavidWells/analytics/tree/master/packages/analytics-util-storage)** \u003cbr/\u003e Storage utility with fallbacks | \u003ca href=\"https://www.npmjs.com/package/@analytics/storage-utils\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/storage-utils.svg\"\u003e\u003c/a\u003e |  **0.4.2** |\n| **[@analytics/type-utils](https://github.com/DavidWells/analytics/tree/master/packages/analytics-util-types)** \u003cbr/\u003e Tiny runtime type checking utils | \u003ca href=\"https://www.npmjs.com/package/@analytics/type-utils\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/type-utils.svg\"\u003e\u003c/a\u003e |  **0.6.2** |\n| **[@analytics/url-utils](https://github.com/DavidWells/analytics/tree/master/packages/analytics-util-url)** \u003cbr/\u003e Url utils | \u003ca href=\"https://www.npmjs.com/package/@analytics/url-utils\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/url-utils.svg\"\u003e\u003c/a\u003e |  **0.2.3** |\n| **[@analytics/visitor-source](https://github.com/DavidWells/analytics/tree/master/packages/analytics-util-visitor-source)** \u003cbr/\u003e Get visitor source | \u003ca href=\"https://www.npmjs.com/package/@analytics/visitor-source\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/@analytics/visitor-source.svg\"\u003e\u003c/a\u003e |  **0.0.7** |\n| **[analytics-cli](https://github.com/DavidWells/analytics/tree/master/packages/analytics-cli)** \u003cbr/\u003e CLI for `analytics` pkg | \u003ca href=\"https://www.npmjs.com/package/analytics-cli\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/analytics-cli.svg\"\u003e\u003c/a\u003e |  **0.0.5** |\n| **[analytics-plugin-do-not-track](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-do-not-track)** \u003cbr/\u003e Disable tracking for opted out visitors plugin for 'analytics' module | \u003ca href=\"https://www.npmjs.com/package/analytics-plugin-do-not-track\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/analytics-plugin-do-not-track.svg\"\u003e\u003c/a\u003e |  **0.1.5** |\n| **[analytics-plugin-event-validation](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-event-validation)** \u003cbr/\u003e Event validation plugin for analytics | \u003ca href=\"https://www.npmjs.com/package/analytics-plugin-event-validation\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/analytics-plugin-event-validation.svg\"\u003e\u003c/a\u003e |  **0.1.2** |\n| **[gatsby-plugin-analytics](https://github.com/DavidWells/analytics/tree/master/packages/gatsby-plugin-analytics)** \u003cbr/\u003e Easily add analytics to your Gatsby site | \u003ca href=\"https://www.npmjs.com/package/gatsby-plugin-analytics\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/gatsby-plugin-analytics.svg\"\u003e\u003c/a\u003e |  **0.2.0** |\n| **[analytics-plugin-lifecycle-example](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-lifecycle-example)** \u003cbr/\u003e Example plugin with lifecycle methods for 'analytics' module | \u003ca href=\"https://www.npmjs.com/package/analytics-plugin-lifecycle-example\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/analytics-plugin-lifecycle-example.svg\"\u003e\u003c/a\u003e |  **0.1.2** |\n| **[analytics-plugin-tab-events](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-tab-events)** \u003cbr/\u003e Expose tab visibility events plugin for 'analytics' module | \u003ca href=\"https://www.npmjs.com/package/analytics-plugin-tab-events\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/analytics-plugin-tab-events.svg\"\u003e\u003c/a\u003e |  **0.2.1** |\n| **[use-analytics](https://github.com/DavidWells/analytics/tree/master/packages/use-analytics)** \u003cbr/\u003e Analytics hooks for React | \u003ca href=\"https://www.npmjs.com/package/use-analytics\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/use-analytics.svg\"\u003e\u003c/a\u003e |  **1.1.0** |\n| **[analytics-util-params](https://github.com/DavidWells/analytics/tree/master/packages/analytics-util-params)** \u003cbr/\u003e Url Parameter helper functions | \u003ca href=\"https://www.npmjs.com/package/analytics-util-params\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/analytics-util-params.svg\"\u003e\u003c/a\u003e |  **0.1.2** |\n| **[analytics-utils](https://github.com/DavidWells/analytics/tree/master/packages/analytics-utils)** \u003cbr/\u003e Analytics utility functions used by 'analytics' module | \u003ca href=\"https://www.npmjs.com/package/analytics-utils\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/analytics-utils.svg\"\u003e\u003c/a\u003e |  **1.0.12** |\n| **[analytics-plugin-window-events](https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-window-events)** \u003cbr/\u003e Expose window events plugin for 'analytics' module | \u003ca href=\"https://www.npmjs.com/package/analytics-plugin-window-events\"\u003e\u003cimg width=\"360\" height=\"22\" src=\"https://img.shields.io/npm/dm/analytics-plugin-window-events.svg\"\u003e\u003c/a\u003e |  **0.0.7** |\n\u003c!-- AUTO-GENERATED-CONTENT:END --\u003e\n\n## Community Plugins\n\nBelow are plugins created outside of this repo:\n\n\u003c!-- AUTO-GENERATED-CONTENT:START (EXTERNAL_PLUGINS) --\u003e\n- [ActiveCampaign](https://github.com/deevus/analytics-plugin-activecampaign) Adds Analytics support for ActiveCampaign\n- [analytics-fetch](https://www.npmjs.com/package/@standardorg/analytics-fetch) Integration with the browser's fetch API for analytics\n- [Conscia](https://www.npmjs.com/package/analytics-plugin-conscia) Adds Analytics support for conscia.ai\n- [Facebook tracking pixel](https://github.com/DavidWells/analytics/issues/54#issuecomment-735413632) Send data to Facebook Tracking pixel\n- [Indicative](https://www.npmjs.com/package/analytics-plugin-indicative) Adds Analytics support for Indicative\n- [LinkedIn Pixel](https://www.npmjs.com/package/analytics-plugin-linkedin) Adds Analytics support for Linkedin tracking pixel\n- [Logrocket](https://www.npmjs.com/package/analytics-plugin-logrocket) Adds Analytics support for LogRocket\n- [mailmodo](https://www.npmjs.com/package/analytics-plugin-mailmodo) Adds Analytics support for mailmodo\n- [Planhat](https://www.npmjs.com/package/analytics-plugin-planhat) Adds Analytics support for Planhat\n- [Plausible](https://www.npmjs.com/package/analytics-plugin-plausible) Adds Analytics support for Plausible\n- [PostHog](https://www.npmjs.com/package/@metro-fs/analytics-plugin-posthog) Adds Analytics support for PostHog by @metro-fs\n- [PostHog](https://www.npmjs.com/package/analytics-plugin-posthog) Adds Analytics support for PostHog by deevus\n- [ProfitWell](https://github.com/deevus/analytics-plugin-profitwell) Adds Analytics support for ProfitWell\n- [Reddit Pixel](https://www.npmjs.com/package/analytics-plugin-reddit-pixel) Adds Analytics support for Reddit Pixel\n- [RudderStack](https://www.npmjs.com/package/begrowth-analytics-rudderstack) Adds Analytics support for RudderStack\n- [Splitbee](https://www.npmjs.com/package/analytics-plugin-splitbee) Adds Analytics support for Splitbee\n- [Tapfiliate](https://github.com/deevus/analytics-plugin-tapfiliate) Adds Analytics support for Tapfiliate\n- [Yandex](https://github.com/pechischev/analytics-yandex-metric-plugin) Send data to Yandex metrica\n- [Add a plugin link](https://github.com/DavidWells/analytics/blob/master/external-plugins.json)\n\u003c!-- AUTO-GENERATED-CONTENT:END --\u003e\n\nAdditional examples\n\n- [Using AWS Lambda, API Gateway \u0026 analytics](https://blog.mikecoughlin.com/own-your-event-tracking/)\n- [Using analytics to make amundsen.io pluggable](https://github.com/amundsen-io/amundsenfrontendlibrary/blob/e91c0ab9d8a39b302a71c535145a20e24326ee21/docs/application_config.md#analytics)\n\n## Creating analytics plugins\n\nThe library is designed to work with any third-party analytics tool.\n\nPlugins are just plain javascript objects that expose methods for `analytics` to register and call.\n\nHere is a quick example of a plugin:\n\n```js\n// plugin-example.js\nexport default function pluginExample(userConfig) {\n  // return object for analytics to use\n  return {\n    /* All plugins require a name */\n    name: 'my-example-plugin',\n    /* Everything else below this is optional depending on your plugin requirements */\n    config: {\n      whatEver: userConfig.whatEver,\n      elseYouNeed: userConfig.elseYouNeed\n    },\n    initialize: ({ config }) =\u003e {\n      // load provider script to page\n    },\n    page: ({ payload }) =\u003e {\n      // call provider specific page tracking\n    },\n    track: ({ payload }) =\u003e {\n      // call provider specific event tracking\n    },\n    identify: ({ payload }) =\u003e {\n      // call provider specific user identify method\n    },\n    loaded: () =\u003e {\n      // return boolean so analytics knows when it can send data to third-party\n      return !!window.myPluginLoaded\n    }\n  }\n}\n```\n\n`name` is required for all plugins. All other methods are optional.\n\nIf you don't need to hook into `page` tracking, just omit the `page` key from your plugin object.\n\nTo use a plugin, import it and pass it into the `plugins` array when you bootstrap `analytics`.\n\n```js\nimport Analytics from 'analytics'\nimport pluginExample from './plugin-example.js'\n\nconst analytics = Analytics({\n  app: 'my-app-name',\n  plugins: [\n    pluginExample({\n      whatEver: 'hello',\n      elseYouNeed: 'there'\n    }),\n    ...otherPlugins\n  ]\n})\n```\n\n### React to any event\n\nPlugins can react to any event flowing through the `analytics` library.\n\nFor example, if you wanted to trigger custom logic when `analytics` bootstraps, you can attach a function handler to the `bootstrap` event.\n\nFor a full list of core events, checkout [`events.js`](https://github.com/DavidWells/analytics/blob/master/packages/analytics-core/src/events.js).\n\n```js\n// Example Plugin plugin.js\nexport default function myPlugin(userConfig) {\n  return {\n    /* Name is a required field for plugins */\n    name: 'my-plugin',\n    /* Bootstrap runs when analytics starts */\n    bootstrap: ({ payload, config, instance }) =\u003e {\n      // Do whatever on `bootstrap` event\n    },\n    pageStart: ({ payload, config, instance }) =\u003e {\n      // Fire custom logic before analytics.page() calls\n    },\n    pageEnd: ({ payload, config, instance }) =\u003e {\n      // Fire custom logic after analytics.page() calls\n    },\n    trackStart: ({ payload, config, instance }) =\u003e {\n      // Fire custom logic before analytics.track() calls\n    },\n    'track:customerio': ({ payload, config, instance }) =\u003e {\n      // Fire custom logic before customer.io plugin runs.\n      // Here you can customize the data sent to individual analytics providers\n    },\n    trackEnd: ({ payload, config, instance }) =\u003e {\n      // Fire custom logic after analytics.track() calls\n    },\n    // ... hook into other events\n  }\n}\n```\n\nUsing this plugin is the same as any other.\n\n```js\nimport Analytics from 'analytics'\nimport customerIoPlugin from '@analytics/customerio'\nimport myPlugin from './plugin.js'\n\nconst analytics = Analytics({\n  app: 'my-app-name',\n  plugins: [\n    // include myPlugin\n    myPlugin(),\n    customerIoPlugin({\n      trackingId: '1234'\n    })\n    ...otherPlugins\n  ]\n})\n```\n\n### Custom methods\n\nAnalytics plugins can provide their own custom functionality via the `methods` key.\n\n```js\nimport Analytics from 'analytics'\n\n// Example plugin with custom methods\nconst pluginOne = {\n  name: 'one',\n  // ... page, track, etc\n  // Custom functions to expose to analytics instance\n  methods: {\n    myCustomThing(one, two, three) {\n      const analyticsInstance = this.instance\n      console.log('Use full analytics instance', analyticsInstance)\n    },\n    otherCustomThing: (one, two, ...args) =\u003e {\n      // Arrow functions break this.instance context.\n      // The instance is instead injected as last arg\n      const analyticsInstance = args[args.length - 1]\n      console.log('Use full analytics instance', analyticsInstance)\n    },\n    // Async function examples\n    async fireCustomThing(one, two, three) {\n      const { track } = this.instance\n      track('customThing')\n      return 'data'\n    },\n    triggerSpecial: async (argOne, argTwo, ...args) =\u003e {\n      // Arrow functions break this.instance context.\n      // The instance is instead injected as last arg\n      const analyticsInstance = args[args.length - 1]\n      return argOne + argTwo\n    }\n  }\n}\n\n// Example plugin with custom methods\nconst pluginTwo = {\n  name: 'two',\n  page: () =\u003e { console.log('page view fired') }\n  // Custom functions to expose to analytics instance\n  methods: {\n    cookieBanner(one, two, three) {\n      const analyticsInstance = this.instance\n      console.log('Use full analytics instance', analyticsInstance)\n      const cookieSettings = analyticsInstance.storage.getItem('preferences-set')\n      if (!cookieSettings) {\n        // Show cookie settings\n      }\n    },\n  }\n}\n\n// Initialize analytics instance with plugins\nconst analytics = Analytics({\n  app: 'your-app-name',\n  plugins: [\n    pluginOne,\n    pluginTwo\n  ]\n})\n\n// Using custom methods in your code\nanalytics.plugins.one.myCustomThing()\nanalytics.plugins.two.cookieBanner()\n```\n\n##  Plugin Naming Conventions\n\nPlugins should follow this naming convention before being published to npm\n\n```bash\nanalytics-plugin-{your-plugin-name}\n```\n\nE.g. An analytics plugin that does `awesome-stuff` should be named\n\n```bash\nnpm install analytics-plugin-awesome-stuff\n```\n\nThen submit to the [list above](#analytic-plugins)\n\n## Debugging analytics\n\nDuring development, you can turn on `debug` mode. This will connect the dev tools for you to see the analytics events passing through your application visually.\n\n![analytics-debug-tools](https://user-images.githubusercontent.com/532272/61163639-21da2300-a4c4-11e9-8743-b45d3a570271.gif)\n\n```js\nimport Analytics from 'analytics'\n\nconst analytics = Analytics({\n  app: 'my-app',\n  debug: true\n})\n```\n\n## TypeScript support\n\nTypes for analytics and plugins are generated from [JSDoc blocks](https://jsdoc.app/) in the code base via the [tsd-jsdoc](https://www.npmjs.com/package/tsd-jsdoc) package.\n\nWe are always looking to improve type support \u0026 improve the DX of users. If you see something that can be improved let us know in an issue!\n\n## Contributing\n\nContributions are always welcome, no matter how large or small. Before contributing, please read the [code of conduct](CODE_OF_CONDUCT.md).\n\n## Setup \u0026 Install dependencies\n\nClone the repo and run\n\n```sh\n$ git clone https://github.com/davidwells/analytics\n$ cd analytics\n$ npm install \u0026\u0026 npm run setup\n```\n\nThe above command will set up all the packages and their dependencies.\n\n## Development\n\nYou can watch and rebuild packages with the `npm run watch` command.\n\n```sh\nnpm run watch\n```\n\nWhile watch mode is activated, you can work against the demo site in examples to test out your changes on a live application.\n","funding_links":["https://github.com/sponsors/davidwells"],"categories":["JavaScript","前端开发框架及项目"],"sub_categories":["多工具库支持或纯JS"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDavidWells%2Fanalytics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDavidWells%2Fanalytics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDavidWells%2Fanalytics/lists"}