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.

Terminal window
npm install @cosembra/sdk
import { cosembra } from '@cosembra/sdk'
cosembra.init('pk_live_REPLACE_ME', { endpoint: 'https://events.cosembra.com/v1/batch' })
cosembra.track('item_viewed', { item_id: 'vid_88' })

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

  • 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 CosembraPlugin are exported.
import { type InitOptions, cosembra } from '@cosembra/sdk'