Examples
Practical, task-based code snippets for @screeb/sdk-angular.
Basic setupโ
If the user is already authenticated when the app loads, pass their identity directly in the provider config to avoid creating an anonymous user:
// app.config.ts (standalone)
import { provideScreeb } from "@screeb/sdk-angular";
export const appConfig: ApplicationConfig = {
providers: [
provideScreeb({
websiteId: "<YOUR-CHANNEL-ID>",
autoInit: true,
userId: "<USER-ID>",
userProperties: { email: "support@screeb.app", plan: "pro" },
}),
],
};
Screeb tracks WebView visibility automatically on iOS and Android via the Capacitor plugin. No extra config needed.
If the userId is not yet available at startup, omit it and call identity() after login (see below).
Identify a user after loginโ
import { Component, inject } from "@angular/core";
import { ScreebService } from "@screeb/sdk-angular";
@Component({ ... })
export class AuthComponent {
private screeb = inject(ScreebService);
async onLogin(user: User) {
await this.screeb.identity(user.id, {
email: user.email,
plan: user.plan,
});
}
}
Track an eventโ
await this.screeb.trackEvent("checkout_completed", {
amount: 99.99,
currency: "USD",
});
Start a survey programmaticallyโ
// Default targeting rules
await this.screeb.surveyStart("", {});
// Specific survey
await this.screeb.surveyStart("<SURVEY-ID>", {});
Use hooksโ
provideScreeb({
websiteId: "<YOUR-CHANNEL-ID>",
autoInit: true,
hooks: {
onSurveyCompleted: ({ surveyId }) => {
console.log("Survey completed:", surveyId);
},
},
})
Reset on logoutโ
await this.screeb.identityReset();