# Snekot > Snekot shows a product's owner everything that happens in it: page views without cookies, and events such as > sign-ups, orders and errors, in a live feed with charts and push notifications. This file tells an assistant how to > add it to a website or an app. ## What you need from the person They sign up at https://app.snekot.co and create a project. Ask them for these, from the project's Setup screen: - the project's slug, such as `acme-store` - a **public key** (starts with `pk_`) for anything that runs in a browser or an app - only if you will send events from a server: a **private key** (starts with `sk_`) Never put a private key in a web page, an app or a public repository. Put it in a server-side secret or environment variable, and never print it back to the person. ## 1. Page views: one script tag Add this to every page, in the shared layout or ``, with the person's own key and slug: ```html ``` That is all page views need. As it comes, without `remember`, `identify` or `setUserId`, it sets no cookie and keeps nothing on the visitor's device. It follows address changes in single-page apps by itself. Do not add a cookie banner for it as it comes. ## 2. Events: the things that matter An event is something that happened: a sign-up, an order, a failed payment. Pick the handful that the owner would want to know about. Give each a `channel` (lowercase letters, digits and dashes) and an `event` name in plain words. In a web page, with no code, add attributes to the button or form: ```html
…
``` In a web page, from code: ```js window.snekot('track', { channel: 'signups', event: 'Signed up', icon: '👋' }); ``` From a server, with the private key, in any language: ```bash curl -X POST https://api.snekot.co/v1/log \ -H "Authorization: Bearer PRIVATE_KEY" \ -H "Content-Type: application/json" \ -d '{ "channel": "orders", "event": "Order placed", "icon": "📦", "notify": true, "user_id": "user-123", "tags": { "total": 49 } }' ``` Only `channel` and `event` are required. `notify: true` sends a push notification to the owner's phone: use it for the few events worth an interruption, such as a sale or an error, not for everything. `user_id` ties an event to a person. `tags` are any extra facts, as strings, numbers or booleans. ### From a server, with an SDK There are open-source libraries at https://github.com/snekot-co. Use one when the project is in its language; plain HTTP as above is always fine too. TypeScript is on npm, Python on PyPI and Rust on crates.io; Swift and Kotlin install from their repositories. Use these exact lines and do not guess a registry name: TypeScript or JavaScript (Node 18 and later, Deno, Bun, edge; `import` or `require`): ```bash npm install @snekot/sdk ``` ```ts import { Client } from '@snekot/sdk'; const events = new Client({ token: process.env.SNEKOT_TOKEN ?? '', project: 'project-slug', disableTracking: !process.env.SNEKOT_TOKEN }); await events.track({ channel: 'orders', event: 'Order placed', icon: '📦', notify: true, user_id: 'user-123', tags: { total: 49 } }).catch(() => {}); ``` Python (3.8 and later, standard library only): ```bash pip install snekot-events ``` ```python import os from snekot_events import Client events = Client(token=os.environ.get("SNEKOT_TOKEN", ""), project="project-slug", disable_tracking=not os.environ.get("SNEKOT_TOKEN")) try: events.track(channel="orders", event="Order placed", icon="📦", notify=True, user_id="user-123", tags={"total": 49}) except Exception: pass ``` Rust (async, needs Tokio): ```bash cargo add snekot-events ``` ```rust use snekot_events::{Client, Track}; let events = Client::builder(token, "project-slug").build(); let _ = events.track(Track::new("orders", "Order placed").icon("📦").notify(true).user_id("user-123").tag("total", 49)).await; ``` Swift (iOS 15, macOS 12 and later; in an app, use the public key). Add the package `https://github.com/snekot-co/snekot-swift` from version `0.3.0`, then: ```swift import SnekotEvents let events = SnekotEvents(token: "PUBLIC_KEY", project: "project-slug") try? await events.track(channel: "orders", event: "Order placed", userID: "user-123", icon: "📦", tags: ["total": 49]) ``` Kotlin and the JVM: two files with no dependencies. Copy `SnekotEvents.kt` and `OfflineQueue.kt` from https://github.com/snekot-co/snekot-kotlin/tree/main/src/main/kotlin/co/snekot/events into the project, then `SnekotEvents(token = token, project = "project-slug").track(channel = "orders", event = "Order placed")`. Its calls block, so run them off the main thread. In a phone app, give the Swift or Kotlin client an offline queue, so events made without a connection are kept and sent later: `SnekotEvents(token: "PUBLIC_KEY", project: "project-slug", queue: OfflineQueue())` in Swift, `SnekotEvents(token = key, project = "project-slug", queue = OfflineQueue(context.filesDir))` in Kotlin. Every library also has `identify`, `group`, `subscribe` and insights, sends to https://api.snekot.co by default, tries once more after a network failure or a server error, and never retries a refusal. ### In React, Next.js or Vue The TypeScript package wraps the script tag, so do not add the script tag as well: ```tsx import { EventsProvider, useEvents } from '@snekot/sdk/react'; {children} const { track, setUserId } = useEvents(); track({ channel: 'signups', event: 'Signed up', icon: '👋' }); ``` In Next's App Router the provider can go straight into the root layout. In Vue: `import Events, { track } from '@snekot/sdk/vue'` and `app.use(Events, { token: 'PUBLIC_KEY', project: 'project-slug' })`. ## 3. People: who is signed in If the product has accounts, identify people when they sign in or their account loads. They then appear under People with a page of their own: a name, an email, the properties the owner keeps about them, where they first came from, and everything they did. Without this the owner sees only anonymous visitors. In a web page, one call says who is signed in and what is known about them, and when they sign out, clear it: ```js window.snekot('identify', { user_id: 'user-123', properties: { name: 'Jane Park', email: 'jane@acme.co', plan: 'pro', paying: true, 'paying-since': '2026-03-01' }, }); window.snekot('clearUserId'); ``` With the React or Vue wrapper it is `identify({ user_id, properties })` from `useEvents()`. From a server, with a private key, it is `events.identify({ user_id, properties })` in every library, or: ```sh curl -X POST https://api.snekot.co/v1/identify \ -H "Authorization: Bearer PRIVATE_KEY" \ -H "Content-Type: application/json" \ -d '{ "user_id": "user-123", "properties": { "name": "Jane Park", "email": "jane@acme.co", "plan": "pro" } }' ``` - `user_id` is the product's own id for the person, the one in its database. Use the same id on every event about them (`user_id` on `/v1/log`), so what they do on the server joins what they do in the browser. - `name` and `email` are the two properties the app shows as a person's heading. Every other key is the product's own: lowercase letters, digits and dashes, with a string, number or boolean. Good ones are what the owner would want beside a name: the plan, whether and since when they pay, their company, where they came from. - Keys sent again replace their old values and the rest are kept. A key sent as `null` is removed, from a server with a private key only; from a browser a `null` is ignored. Call identify again when something changes, such as the plan after a payment; send that from the server, not the browser. - **What is sent about a person is the owner's choice, not yours.** A person has no name, email or properties that the product does not send. Before you add identify, tell the person which details you plan to send and let them take any out; an id alone is enough to work. Never send passwords, payment details, or anything the product's own privacy policy would not cover. When you are done, list every property you send. - `identify` and `setUserId` keep the id in the browser's storage so later pages know who is signed in. That is for signed-in people only; leave anonymous visitors as they are. - `DELETE https://api.snekot.co/v1/users/USER_ID` with a private key removes everything said about a person, for when someone asks the product to erase them. Call it where the product deletes an account, if it has that. ## 4. A/B tests An experiment has a name and two to eight variants; the first is the control, what the product shows today. The person usually makes it in the app first, under Experiments, and hands you its exact name, its variants in order and its goal. Use those exactly as given: a different name is a different experiment, and a different order deals visitors again. If they have not made one, the first ask below makes it. Ask which variant this visitor gets, and show that one. In a page with the script: ```js window.snekot('experiment', 'pricing-headline', ['control', 'new'], (variant) => { if (variant === 'new') showTheNewHeadline(); }); ``` From a server, with a private key, when the variant decides what is rendered: ```sh curl -X POST https://api.snekot.co/v1/experiment \ -H "Authorization: Bearer $SNEKOT_KEY" \ -H "Content-Type: application/json" \ -d '{"experiment":"pricing-headline","variants":["control","new"],"user_id":"user-123"}' ``` It answers `{"experiment":"pricing-headline","variant":"new"}`. Send the person's `user_id`, or their `ip` and `user_agent` when they have none. The TypeScript client has the same call as `experiment`, and `useEvents()` has it in React. In any other language, make the `POST /v1/experiment` call yourself. - The same person always gets the same variant, and being shown one is recorded once a visit. Nothing else is needed to count visitors. - If the answer cannot be had, the script answers with the first variant, so the page must work with it. Hide what differs until the callback runs, or decide on the server, so the page does not flicker. - The goal is an ordinary event, or a page view. Make sure it is sent when it happens, from the same browser or with the same `user_id` as the visitor who saw the variant, or it cannot be tied to them. Do not invent a new event if the product already sends the one the person named. - When the person ends the experiment in the app, every ask is answered with the variant they kept, so the code keeps working. Tell them it can then be taken out, leaving that variant in. - When you are done, tell the person where the experiment is asked for and what each variant shows. ## Check that it works Do this before you say the work is done. Do not read the script's source to find out why nothing arrived. 1. Prove the key, project and channel without sending anything. A dry run checks the call and stores nothing: ```sh curl -X POST "https://api.snekot.co/v1/log?dry_run=1" \ -H "Authorization: Bearer $SNEKOT_TOKEN" -H "Content-Type: application/json" \ -d '{"project":"project-slug","channel":"orders","event":"Order placed"}' ``` `200` with `"dry_run": true` means a real call with the same key and fields will be accepted. Anything else is a refusal whose `message` says what to fix: 401 is the key, 403 is the project or channel, 400 is a field. 2. In a browser, if nothing arrives, look at the console first. The script sends nothing in two cases, and says so: after `snekot('setDebug', true)` it logs each call as `[snekot] /v1/log {…}` in place of sending it, and without `setConfig` it warns "not configured". Local addresses are treated like any other: the script does not skip localhost by itself, so the only thing keeping local runs quiet is your own guard. A 403 that names "Allowed senders" means the project only accepts its listed sites, and a preview or local address is not one of them; ask the person to add it under Setup, or check on the real site. 3. A sent event answers `201` with its `id`. Look for that request in the network tab; that is proof enough. 4. Do not send made-up events to prove it works: they land in the person's real feed and count towards their plan. If the person asks for one real event, send exactly one, name it plainly such as "Setup check", and tell them. ## Rules for a good integration - Send events when the thing has really happened: after the order is saved, not when the button is pressed. - A failed call must never break the product. Do not await it in a way that can fail a request, and catch its errors. - Do not send passwords, card numbers or anything else secret in a description or a tag. - If you call the API yourself from Python's `urllib`, set a `User-Agent` header of your own. Its default one is turned away with a 403 before it reaches the API. The Python SDK and `requests` are fine. - Do not send events from local development or tests. Read the key from an environment variable and skip when unset. In a browser, `snekot('setDebug', true)` does the same: calls are logged to the console and nothing is sent. - When you are done, tell the person which events you added and where, and ask them to open https://app.snekot.co and watch the first one arrive in the feed. ## After it is added: the MCP server The person can then ask about their numbers, and manage the project, from an assistant instead of the app. The server is at https://api.snekot.co/mcp, with a key as a Bearer token: ```sh claude mcp add --transport http snekot https://api.snekot.co/mcp --header "Authorization: Bearer KEY" ``` - A read key (`rk_`) reads one project: events, counts, funnels, retention, page views, visitors now, people, subscribers, A/B test results and the charts board. It cannot change anything. - A manage key (`mk_`) also changes that project: charts and goals, A/B tests, keys, the invitation link for teammates, the shared overview, allowed senders, forwarding, the name and colour. - An account key (`ak_`) is the person: every project they are on, and creating a project, which answers with its first keys. With one, a person never has to open the app to get started. Never put a manage or account key in the product's code or in a repository. They belong in the assistant's config. Deleting a project or the account, and paying, stay in the app. Clients that draw MCP Apps show `realtime`, `traffic_overview`, `count_events` and `funnel` as cards. ## Plans A new account can try everything for 7 days without a card. After that, plans start at $5 a month for 10,000 events. A page view counts as one event, from the same allowance. Past the month's allowance, a call still answers `201`, but the event or page view is held: stored and not shown until the account has a bigger plan or the month turns. A call answers `429` at twice the month's events, and `402` once the account has had no plan for 7 days. ## Docs - [Quick start](https://snekot.co/docs) - [Web pages: the script tag, clicks without code, forms, the feedback button](https://snekot.co/docs/browser) - [Site builders: where the script goes on Shopify, WordPress, Wix, Webflow, Squarespace, Framer and others](https://snekot.co/docs/platforms) - [AI builders: where keys go in Lovable, Replit, Bolt and v0](https://snekot.co/docs/builders) - [Zapier, Make and n8n](https://snekot.co/docs/automation) - [Newsletter signups: sending the addresses from a subscribe field](https://snekot.co/docs/subscribers) - [Sending events over HTTP: every field](https://snekot.co/docs/api) - [Private, public, read and manage keys, and account keys](https://snekot.co/docs/keys) - [SDKs for TypeScript, Effect, React, Vue, Python, Rust, Swift and Kotlin: install lines and every call](https://snekot.co/docs/sdks) - [Reading events and counts back](https://snekot.co/docs/reading) - [The MCP server: every tool, which key each needs, and the chat widgets](https://snekot.co/docs/agents) - [Your own domain: serving the script through your site so blockers leave it alone](https://snekot.co/docs/proxy) - [Forwarding events to Slack, Discord, Telegram or a webhook](https://snekot.co/docs/forwarding) - [A/B tests](https://snekot.co/docs/experiments) - [Limits and errors](https://snekot.co/docs/limits)