Appearance
SDK API
The same API is available on window.vectelle (loader snippet) and as vectelle from @vectelle/sdk (npm).
init
ts
vectelle.init(siteKey: string, options: InitOptions): voidStarts the SDK. Call it once per page load, before any other call. A second call is ignored.
| Option | Type | Default | Description |
|---|---|---|---|
endpoint | string | required | Full URL of the ingest endpoint: https://INGEST_HOST/v1/batch |
flushAt | number | 20 | Send when this many events are queued |
flushIntervalMs | number | 5000 | Send at least this often while events are queued |
autoPageviews | boolean | false | Send page_view on load and on route changes. See Single-page apps. |
requireConsent | boolean | false | Store and send nothing until consent(true). See Consent and privacy. |
debug | boolean | false | Log to the console. See Troubleshooting. |
track
ts
vectelle.track(name: string, properties?: object): string | undefinedRecords an event. Returns the event's id, or undefined if the event was dropped (invalid name, properties that can't be serialized, consent denied, or not initialized). With the loader snippet, calls made before the SDK loads also return undefined.
See Tracking events.
page
ts
vectelle.page(properties?: object): string | undefinedRecords a page_view. Same as track('page_view', properties).
identify
ts
vectelle.identify(userId: string): voidLinks this and later events to your user id. Call it on login. Ids longer than 256 characters are cut. See Identifying users.
reset
ts
vectelle.reset(): voidForgets the user id and registered properties, and starts a new anonymous id and session. Call it on logout.
register / unregister
ts
vectelle.register(properties: Record<string, string | number | boolean | null>): void
vectelle.unregister(key: string): voidAdds or removes properties attached to every later event. They're kept across page loads. Up to 50 keys, with scalar values only.
consent
ts
vectelle.consent(granted: boolean): voidtrue allows storing and sending, and sends anything queued. false clears the queue and everything stored, and stops tracking.
flush
ts
vectelle.flush(): Promise<void>Sends everything queued now. Safe to call any time. It resolves when the attempt finishes; events that failed stay queued for retry.
debug
ts
vectelle.debug(on?: boolean): voidTurns console logging on (default) or off.
What's stored on the device
Unless requireConsent is on and consent hasn't been given, the SDK keeps these in localStorage:
- an anonymous id and, after
identify(), the user id - the current session id and the time of the last activity
- properties set with
register() - events waiting to be sent, up to 1,000
The SDK sets no cookies, and its requests carry no credentials.