{"_id":"@aetraapp/analytics-next","name":"@aetraapp/analytics-next","dist-tags":{"latest":"1.83.0"},"versions":{"1.83.0":{"name":"@aetraapp/analytics-next","version":"1.83.0","repository":{"type":"git","url":"git+https://github.com/segmentio/analytics-next.git","directory":"packages/browser"},"license":"MIT","main":"./dist/cjs/index.js","module":"./dist/pkg/index.js","types":"./dist/types/index.d.ts","browser":{"./dist/cjs/node":"./dist/cjs/node/node.browser.js","./dist/cjs/node.js":"./dist/cjs/node/node.browser.js","./dist/pkg/node":"./dist/pkg/node/node.browser.js","./dist/pkg/node.js":"./dist/pkg/node/node.browser.js"},"sideEffects":false,"scripts":{".":"yarn run -T turbo run --filter=@aetraapp/analytics-next...","build-prep":"sh scripts/build-prep.sh","version":"yarn run build-prep && git add src/generated/version.ts","umd":"webpack","eslint":"yarn run -T eslint","tsc":"yarn run -T tsc","jest":"yarn run -T jest","concurrently":"yarn run -T concurrently","watch":"yarn concurrently 'WATCH=true yarn umd --watch' 'yarn pkg --watch'","build":"yarn clean && yarn build-prep && yarn concurrently 'NODE_ENV=production yarn umd' 'yarn pkg' 'yarn cjs'","release:cdn":"yarn . build && NODE_ENV=production bash scripts/release.sh && NODE_ENV=stage bash scripts/release.sh","pkg":"yarn tsc -p tsconfig.build.json","cjs":"yarn tsc -p tsconfig.build.json --outDir ./dist/cjs --module commonjs","clean":"rm -rf dist","lint":"yarn concurrently 'yarn:eslint .' 'yarn:tsc --noEmit'","test":"yarn jest","vendor":"node scripts/vendor/run.js"},"size-limit":[{"path":"dist/umd/index.js","limit":"29.7 KB"}],"dependencies":{"@lukeed/uuid":"^2.0.0","@segment/analytics-core":"1.8.2","@segment/analytics-generic-utils":"1.2.0","@segment/analytics-page-tools":"1.0.0","@segment/analytics.js-video-plugins":"^0.2.1","@segment/facade":"^3.4.9","dset":"^3.1.4","js-cookie":"3.0.1","node-fetch":"^2.6.7","tslib":"^2.4.1","unfetch":"^4.1.0"},"devDependencies":{"@aws-sdk/client-s3":"^3.540.0","@internal/config":"0.0.0","@segment/analytics-browser-actions-braze":"^1.3.0","@segment/analytics.js-integration":"^3.3.3","@segment/analytics.js-integration-amplitude":"^3.3.3","@segment/tsub":"^2.0.0","@size-limit/preset-big-lib":"^7.0.8","@types/flat":"^5.0.1","@types/fs-extra":"^9.0.2","@types/jest-dev-server":"^5.0.0","@types/jquery":"^3.5.4","@types/js-cookie":"3.0.1","@types/jsdom":"^16.2.14","@types/mime":"^2.0.3","@types/node":"^20","@types/serve-handler":"^6.1.0","circular-dependency-plugin":"^5.2.2","compression-webpack-plugin":"^8.0.1","ecma-version-validator-webpack-plugin":"^1.2.1","execa":"^4.1.0","flat":"^5.0.2","fs-extra":"^9.0.1","jest-dev-server":"^6.0.3","jest-environment-jsdom":"^28.1.1","jquery":"^3.5.1","jsdom":"^19.0.0","lighthouse":"^9.6.3","log-update":"^4.0.0","micro-memoize":"^4.0.9","mime":"^2.4.6","node-gyp":"^9.0.0","playwright":"^1.28.1","serve-handler":"^6.1.3","size-limit":"^7.0.8","terser-webpack-plugin":"^5.1.4","ts-loader":"^9.1.1","ts-node":"^10.8.0","webpack":"^5.94.0","webpack-bundle-analyzer":"^4.4.2","webpack-cli":"^4.8.0"},"packageManager":"yarn@3.4.1","gitHead":"78b6b4ca3b77b867f07ff8d93cd27a3672506fc5","_id":"@aetraapp/analytics-next@1.83.0","description":"Analytics Next (aka Analytics 2.0) is the latest version of Segment’s JavaScript SDK - enabling you to send your data to any tool without having to learn, test, or use a new API every time.","bugs":{"url":"https://github.com/segmentio/analytics-next/issues"},"homepage":"https://github.com/segmentio/analytics-next#readme","_nodeVersion":"24.14.1","_npmVersion":"11.11.0","dist":{"integrity":"sha512-ptHk7bJPcWbUJEZ3azXMzkbYwG1ja2e7AbWERrU1fc7FYU1now8s8bXrW23f58UMmEdt0bcfpgYRM4giCPWUKA==","shasum":"2c1aa8268f5e4c2ae38611b2758be2d2b58115cd","tarball":"https://registry.npmjs.org/@aetraapp/analytics-next/-/analytics-next-1.83.0.tgz","fileCount":672,"unpackedSize":2761390,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIBaSEN4rAiS4mEZpcATAR3fnkdnFqLwD1vmLKiD6kKraAiEA3Xe0B/J8frpDwH+91Bg33eJNjVnRWzc8mRyVFGP1zEo="}]},"_npmUser":{"name":"lukebussey","email":"luke@loganbussey.com"},"directories":{},"maintainers":[{"name":"lukebussey","email":"luke@loganbussey.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/analytics-next_1.83.0_1787619797420_0.8313945138779766"},"_hasShrinkwrap":false}},"time":{"created":"2026-08-25T01:03:17.269Z","1.83.0":"2026-08-25T01:03:17.626Z","modified":"2026-08-25T01:03:17.826Z"},"maintainers":[{"name":"lukebussey","email":"luke@loganbussey.com"}],"description":"Analytics Next (aka Analytics 2.0) is the latest version of Segment’s JavaScript SDK - enabling you to send your data to any tool without having to learn, test, or use a new API every time.","homepage":"https://github.com/segmentio/analytics-next#readme","repository":{"type":"git","url":"git+https://github.com/segmentio/analytics-next.git","directory":"packages/browser"},"bugs":{"url":"https://github.com/segmentio/analytics-next/issues"},"license":"MIT","readme":"# @aetraapp/analytics-next\n\nAnalytics Next (aka Analytics 2.0) is the latest version of Segment’s JavaScript SDK - enabling you to send your data to any tool without having to learn, test, or use a new API every time.\n\n### Table of Contents\n\n- [🏎️ Quickstart](#-quickstart)\n  - [💡 Using with Segment](#-using-with-segment)\n  - [💻 Using as an `npm` package](#-using-as-an-npm-package)\n- [🔌 Architecture](#-architecture--plugins)\n- [🐒 Development](#-development)\n\n---\n\n# 🏎️ Quickstart\n\nThe easiest and quickest way to get started with Analytics 2.0 is to [use it through Segment](#-using-with-segment). Alternatively, you can [install it through NPM](#-using-as-an-npm-package) and do the instrumentation yourself.\n\n## 💡 Using with Segment\n\n1. Create a javascript source at [Segment](https://app.segment.com) - new sources will automatically be using Analytics 2.0! Segment will automatically generate a snippet that you can add to your website. For more information visit our [documentation](https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/)).\n\n2. Start tracking!\n\n## 💻 Using as an `npm` package\n\n1. Install the package\n\n```sh\n# npm\nnpm install @aetraapp/analytics-next\n\n# yarn\nyarn add @aetraapp/analytics-next\n\n# pnpm\npnpm add @aetraapp/analytics-next\n```\n\n2. Import the package into your project and you're good to go (with working types)!\n\n```ts\nimport { AnalyticsBrowser } from '@aetraapp/analytics-next'\n\nconst analytics = AnalyticsBrowser.load({ writeKey: '<YOUR_WRITE_KEY>' })\n\nanalytics.identify('hello world')\n\ndocument.body?.addEventListener('click', () => {\n  analytics.track('document body clicked!')\n})\n```\n\n## Lazy / Delayed Loading\nYou can load a buffered version of analytics that requires `.load` to be explicitly called before initiating any network activity. This can be useful if you want to wait for a user to consent before fetching any tracking destinations or sending buffered events to segment.\n\n- ⚠️ ️`.load` should only be called _once_.\n\n```ts\nexport const analytics = new AnalyticsBrowser()\n\nanalytics.identify(\"hello world\")\n\nif (userConsentsToBeingTracked) {\n    analytics.load({ writeKey: '<YOUR_WRITE_KEY>' }) // destinations loaded, enqueued events are flushed\n}\n```\nThis strategy also comes in handy if you have some settings that are fetched asynchronously.\n```ts\nconst analytics = new AnalyticsBrowser()\nfetchWriteKey().then(writeKey => analytics.load({ writeKey }))\n\nanalytics.identify(\"hello world\")\n```\n## Error Handling\n### Handling initialization errors\nInitialization errors get logged by default, but if you also want to catch these errors, you can do the following:\n```ts\nexport const analytics = new AnalyticsBrowser();\nanalytics\n  .load({ writeKey: \"MY_WRITE_KEY\" })\n  .catch((err) => ...);\n```\n\n## Custom CDN / API Proxy\n[Self Hosting or Proxying Analytics.js documentation](\n https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/custom-proxy/#custom-cdn--api-proxy)\n\n## Examples / Usage in Common Frameworks and SPAs\n\n### Next.js\n- https://github.com/vercel/next.js/tree/canary/examples/with-segment-analytics\n- https://github.com/vercel/next.js/tree/canary/examples/with-segment-analytics-pages-router\n\n### Vanilla React\n```tsx\nimport { AnalyticsBrowser } from '@aetraapp/analytics-next'\n\n// We can export this instance to share with rest of our codebase.\nexport const analytics = AnalyticsBrowser.load({ writeKey: '<YOUR_WRITE_KEY>' })\n\nconst App = () => (\n  <div>\n    <button onClick={() => analytics.track('hello world')}>Track</button>\n  </div>\n)\n```\n\n\n\n### Vue\n\n1. Export analytics instance.\n\n```ts\nimport { AnalyticsBrowser } from '@aetraapp/analytics-next'\n\nexport const analytics = AnalyticsBrowser.load({\n  writeKey: '<YOUR_WRITE_KEY>',\n})\n```\n\n2. in `.vue` component\n\n```tsx\n<template>\n  <button @click=\"track()\">Track</button>\n</template>\n\n<script>\nimport { defineComponent } from 'vue'\nimport { analytics } from './services/segment'\n\nexport default defineComponent({\n  setup() {\n    function track() {\n      analytics.track('Hello world')\n    }\n\n    return {\n      track,\n    }\n  },\n})\n</script>\n```\n\n## Support for Web Workers (Experimental)\n While this package does not support web workers out of the box, there are options:\n\n1. Run analytics.js in a web worker via [partytown.io](https://partytown.builder.io/). See [our partytown example](../../playgrounds/next-playground/pages/partytown). **Supports both cloud and device mode destinations, but not all device mode destinations may work.**\n\n2. Try [@segment/analytics-node](../node) with `flushAt: 1`, which should work in any runtime where `fetch` is available. **Warning: cloud destinations only!**\n\n\n\n\n## How to add typescript support (snippet users only)\n\n1. Install npm package `@aetraapp/analytics-next` as a dev dependency.\n\n2. Create `./typings/analytics.d.ts`\n```ts\n// ./typings/analytics.d.ts\nimport type { AnalyticsSnippet } from \"@aetraapp/analytics-next\";\n\ndeclare global {\n  interface Window {\n    analytics: AnalyticsSnippet;\n  }\n}\n\n```\n3. Configure typescript to read from the custom `./typings` folder\n```jsonc\n// tsconfig.json\n{\n  ...\n  \"compilerOptions\": {\n    ....\n    \"typeRoots\": [\n      \"./node_modules/@types\",\n      \"./typings\"\n    ]\n  }\n  ....\n}\n```\n\n##  🔌 Architecture & Plugins\n- See [ARCHITECTURE.md](architecture/ARCHITECTURE.md)\n\n## 🐒 Development\n\nFirst, clone the repo and then startup our local dev environment:\n\n```sh\n$ git clone git@github.com:segmentio/analytics-next.git\n$ cd analytics-next\n$ nvm use  # installs correct version of node defined in .nvmrc.\n$ yarn && yarn build\n$ yarn test\n$ yarn dev  # optional: runs analytics-next playground.\n```\n\n> If you get \"Cannot find module '@aetraapp/analytics-next' or its corresponding type declarations.ts(2307)\" (in VSCode), you may have to \"cmd+shift+p -> \"TypeScript: Restart TS server\"\n\nThen, make your changes and test them out in the test app!\n\n<img src=\"https://user-images.githubusercontent.com/2866515/135407053-7561d522-b969-484d-8d3a-6f1c4d9c025b.gif\" alt=\"Example of the development app\" width=\"500px\">\n\n\n\n","readmeFilename":"README.md","_rev":"1-fd882e0f7b2e064679b5d22bfa726ea1"}