{"id":23692476,"url":"https://github.com/yext/analytics","last_synced_at":"2025-09-02T20:33:08.327Z","repository":{"id":37080367,"uuid":"409760813","full_name":"yext/analytics","owner":"yext","description":"An analytics library for Yext Chat, Pages, and Search.","archived":false,"fork":false,"pushed_at":"2024-08-22T19:05:12.000Z","size":1261,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-08-22T21:18:12.742Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yext.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-23T22:29:52.000Z","updated_at":"2024-08-22T19:03:49.000Z","dependencies_parsed_at":"2023-09-27T02:52:54.066Z","dependency_job_id":"c49f5207-2fbf-41ed-ba4a-5b51c0ea9435","html_url":"https://github.com/yext/analytics","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yext%2Fanalytics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yext%2Fanalytics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yext%2Fanalytics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yext%2Fanalytics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yext","download_url":"https://codeload.github.com/yext/analytics/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231810495,"owners_count":18429999,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-30T03:28:16.299Z","updated_at":"2024-12-30T03:28:21.594Z","avatar_url":"https://github.com/yext.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Yext Analytics\n\n\u003cdiv\u003e\n  \u003ca href=\"./LICENSE\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/License-BSD%203--Clause-blue.svg\" alt=\"License\"/\u003e\n  \u003c/a\u003e\n  \u003ca href='https://coveralls.io/github/yext/analytics?branch=main'\u003e\n    \u003cimg src='https://coveralls.io/repos/github/yext/analytics/badge.svg?branch=main' alt='Coverage Status' /\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\u003cbr\u003e\n\nA Typescript library for sending Yext Analytics events.\n\n[Full Documentation](./docs/analytics.md)\n\n# Yext Analytics\n\nYext Analytics is a Typescript library for sending analytics events that occur on your digital experiences to the Yext Analytics platform. You can record user actions that we offer out-of-the-box, such as page views and clicks, or custom actions that are unique to your business! Yext uses the same analytics reporting features across Search, Pages, and Chat so these products all use one interface.\n\n- Works in the **browser** only.\n- 100% **TypeScript**, with detailed analytics event models\n- Compatible with both **CommonJS** and **ES6** imports\n\n## Getting Started\n\nFirst, install the library via [npm](https://www.npmjs.com/get-npm):\n\n```bash\nnpm install @yext/analytics\n```\n\n### Initialize Analytics Reporter\n\nNext, import and initialize the library in your application. When initializing your analytics reporter, you only need to provide an API Key that has access to the Events API. Other attributes such as your business ID will be automatically inferred. You can acquire this API key in the developer console of the Yext Platform.\n\n```ts\nimport { analytics } from '@yext/analytics';\n\n// Root analytics service with no defaults.\nconst rootAnalytics = analytics({\n  authorizationType: 'apiKey',\n  authorization: 'MY_API_KEY'\n});\n```\n\nIn many cases, you might need to repeatedly specify the same properties, such as a Pages site ID or Chat bot ID. Yext Analytics allows you to avoid having to repeatedly specify the same code by allowing you to set **default values**.\n\nYou can add a `.with()` method to the root analytics service you initialized, which returns a new analytics object with the specified JSON merged on top of the existing defaults.\n\n```ts\nimport { analytics } from '@yext/analytics';\n\n// Root analytics service with no defaults.\nconst rootAnalytics = analytics({\n  authorizationType: 'apiKey',\n  authorization: 'MY_API_KEY'\n});\n\n// Pages analytics service with Pages defaults.\nconst pageAnalytics = rootAnalytics.with({ pages: { siteId: 123 } });\n\n// Chat analytics service with both Chat **and** Pages defaults.\nconst chatAnalytics = pageAnalytics.with({ chat: { botId: 'my-bot' } });\n```\n\nCalling `pageAnalytics.report()` sends an event with the `pages` object, plus anything passed to `report`. Calling `chatAnalytics.report()` sends an event with both the `pages` and `chat` objects, plus anything passed to `report`. You can override the default values defined in the .with() method by sending them along with the event.\n\nFor other configuration features, see [AnalyticsConfig.ts](/docs/analytics.analyticsconfig.md)\n\n### Fire an Event\n\nNow that we’ve initialized our analytics reporter, we can fire an event! This sends a `CHAT_IMPRESSION` event type, along with a `sessionId`, a `pages.siteId`, and a `chat.botId`.\n\n```ts\nchatAnalytics.report({\n  action: 'CHAT_IMPRESSION'\n});\n```\n\n### Additional Configuration\n\n#### Session Tracking\n\nSession tracking is now available for Chat, Pages, and Search. Yext uses a browser-based method (sessionStorage) to track this. By default, session tracking is **enabled** in **both** the US and EU environments. This can be disabled by setting `sessionTrackingEnabled` to `false`.\n\nWhen `sessionTrackingEnabled` is set to `true`, Analytics will automatically generate a ULID for `sessionId` and bind that ULID to events from the same browser session. Users may also provide their own `sessionId`, which takes precedence over the auto-generated ID by Analytics. [To read more about how we generate ULIDs, check out ulidx.](https://github.com/perry-mitchell/ulidx)\n\n#### Custom Events\n\nYou can also send custom analytics events.\n\n```ts\npagesAnalytics.report({\n  action: 'C_MY_CUSTOM_EVENT'\n});\n```\n\nAdditionally, you can send arbitrary conversion events by specifying a `value` JSON object with a dollar `amount` and a `currency` in ISO format.\n\n```ts\nchatAnalytics.report({\n  action: 'C_CONVERSION_EVENT',\n  value: {\n    amount: 10,\n    currency: 'USD'\n  }\n});\n```\n\nTo learn more about sending conversion events, see our [API documentation](https://hitchhikers.yext.com/docs/eventsapis/events/events#operation/sendEvents).\n\n#### Custom Properties\n\nYou can attach custom properties to your analytics events by specifying either `customTags` or `customValues` with your request. `customTags` represent up to ten **string** key-value pairs and `customValues` represent up to ten **numeric** key-value pairs.\n\nFor example, if I set up an `ORDER` event for my restaurant and wanted to track whether a promotional code was used on the order, I could add an `promoCode` custom tag to the event.\n\n```ts\npagesAnalytics.report({\n  action: 'C_CONVERSION_EVENT',\n  sessionId: 'e790f75d-4f1e-4a1b-b57b-9a456019b176',\n  value: {\n    amount: 35.5,\n    currency: 'USD'\n  },\n  customTags: {\n    promoCode: 'SPRING15OFF'\n  }\n});\n```\n\nAdditionally, if I wanted to record the discount amount of the promotion, I could add a `promoDiscount` custom value to the `ORDER` event.\n\n```ts\npagesAnalytics.report({\n  action: 'C_CONVERSION_EVENT',\n  sessionId: 'e790f75d-4f1e-4a1b-b57b-9a456019b176',\n  value: {\n    amount: 35.5,\n    currency: 'USD'\n  },\n  customTags: {\n    promoCode: 'SPRING15OFF'\n  },\n  customValues: {\n    promoDiscount: 41.76\n  }\n});\n```\n\n### Debugging\n\n#### Debug Mode\n\nThe SDK has a debug mode which can be activated by setting the `debug` property in your AnalyticsConfig to `true`.\nThis will prevent `report()` from sending a real request to the Yext Events API. Instead it will print the EventPayload and AnalyticsConfig to console.\n\n#### fetch + keepalive\n\nWe use `fetch()` + `keepalive` by default in [supported browsers](https://developer.mozilla.org/en-US/docs/Web/API/fetch) to make debugging easier. For browsers like Firefox that do not support `keepalive`, [we use the Beacon API](https://developer.mozilla.org/en-US/docs/Web/API/Beacon_API). Users can set `forceFetch: true` in their config, which will make these browsers use `fetch()` instead of the `Beacon API`. Be warned, since `forceFetch` uses `fetch()` without `keepalive`, **requests in progress for browsers like FireFox will be canceled if the page is unloaded**.\n\n## Module support\n\n- The ESM (ES6) build will be used automatically by module bundlers that support it (e.g. Webpack). It can be specified directly by importing `@yext/analytics/lib/esm`\n- The CommonJS build will be used automatically by Node, but it can be specified directly by importing `@yext/analytics/lib/commonjs`\n\n## License\n\nYext Analytics is an open-sourced library licensed under the [BSD-3 License](./LICENSE).\n\n## Third Party Licenses\n\nThe licenses of our 3rd party dependencies are collected here: [THIRD-PARTY-NOTICES](./THIRD-PARTY-NOTICES).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyext%2Fanalytics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyext%2Fanalytics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyext%2Fanalytics/lists"}