> For the complete documentation index, see [llms.txt](https://docs.millimetric.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.millimetric.ai/sdks/frameworks.md).

# Framework recipes

Drop-in setup for React, Next.js, Vue, Svelte, and other JS frameworks.

The browser SDK (`@millimetric/track`) is framework-agnostic — it's just `init`, `track`, `identify`, `page`, `flush`. This page collects the small, copy-paste-ready integrations for the frameworks people actually use.

If your framework isn't listed, the [pure-JS browser snippet](/sdks/browser.md#a-drop-in-script-snippet--for-static-sites-webflow-framer-marketing-pages) Just Works on any HTML page.

## Sub-recipes

* [React](/sdks/frameworks/react.md)
* [Next.js](/sdks/frameworks/nextjs.md)
* [Vue](/sdks/frameworks/vue.md)
* [Svelte / SvelteKit](/sdks/frameworks/svelte.md)

## Common pattern across all of them

Three things, in order:

1. **Init once** — at the top of your app, with your `pk_*` key.
2. **Identify on auth** — when you know who the visitor is.
3. **Track on intent** — buttons, conversions, the things you'd put in a funnel.

Auto-pageviews (including SPA navigations) are on by default; you usually don't have to call `page()` yourself.

## Where to put the key

| Framework               | Env var name (suggested) | Read at                                               |
| ----------------------- | ------------------------ | ----------------------------------------------------- |
| Vite (React/Vue/Svelte) | `VITE_AOA_KEY`           | `import.meta.env.VITE_AOA_KEY`                        |
| Next.js                 | `NEXT_PUBLIC_AOA_KEY`    | `process.env.NEXT_PUBLIC_AOA_KEY`                     |
| Nuxt                    | `NUXT_PUBLIC_AOA_KEY`    | `useRuntimeConfig().public.aoaKey`                    |
| SvelteKit               | `PUBLIC_AOA_KEY`         | `import { PUBLIC_AOA_KEY } from "$env/static/public"` |

The `pk_*` key is browser-safe — it's origin-allowlisted on the server. Never expose `sk_*` or `rk_*` to the browser.

## Anti-patterns

* **Calling `init()` in a render function.** Init is idempotent but inits-per-render is wasteful. Wrap in `useEffect` (React) / `onMount` (Svelte) / `mounted()` (Vue).
* **Tracking inside `useEffect` cleanup.** The cleanup runs on unmount and on every re-render — easy to over-track. Track on the user action (`onClick`), not on the effect lifecycle.
* **Calling `flush()` synchronously in render.** It returns a promise; awaiting it in render breaks SSR.
* **Setting `user_id` from your URL.** Use `identify(user.id)` once after auth resolves; don't pass `user_id` per-call.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.millimetric.ai/sdks/frameworks.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
