{"_id":"@alyt/svelte","name":"@alyt/svelte","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.1":{"name":"@alyt/svelte","version":"0.1.1","description":"Svelte 5 bindings for alyt — AnalyticsProvider and analytics context","keywords":["analytics","svelte","sveltekit","typescript","event-tracking"],"repository":{"type":"git","url":"git+https://github.com/mathematic-inc/alyt.git","directory":"packages/svelte"},"license":"Apache-2.0","author":{"name":"Mathematic Inc"},"type":"module","exports":{".":{"types":"./build/index.d.ts","svelte":"./build/index.js","default":"./build/index.js"}},"svelte":"./build/index.js","types":"./build/index.d.ts","dependencies":{"@alyt/core":"0.1.3"},"devDependencies":{"@sveltejs/package":"^2.5.8","@sveltejs/vite-plugin-svelte":"^7.3.0","jsdom":"^30.0.1","svelte":"^5.57.0","svelte-check":"^4.7.6","typescript":"6.0.3","vitest":"^4.1.11"},"peerDependencies":{"svelte":"^5.0.0"},"scripts":{"build":"svelte-package -i src -o build","test":"vitest run","typecheck":"svelte-check --tsconfig ./tsconfig.json --fail-on-warnings"},"_id":"@alyt/svelte@0.1.1","bugs":{"url":"https://github.com/mathematic-inc/alyt/issues"},"homepage":"https://github.com/mathematic-inc/alyt#readme","_integrity":"sha512-WXV4yQk9jZBk63Me1v6gY0oYQJZbXbQNBoIkdXn6LnK4MShbqYHUtkN2LKy+F3u8hL3rydDkCHy7+Ayh9ONUow==","_resolved":"/Users/jrandolf/Documents/Codex/2026-09-05/alyt-svelte-bindings/outputs/alyt-svelte-0.1.1.tgz","_from":"file:/Users/jrandolf/Documents/Codex/2026-09-05/alyt-svelte-bindings/outputs/alyt-svelte-0.1.1.tgz","_nodeVersion":"26.7.0","_npmVersion":"11.19.0","dist":{"integrity":"sha512-WXV4yQk9jZBk63Me1v6gY0oYQJZbXbQNBoIkdXn6LnK4MShbqYHUtkN2LKy+F3u8hL3rydDkCHy7+Ayh9ONUow==","shasum":"5b8898a918ccf6a74169a16ac2510d399143412b","tarball":"https://registry.npmjs.org/@alyt/svelte/-/svelte-0.1.1.tgz","fileCount":12,"unpackedSize":19185,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDzTppFjQqDcjj1rKK244FAWhdM/GGsVkx1AmyI4WNfQAIgdF8ZtQTE5vV+k6vVdwJmXn40AAu3S/tLa1BatZEZg4k="}]},"_npmUser":{"name":"junsheaf","email":"me@jrandolf.com"},"directories":{},"maintainers":[{"name":"junsheaf","email":"me@jrandolf.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/svelte_0.1.1_1788597602913_0.1912518982786895"},"_hasShrinkwrap":false}},"time":{"created":"2026-09-05T08:40:02.796Z","0.1.1":"2026-09-05T08:40:03.024Z","modified":"2026-09-05T08:40:03.205Z"},"maintainers":[{"name":"junsheaf","email":"me@jrandolf.com"}],"description":"Svelte 5 bindings for alyt — AnalyticsProvider and analytics context","homepage":"https://github.com/mathematic-inc/alyt#readme","keywords":["analytics","svelte","sveltekit","typescript","event-tracking"],"repository":{"type":"git","url":"git+https://github.com/mathematic-inc/alyt.git","directory":"packages/svelte"},"author":{"name":"Mathematic Inc"},"bugs":{"url":"https://github.com/mathematic-inc/alyt/issues"},"license":"Apache-2.0","readme":"# @alyt/svelte\n\nSvelte 5 bindings for alyt: `AnalyticsProvider`, `getAnalytics`, and\n`setAnalytics`.\n\n```sh\npnpm add @alyt/core @alyt/svelte\n```\n\nIn a SvelteKit root layout, create the client inside the component so each\nserver request gets its own instance:\n\n```svelte\n<script lang=\"ts\">\n  import { createAnalytics } from \"@alyt/core\";\n  import { AnalyticsProvider } from \"@alyt/svelte\";\n  import type { Snippet } from \"svelte\";\n\n  let { children }: { children: Snippet } = $props();\n  const client = createAnalytics();\n</script>\n\n<AnalyticsProvider {client}>\n  {@render children()}\n</AnalyticsProvider>\n```\n\nRead the client during a descendant component's initialization:\n\n```svelte\n<script lang=\"ts\">\n  import { getAnalytics } from \"@alyt/svelte\";\n  import { createTracker } from \"$lib/generated/tracker.js\";\n\n  const analytics = getAnalytics();\n  const tracker = createTracker(analytics);\n</script>\n\n<button onclick={() => tracker.signupClicked(\"header\")}>Sign up</button>\n```\n\n`createTracker` is generated by `@alyt/codegen` from your event schema. Its\ntypes and `TrackOptions.only` filtering work unchanged. The returned client\nis the original core client, including `track`, `identify`, `page`, `reset`,\n`addPlugin`, and `removePlugin`.\n\n## Context\n\nCall `getAnalytics()` during component initialization, then use the returned\nclient in event handlers, effects, and lifecycle callbacks. It throws if no\nancestor provided a client. Nested providers override context only for their\nown descendants.\n\nYou can use `setAnalytics(createAnalytics())` in a layout's instance script\ninstead of the provider component. `setAnalytics` returns the supplied client\nand makes it available to descendants. Both helpers use Svelte's component\ncontext; neither stores a client in module-level state.\n\nThe provider captures its initial `client`. Keep that instance for the tree's\nlifetime and mutate its plugins as needed. To replace the client, remount the\ntree with `{#key client}<AnalyticsProvider {client}>…</AnalyticsProvider>{/key}`.\nThe caller owns the client and its SDKs; unmounting the provider does not reset\nor dispose of a shared client.\n\n## Plugins and consent\n\nUse a Svelte effect in a descendant component to scope plugin registration\nto consent and component lifetime:\n\n```svelte\n<script lang=\"ts\">\n  import { googleAnalytics } from \"@alyt/plugin-ga\";\n  import { getAnalytics } from \"@alyt/svelte\";\n\n  let { consent }: { consent: boolean } = $props();\n  const analytics = getAnalytics();\n\n  $effect(() => {\n    if (consent) {\n      const plugin = googleAnalytics({ measurementId: \"G-XXXXXXXXXX\" });\n      analytics.addPlugin(plugin);\n      return () => analytics.removePlugin(plugin.name);\n    }\n  });\n</script>\n```\n\nEffects run only in the browser. Initialize `gtag.js` separately under your\nconsent policy, or use the existing SDK initialization in your app. Each\nplugin name should have one registration owner per client.\n\nRemoving a plugin stops alyt from forwarding events to it. It does not unload\nthe provider SDK, revoke its consent, clear cookies, or stop its automatic\ncollection. Apply the SDK's consent controls as well. Events without a\nregistered plugin are dropped; the bindings do not buffer or replay them.\n\nThe bindings do not load SDK scripts, track navigation, or implement GA4\nenhanced measurement. When GA4 already collects page views, scrolls, outbound\nclicks, or form events, avoid sending duplicate events through alyt. Use typed\ntrackers for your application's business events.\n\nSee the [runnable SvelteKit example](https://github.com/mathematic-inc/alyt/tree/main/examples/sveltekit).\n","readmeFilename":"README.md","_rev":"1-d28c25880cfab9a7a054e09d12a84210"}