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.
npm install @cosembra/sdkimport { 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.
Differences from the snippet
Section titled “Differences from the snippet”track()returns the event id. With the snippet, calls made before the SDK loads returnundefined. With npm,track()always returns the event’s id, which you can use to link related events. See Search.- The TypeScript types are included.
InitOptionsandCosembraPluginare exported.
import { type InitOptions, cosembra } from '@cosembra/sdk'