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โ
| Type | Supported values |
|---|---|
string | Any UTF-8 string, max 255 characters |
number | Integer or float |
boolean | true or false |
Date | JavaScript Date object |
null | Removes the property |
Property names must be 128 characters or less. No more than 1000 attributes per user.