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:
Standalone (recommended)
// app.config.ts
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" },
}),
],
};
NgModule
// app.module.ts
import { ScreebModule } from "@screeb/sdk-angular";
@NgModule({
imports: [ScreebModule.forRoot({ websiteId: "<YOUR-CHANNEL-ID>", autoInit: true })],
})
export class AppModule {}
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
Pass hooks at init time via the provider config:
provideScreeb({
websiteId: "<YOUR-CHANNEL-ID>",
autoInit: true,
hooks: {
onSurveyCompleted: ({ surveyId }) => {
console.log("Survey completed:", surveyId);
},
},
})
Reset on logout
await this.screeb.identityReset();