/optimove-websdk

Optimove WebSDK for humans

Primary LanguageTypeScript

optimove-websdk

Optimove WebSDK for humans

npm min.gz size code style: prettier

Why

Because Optimove is complicated™

Features

  • Promisified API
  • Reasonable defaults
  • Typescript types built-in
  • Bundled, so e.g. ad-blockers won't block it just by url name
  • Loads config with hard-coded https:// schema, which allows it to work under e.g ionic://, capacitor://, file://, etc schemas
  • Allows to not care about optimoveSDK.initialize, since it's called lazily on first usage.
  • Allows to (hopefully) not care about "is it loaded yet?" problem
  • Zero dependencies (1 small tree-shakeable dependency), exports ESM / 🌲-shakeable
  • Automatically handles snakeToCamel, camelToSnake case conversions when reporting events and custom properties

Usage

import { OptimoveWebSK } from 'optimove-websdk'

const sdk = new OptimoveWebSDK({
  tenantToken: 'lalala',
  configVersion: '1.0.0',
})

// Will lazily initialize SDK on the first call (hence the `await`)
await sdk.registerUser('someCustomerId', 'some@email.com')

// Skip await freely, if it's more convenient
void sdk.registerUser('someCustomerId', 'some@email.com')

// Low-level API is available via `window.optimoveSDK` too (Window interface is augmented with its types already)
window.optimoveSDK.API.registerUser('someCustomerId', 'some@email.com')