Install Statlark with npm
Install @statlark/web and start the same tracker in code, with a typed API and a React provider.
Using an AI coding tool?Hand it the prompt below, or point it at this page as markdown: npm.md
Where it goes
Your app's client entry point, or a client component at the root if you use React.
Steps
- Install the package:
npm install @statlark/web. - 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. - You can call
goal(),identify()andpayment()straight away. Calls made before the tracker loads are queued and sent in order. - Using React? Wrap your app in
StatlarkProviderin a client component at the root, then calluseStatlark()in any client component. - Don't call
pageview()for normal page changes. The tracker counts page loads and client-side navigations itself.
Terminal
npm install @statlark/webClient entry point
import { initStatlark } from "@statlark/web";
const statlark = await initStatlark({ site: "YOUR_SITE_ID" });
statlark.goal("signup", { plan: "pro" });app/providers.tsx (React)
"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 in its place: it loads the tracker only after the visitor accepts. Or switch on cookieless mode, which stores nothing on the device.
The package loads the same tracker, so the same applies. For cookieless mode, pass cookieless: true.
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.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 fordata-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 · WordPress · Shopify · Webflow · Google Tag Manager · anything else
Sources
These steps were checked against the pages below on .
Last reviewed