SDK reference
The browser SDK is one small script, the loader. It reads your published tours from Neaten's CDN, decides in the browser which tour may start, and only then loads the code that draws it. It never throws into your page, and if it can't load, your app works as before, without tours. Use it as a script tag (the global neaten) or through @neaten/sdk on npm, a typed wrapper that adds the same script.
Script tag
<script async src="https://cdn.tryneaten.com/v1/loader.js" data-key="pk_live_…"></script>
| Attribute | What it does |
|---|---|
src | The loader. Keep it on Neaten's CDN, so fixes reach your users without a redeploy. |
data-key | Your publishable key (pk_live_… or pk_test_…). It's public by design, like an analytics id. |
nonce | Your CSP nonce, if your policy uses one. The loader puts it on the scripts it adds. |
data-debug | Logs what Neaten decides to the browser console. ?neaten_debug=1 in the page address does the same. |
data-api, data-cdn | Other addresses for the API and the CDN. Only for self-hosting and local development. |
Call it by pushing commands. This works before and after the script has loaded, in the order you push them:
(window.neaten = window.neaten || []).push(["identify", user.id, { plan: user.plan }]);
Once it has loaded, window.neaten also has each method (neaten.track("invoice_sent")) and neaten.version. The push form is the safe one, because it doesn't depend on load order.
npm
npm install @neaten/sdk
import { identify, init, track } from "@neaten/sdk";
init({ key: "pk_live_…" });
identify(user.id, { plan: user.plan });
track("invoice_sent");
init adds the loader once (calling it again only updates the options). Every other function queues a command, so calls made before the loader arrives still run, in order. During server rendering every function does nothing. Exported types: InitOptions, NeatenEvent, TourEvent, Traits, TraitValue.
Methods
The same in both: identify(…) on npm is push(["identify", …]) with the script tag, and so on.
| Method | What it does |
|---|---|
init(options) | Starts Neaten. Options: key (required on npm; the script tag takes it from data-key), nonce, locale, consent (see Consent), onEvent, debug, and cdn and api for self-hosting. With the script tag, push init for the other options. |
identify(userId, traits?, { userHash }?) | Who is signed in. userId is a string of up to 200 characters; anything else is ignored. Traits (plan, role, locale and the like) decide who a tour is for and stay in the browser: they're never sent to Neaten. Call it again when the person changes. What someone saw before signing in carries over to their own record. userHash is for identity verification. |
track(name, props?) | Something happened in your app (a name of up to 100 characters). It moves on a step that waits for that event, can start a tour that starts on it, and counts a tour's goal. props is accepted, but not used or sent today. |
startTour(id, { force }?) | Starts a published tour now, by its id, and closes any tour that's showing. It still checks the tour's own conditions (its page, who it's for, how often it shows, and any event or element it waits for); force: true skips them. Tours set to start only this way (trigger.manualOnly) start here. A call made before the tours have loaded does nothing, so call it from something the person does, like a Help button. The npm type also takes step, which the loader doesn't use yet. |
endTour() | Closes the tour that's showing, if any. |
on(event, callback) | Listens to tours: tour:start, step:view, tour:complete, tour:dismiss, tour:snooze, target:missing, target:healed, error, and identify. The callback gets { tourId, stepId, stepIndex, … }, with preview: true during a preview from the dashboard. On npm it returns a function that stops listening; its TourEvent type names six of these (start, view, complete, dismiss, missing, error). |
onEvent(callback) | Every analytics event, for forwarding to your own analytics. Each has e (the event: tour:start, step:view, tour:complete, tour:dismiss, tour:snooze, target:missing, target:healed, tour:exposure, goal or error), tour, rev, step, idx, arm (in a measured tour), path (without the query string), locale, u (the user id, or an anonymous id), ts and sometimes d (details). It runs whatever the consent setting. On npm it returns a function that stops listening. |
setLocale(locale) | Shows tours in this language when they have it. Otherwise Neaten uses the locale trait, then <html lang>, then the browser's language. |
setConsent({ analytics, storage }) | What the person agreed to (see Consent). |
reset() | The person signed out: closes any tour and forgets their id and traits on this page. What this browser has stored stays. |
page() | The page changed. Neaten notices address changes by itself (the History and Navigation APIs), so most apps never need this. |
Consent and consent tools (CMPs)
Neaten sets no cookies. Two things it does may need consent where you operate: storage, a small record in localStorage (keys starting neaten:) so a finished tour stays finished on the next visit, and analytics, tour events sent to Neaten (POST /e), which feed Insights, Health and repairs.
By default both are on ("granted"). To wait for your consent tool, start with consent: "pending" ("denied" behaves the same until you call setConsent). Then nothing is written to localStorage and no events are sent. Tours still show, and progress is kept in memory for the page.
// npm
init({ key: "pk_live_…", consent: "pending" });
// Script tag: push this before the Neaten tag runs (in a script above it, or code that runs earlier)
(window.neaten = window.neaten || []).push(["init", { consent: "pending" }]);
When your consent tool reports a decision, and whenever it changes, pass it on. A value you leave out counts as no:
(window.neaten = window.neaten || []).push(["setConsent", { storage: true, analytics: false }]);
Which of your tool's categories each one belongs to is your decision. Turning analytics off drops events not sent yet; turning storage on keeps progress from then on. Use setConsent for every change after the first page load: init only sets the starting value.
Without consent, a few things still happen:
- Tours show, and
onandonEventcallbacks run. If you forward events to your own analytics withonEvent, check consent there too. - For a signed-in person, when how often a tour shows depends on what they did on other devices, the loader reads their progress from Neaten (
GET /s, with their user id). Nothing is written there without analytics consent. - A page the dashboard's install check opened (
?neaten_verify=…) reports in once. The daily install heartbeat is skipped without storage consent.
The workspace setting consentDefault (settings schema) can set the starting value too, but the dashboard has no control for it yet, so set consent in code. What Neaten stores and sends, for your privacy notice: Storage and consent.