# Install Statlark with npm

This is the markdown version of https://statlark.com/docs/install/npm. Every docs and Learn page has one: add .md to its address. Index: https://statlark.com/llms.txt

Install @statlark/web and start the same tracker in code, with a typed API and a React provider.

## <a id="where"></a>Where it goes

Your app's client entry point, or a client component at the root if you use React.

## Steps

1. Install the package: `npm install @statlark/web`.
2. Call `initStatlark()` once, in code that runs in the browser on every page, with your site ID from Settings → Install. On the server it returns a handle that does nothing, so it's safe during server rendering.
3. You can call `goal()`, `identify()` and `payment()` straight away. Calls made before the tracker loads are queued and sent in order.
4. Using React? Wrap your app in `StatlarkProvider` in a client component at the root, then call `useStatlark()` in any client component.
5. Don't call `pageview()` for normal page changes. The tracker counts page loads and client-side navigations itself.

Terminal

```sh
npm install @statlark/web
```

Client entry point

```ts
import { initStatlark } from "@statlark/web";

const statlark = await initStatlark({ site: "YOUR_SITE_ID" });

statlark.goal("signup", { plan: "pro" });
```

app/providers.tsx (React)

```tsx
"use client";
import { StatlarkProvider } from "@statlark/web/react";

export function Providers({ children }: { children: React.ReactNode }) {
  return <StatlarkProvider config={{ site: "YOUR_SITE_ID" }}>{children}</StatlarkProvider>;
}
```

The tag sets a first-party analytics cookie as soon as it loads. Where the law asks for consent first, such as for visitors in the EU or UK, install the [consent banner](https://statlark.com/docs/consent.md) in its place: it loads the tracker only after the visitor accepts. Or switch on [cookieless mode](https://statlark.com/docs/script-configuration.md#cookieless), which stores nothing on the device.

The package loads the same tracker, so the same applies. For cookieless mode, pass `cookieless: true`.

## <a id="ai-prompt"></a>Hand this to your AI

For AI tools: this is the prompt a customer pastes in to start this task. If you are already following it, don’t start again: use the rest of this page as the guide.

Paste this into Claude Code, Cursor or another AI coding tool, in your project. Replace `YOUR_SITE_ID` with the ID from Settings → Install first. It never needs your API key.

```
Add Statlark analytics to this project with the @statlark/web package.

Follow this guide for the exact code: https://statlark.com/docs/javascript-sdk.md
If that link doesn't open, try the same address without .md. If neither opens, stop and tell me. Don't write this from memory.

1. First check the site doesn't already load Statlark, whether through the script tag, consent.js, @statlark/web or a first-party proxy. If it does, stop and tell me.
2. Statlark sets first-party analytics cookies. Ask me whether this site has visitors in the EU or UK; you can't tell from the code. If it does, or I'm not sure, stop before installing it, because they may need to consent first: https://statlark.com/docs/consent.md
3. Install @statlark/web with the project's package manager. Call initStatlark({ site: "YOUR_SITE_ID" }) once, in code that runs in the browser on every page. If the id still says YOUR_SITE_ID, ask me for it: it's under Settings, Install in Statlark. In a React app, wrap the root in StatlarkProvider in a client component instead, and use useStatlark() where you need the handle.
4. Don't add pageview calls for normal navigation. The tracker counts page loads and client-side navigations itself.
5. If the site has a Content Security Policy (check its server or framework config and any <meta http-equiv="Content-Security-Policy"> tag), allow https://statlark.com for scripts and https://collect.statlark.com for connections.
6. Don't change anything else. Finish by telling me what you changed. Remind me to deploy, then confirm it in Statlark under Settings, Install, Verification, because visits from localhost aren't counted by default.
```

## <a id="check"></a>Check it’s working

Open your deployed app. The package adds the tag in the browser, so View Source won't show it. Look in your browser's developer tools instead: the Network tab should show `script.js` loading.

Then open Settings → Install in Statlark and look under Verification. It says “You're live” once the site's first event arrives, usually within seconds. On a site that already had traffic it's green already, so the real test is your own visit: open your live site, then find yourself on the Overview with the Now range. A browser you excluded with `?statlark_ignore=1` won't show up.

## Good to know

- Testing on localhost? Pass `trackLocalhost: true`. It's the package's name for `data-allow-localhost`.
- Pick one install method, and don't also paste the script tag. A second `initStatlark()` with a different site is ignored, with a console warning.

## Other platforms

[Next.js](https://statlark.com/docs/install/nextjs.md) · [WordPress](https://statlark.com/docs/install/wordpress.md) · [Shopify](https://statlark.com/docs/install/shopify.md) · [Webflow](https://statlark.com/docs/install/webflow.md) · [Google Tag Manager](https://statlark.com/docs/install/google-tag-manager.md) · [anything else](https://statlark.com/docs/install.md#anything-else)

## Sources

These steps were checked against the pages below on 10 November 2026.

- [npmjs.com/package/@statlark/web](https://www.npmjs.com/package/@statlark/web)

Last reviewed 21 November 2026
