Skip to content

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): void

Starts the SDK. Call it once per page load, before any other call. A second call is ignored.

OptionTypeDefaultDescription
endpointstringrequiredFull URL of the ingest endpoint: https://INGEST_HOST/v1/batch
flushAtnumber20Send when this many events are queued
flushIntervalMsnumber5000Send at least this often while events are queued
autoPageviewsbooleanfalseSend page_view on load and on route changes. See Single-page apps.
requireConsentbooleanfalseStore and send nothing until consent(true). See Consent and privacy.
debugbooleanfalseLog to the console. See Troubleshooting.

track ​

ts
vectelle.track(name: string, properties?: object): string | undefined

Records 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 | undefined

Records a page_view. Same as track('page_view', properties).

identify ​

ts
vectelle.identify(userId: string): void

Links 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(): void

Forgets 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): void

Adds or removes properties attached to every later event. They're kept across page loads. Up to 50 keys, with scalar values only.

ts
vectelle.consent(granted: boolean): void

true 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): void

Turns 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.