# 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: ` ``` 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: