Skip to main content
Version: Svelte SDK

Identity

Set identity via provider configโ€‹

If the user is already authenticated when the app loads, pass userId directly in the provider config:

<script lang="ts">
import { setScreebContext } from "@screeb/sdk-svelte";

setScreebContext({
websiteId: "<YOUR-CHANNEL-ID>",
autoInit: true,
userId: "<USER-ID>",
userProperties: {
firstname: "<user-firstname>",
lastname: "<user-lastname>",
plan: "<user-plan>",
last_seen_at: new Date(),
authenticated: true,
},
});
</script>
info

The userId parameter should be your unique user identifier (user id, internal id, uuid, email, ...).

Change identityโ€‹

Change the current user identity after initialization. Running surveys will be closed.

<script lang="ts">
import { useScreeb } from "@screeb/sdk-svelte";

const { identity } = useScreeb();

async function onLogin(userId: string) {
await identity(userId, {
firstname: "<user-firstname>",
lastname: "<user-lastname>",
plan: "<user-plan>",
last_seen_at: new Date(),
authenticated: true,
});
}
</script>

Reset identity (logout)โ€‹

<script lang="ts">
import { useScreeb } from "@screeb/sdk-svelte";

const { identityReset } = useScreeb();

async function onLogout() {
await identityReset();
}
</script>

Update user propertiesโ€‹

<script lang="ts">
import { useScreeb } from "@screeb/sdk-svelte";

const { identityProperties } = useScreeb();

// Add or update properties
await identityProperties({
plan: "growth",
signed_up_at: new Date(),
authenticated: true,
});

// Remove a property by setting it to null
await identityProperties({
legacy_field: null,
});
</script>

Get current identityโ€‹

<script lang="ts">
import { onMount } from "svelte";
import { useScreeb } from "@screeb/sdk-svelte";

const { identityGet } = useScreeb();

onMount(async () => {
const id = await identityGet();
console.log(id);
// {
// anonymous_id: "<UUID>",
// user_id: "<UUID>",
// session_id: "<UUID>",
// session_start: "2023-05-04T16:30:15.882Z",
// session_end: "2023-05-04T17:02:09.087Z",
// channel_id: "<UUID>",
// is_ready: true,
// }
});
</script>

Property typesโ€‹

TypeSupported values
stringAny UTF-8 string, max 255 characters
numberInteger or float
booleantrue or false
DateJavaScript Date object
nullRemoves the property

Property names must be 128 characters or less. No more than 1000 attributes per user.

Good practices with an existing CDPโ€‹

When Amplitude, Segment or RudderStack is a Screeb source, Screeb resolves the respondent of each forwarded event from its user id, or from its anonymous id when the visitor is not logged in. Once both ids appear on the same event, Screeb aliases them to one respondent, so a visitor who logs in keeps a single profile. Screeb never moves an id from one respondent to another, and it does not read your CDP's identifiers from your app: keeping the two tools on the same identifiers is part of your instrumentation. Three rules do it.

1. One user id, the same string everywhereโ€‹

Identify the user in Screeb with exactly the value you give your CDP's identify: a stable internal id rather than an email, which can change. Do it in the same place in your code so neither tool lags behind the other.

const { identity } = useScreeb();
await identity(userId);

Amplitude drops user ids and device ids shorter than 5 characters, and the event then reaches Screeb as anonymous: use ids of 5 characters or more.

2. Tell Screeb which anonymous id your CDP usesโ€‹

Before login, CDP events carry only the CDP's own anonymous id (Amplitude device_id, Segment and RudderStack anonymousId). Give that id to Screeb: the current respondent adopts it, and stays anonymous. When the CDP webhook already created a respondent for that id, Screeb switches to it, so the events it already received are not lost. An identified respondent is never switched away from: the id then stays with its owner. If that switches the respondent, any survey it has running closes, as with identityReset(). Load order does not matter (call setAnonymousId after init).

const { setAnonymousId } = useScreeb();
setAnonymousId(amplitude.getDeviceId());

Call it right after init: Screeb resolves the id before creating any respondent, so the two consecutive calls behave like an init option.

The id must be 5 to 128 characters. Calling it again with the same id does nothing. Nothing changes in your CDP installation: Screeb never writes to it, and other tools wired to your CDP are not affected.

Do not pass the CDP anonymous id to identity: that turns it into a user identity, and the real login then creates a second respondent instead of merging.

If you cannot read the CDP anonymous id client side, the reverse also works: give your CDP the Screeb anonymous id (identityGet โ†’ amplitude.setDeviceId / setAnonymousId) before the CDP sends its first event. Prefer the recipe above: changing your CDP's device id also changes it for every other tool connected to that CDP.

3. Reset both tools together on logoutโ€‹

Reset Screeb, reset your CDP, then give Screeb the CDP's new anonymous id. Reset once, on logout only: resetting on every anonymous screen creates a new respondent each time on both sides.

const { identityReset, setAnonymousId } = useScreeb();
await identityReset();
amplitude.reset();
setAnonymousId(amplitude.getDeviceId());

What the "ignore anonymous users" settings changeโ€‹

The integration's "ignore events from anonymous users" option and the workspace-level "Ignore anonymous users" setting drop CDP events that carry no user id. Rule 2 needs both off: the workspace setting refuses setAnonymousId with anonymous_user_not_allowed. An event carrying a user id is never dropped by them, so the login-time merge happens either way.

Check it worksโ€‹

Read the current identity and compare anonymous_id and user_id with what your CDP reports for the same visitor. In Screeb, the respondent page lists the CDP anonymous id among its aliases while the respondent is still marked anonymous, and a survey targeted on a CDP event displays a few seconds after the event.