Skip to content

Install with npm ​

If your site is built with a bundler, you can import the SDK instead of using the loader snippet. The API is the same.

bash
npm install @vectelle/sdk
js
import { vectelle } from '@vectelle/sdk'

vectelle.init('pk_live_REPLACE_ME', { endpoint: 'https://INGEST_HOST/v1/batch' })

vectelle.track('item_viewed', { item_id: 'vid_88' })

vectelle is a ready-made instance. Call init() once, as early as possible in your app's startup, before any track() call.

Browser only

The SDK uses window, document and localStorage. In server-rendered frameworks (Next.js, Nuxt, SvelteKit), call init() and track() only in code that runs in the browser, for example inside useEffect or onMounted. To send events from server code, use the HTTP API instead.

Differences from the snippet ​

  • track() returns the event id. With the snippet, calls made before the SDK loads return undefined. With npm, track() always returns the event's id, which you can use to link related events. See Search.
  • The TypeScript types are included. InitOptions and VectellePlugin are exported.
ts
import { type InitOptions, vectelle } from '@vectelle/sdk'