# 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 ``` Every call after that is a method on `snekot`, such as `snekot.track(…)` below. A site set up earlier may call `snekot('track', …)` instead, with the method's name first, and have an older snippet: both still work, so leave them as they are unless the person asks. 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. Whether the site needs a consent banner depends on where its visitors are and what else it runs. That is the owner's decision: leave the site's banner, or its absence, as it is, and tell the owner the question is theirs. ## 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.5.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 an iPhone, iPad or Mac app, create the Swift client once at launch with the app side on: `SnekotEvents(token: "PUBLIC_KEY", project: "project-slug", queue: OfflineQueue(), app: AppAnalytics())`. It then posts `App installed`, `App updated` and `App opened` to the `app` channel by itself and adds the app's version, build, system, device model and language to every event and screen. Name each screen as it appears with `try? await snekot.screen("Checkout")`, call `identify` on sign-in and `snekot.reset()` on sign-out. The project's Views page then has an App choice. https://snekot.co/docs/apps has the fields, for sending them from any other kind of app. 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. A newsletter signup needs no code in a web page: `
` with an email field puts the address on the project's list of subscribers, with the browser's language and time zone. On a site in several languages, add `data-snekot-language="sv"` to the form to keep the language of the page instead. From a server or an app, `subscribe` takes `email`, and may take `name`, `properties`, `source`, `language` (a tag such as `sv-SE`) and `timezone` (a name such as `Europe/Stockholm`). https://snekot.co/docs/subscribers has the rest. ### 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, every library has `identify`, taking the id and the properties in its language's own form (`events.identify({ user_id, properties })` in TypeScript, `events.identify(user_id, properties)` in Python). 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 and keeps what they did. With `?events=true` it erases the person: their events, page views and A/B test records go too, for good, under every id and visitor joined to them. That is the call for when someone asks the product to delete what it keeps about them; make it where the product deletes an account, if it has that, and tell the person first, since it cannot be undone. ## 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_TOKEN" \ -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. Every library has the same call as `experiment`, and `useEvents()` has it in React. - 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. ## 5. Feature flags A flag is a key and a switch. The person makes it in the app, under Experiments, Flags, and hands you its key. Use the key exactly as given: a key no flag has is answered off, and asking does not make one. The person turns the flag on in the app, for everyone, a share of visitors, or people by id; nothing in the code decides that. Ask whether the flag is on for this visitor, and show the feature only if it is. In a page with the script: ```js window.snekot.flag('new-checkout', (on) => { if (on) showTheNewCheckout(); }); ``` From a server, with a private key, when the flag decides what is rendered: ```sh curl -X POST https://api.snekot.co/v1/flag \ -H "Authorization: Bearer $SNEKOT_TOKEN" \ -H "Content-Type: application/json" \ -d '{"flag":"new-checkout","user_id":"user-123"}' ``` It answers `{"flag":"new-checkout","on":true}`. Send the person's `user_id`, or their `ip` and `user_agent` when they have none. Every library has the same call as `flag`, and React has `useFlag(key)`. - Off is the product as it is today. Build the feature beside it, never in place of it, so turning the flag off takes the feature away and breaks nothing. - If the answer cannot be had, the script answers `false`, and a library's call fails as its other calls do: catch that and treat it as off. A flag must never be the reason a page or a request fails. - Hide what the flag changes until the callback runs, or decide on the server, so the page does not flicker. - The same person always gets the same answer, and asking is not recorded: it is not an event and costs nothing. To measure the feature, send an event from it, or use an A/B test instead. - Do not cache the answer for longer than a page or a request: the person expects the switch to act at once. - When you are done, tell the person where the flag is asked for and what it turns on, and that it is off until they turn it on in the app. ## 6. Forms A contact, signup or quote form on the person's site can send its submissions here, where they are kept under Forms, tied to the person who wrote them. Do this only when the person asks for it, or when a form on the site posts nowhere. Nothing is set up first: the form is named where it is sent from, and whatever fields it has are kept. With the script on the page, mark the form. The page stays where it is: ```html
``` Without the script, a plain form posts to an address with the public key and the form's name in it: ```html
``` - Use the public key only. Keep the fields' own `name`s: they become the columns the person reads. - Give the form an email field when it has one to give: the address ties the submission to a person. - `_trap` stays empty and hidden; what fills it in is not kept. `_redirect` must be on the form's own site. - A file field (``) is kept with the submission: add `enctype="multipart/form-data"` to a plain form; the script needs nothing more. Up to 5 files of 10 MB each, documents and pictures only (pdf, doc, docx, xls, xlsx, ppt, pptx, odt, rtf, txt, csv, png, jpg, gif, webp, heic). A file that is not taken never costs the submission. - Files are private: read only in the app, through a link that works for a minute. They count against the account's file storage, 1 GB on the smallest plan and more on larger ones. - A submission holds up to 40 fields of up to 5,000 characters each. - From a server, `POST https://api.snekot.co/v1/form` with `{"form":"Contact","fields":{…}}`. https://snekot.co/docs/forms has the rest. ## 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 Setup's "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. - For money to be added up as revenue, a payment is the event `Order paid` (or `Subscription renewed`) in the channel `payments`, with the tags `amount` as a number and `currency` as a three-letter code, and the payer's `user_id`. Money returned is `Refund`, tagged the same way. Send them from the server. - 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, form submissions, 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, feature flags, form submissions' status and note, 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. A project's keys together may make 300 requests a minute to the MCP server, and so may one person's account keys. Reads on `/v1` with a project's private, read and manage keys are held to 600 a minute together. Past either, the answer is `429` with a `Retry-After` header in seconds: wait that long, and do not retry sooner. 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 ten of the read tools as charts: `project_summary`, `realtime`, `traffic_overview`, `traffic_sources`, `count_events`, `funnel`, `retention`, `top_values`, `experiment_results` and `list_charts` (the whole board). A funnel's step is an event's exact name or a page view as `view:`, such as `view:/pricing`. ## 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) - [Apps: installs, updates, opens and screens from an iPhone, iPad or Mac app, and the app details on every event](https://snekot.co/docs/apps) - [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) - [Forms: pointing a contact, signup or quote form at Snekot, with or without the script, and the files it takes](https://snekot.co/docs/forms) - [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 charts it draws in a chat](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) - [Feature flags: a switch for a feature, on for a share of visitors or for people by name](https://snekot.co/docs/flags) - [Revenue: which events count as money, whose payment it is, and reading the total and its split by source](https://snekot.co/docs/revenue) - [Bot traffic: which page views are marked as bots, why, and the switch that counts them](https://snekot.co/docs/bots) - [Limits and errors](https://snekot.co/docs/limits)