Skip to main content

Installation

Choose Integration Mode

Use one integration mode per client shell:

  • CDN mode (<script>): fastest rollout, minimal code changes, global API on window.Selwise.
  • npm mode (@selwise/widget): framework-controlled lifecycle, explicit init() and destroy().
  • React Native mode (@selwise/react-native): headless mobile SDK with API-key auth.

Prerequisites

  1. Active siteKey from Selwise dashboard.
  2. Correct API base URL ending with /api/v1.
  3. Domain verification for web or mobile public API key (x-selwise-api-key) for RN.

Install

<script
src="https://widget.selwise.com/client.js"
data-site-key="YOUR_SITE_KEY"
data-api-url="https://api.selwise.com/api/v1"
></script>

Notes:

data-api-url is optional.
API URL resolution order: NEXT_PUBLIC_API_URL -> data-api-url -> https://api.selwise.com/api/v1.
CDN mode auto-initializes and exposes window.Selwise.

First Runtime Check

Web

console.log(window.Selwise);
console.log(window.Selwise?.siteKey);
console.log(window.Selwise?.apiUrl);
console.log(window.Selwise?.getVisitorId?.());

React Native

console.log(sdk.getVisitorId());
console.log(sdk.getSessionId());
console.log(sdk.getJourneyId());

Environment Variables

NEXT_PUBLIC_SELWISE_SITE_KEY="sk_xxx"
NEXT_PUBLIC_SELWISE_API_URL="https://api.selwise.com/api/v1"
NEXT_PUBLIC_SELWISE_WIDGET_URL="https://widget.selwise.com/client.js"

Common Installation Problems

  1. window.Selwise is undefined.
  • CDN: wrong script URL or missing data-site-key.
  • npm: exposeGlobal is false by default.
  1. Mobile requests return auth errors.
  • missing or revoked x-selwise-api-key
  • missing mobile_read/mobile_write scope
  1. Events are not reaching backend.
  • consent state blocks event family
  • payload shape invalid for canonical event

Next