Skip to main content
Version: Browser SDK

Examples

Practical, task-based code snippets for @screeb/sdk-browser.

import * as Screeb from "@screeb/sdk-browser";

Basic setup

If the user is already authenticated when the app loads, pass their identity directly to init() to avoid creating an anonymous user:

await Screeb.init("<YOUR-CHANNEL-ID>", "<USER-ID>", {
email: "support@screeb.app",
plan: "pro",
});

If the user isn't authenticated yet, initialize without identity and call identity() after login (see below).

await Screeb.init("<YOUR-CHANNEL-ID>");

Identify a user after login

Call when the user authenticates post-init.

await Screeb.identity("user-123", {
email: "support@screeb.app",
plan: "pro",
createdAt: new Date("2024-01-01"),
});

Track an event

await Screeb.trackEvent("checkout_completed", {
amount: 99.99,
currency: "USD",
});

Start a survey programmatically

// Default targeting rules
await Screeb.surveyStart();

// Specific survey
await Screeb.surveyStart({ surveyId: "<SURVEY-ID>" });

Use hooks

await Screeb.init("<YOUR-CHANNEL-ID>", {
hooks: {
onSurveyCompleted: ({ surveyId }) => {
console.log("Survey completed:", surveyId);
},
},
});

Reset on logout

Call when the user signs out to clear the identity.

await Screeb.identityReset();