Identity
Set identity via plugin config
If the user is already authenticated when the app loads, pass userId directly in the plugin config:
createApp(App)
.use(ScreebPlugin, {
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,
},
})
.mount("#app");
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 setup lang="ts">
import { useScreeb } from "@screeb/sdk-vue";
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 setup lang="ts">
import { useScreeb } from "@screeb/sdk-vue";
const { identityReset } = useScreeb();
async function onLogout() {
await identityReset();
}
</script>
Update user properties
<script setup lang="ts">
import { useScreeb } from "@screeb/sdk-vue";
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 setup lang="ts">
import { onMounted } from "vue";
import { useScreeb } from "@screeb/sdk-vue";
const { identityGet } = useScreeb();
onMounted(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.