Skip to main content
Version: React SDK

Identity

Initial identity via ScreebProviderโ€‹

Set the initial user identity when wrapping your app:

import { ScreebProvider } from "@screeb/sdk-react";

export const App = () => (
<ScreebProvider
autoInit
websiteId="<YOUR-CHANNEL-ID>"
userId="<USER-ID>"
userProperties={{
firstname: "<user-firstname>",
lastname: "<user-lastname>",
plan: "<user-plan>",
last_seen_at: new Date(),
authenticated: true,
}}
>
<YourApp />
</ScreebProvider>
);
info

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

Change identityโ€‹

Change the current user identity. Running surveys will be closed. Hooks will be triggered with new identity.

import { useScreeb } from "@screeb/sdk-react";

const MyComponent = () => {
const { identity } = useScreeb();

const handleLogin = async () => {
await identity(
"<USER-ID>",
{
firstname: "<user-firstname>",
lastname: "<user-lastname>",
plan: "<user-plan>",
last_seen_at: new Date(),
authenticated: true,
}
);
};
};
Requirements
  • Property names must be limited to 128 characters
  • No more than 1000 attributes
  • Supported types for values: string, number, boolean and Date.

Reset current identityโ€‹

Reset the current user identity. This command must be called only once, since it creates a new identity on Screeb side.

import { useScreeb } from "@screeb/sdk-react";

const MyComponent = () => {
const { identityReset } = useScreeb();

const handleLogout = async () => {
await identityReset();
};
};

Add properties to the current identityโ€‹

This command adds properties to the current user identity without resetting the identity.

To delete a user property, set it to null.

import { useScreeb } from "@screeb/sdk-react";

const MyComponent = () => {
const { identityProperties } = useScreeb();

const updateUserProperties = async () => {
// Set user properties
await identityProperties({
firstname: "<user-firstname>",
lastname: "<user-lastname>",
plan: "<user-plan>",
last_seen_at: new Date(),
authenticated: true,
});

// Delete user property: set values to null
await identityProperties({
age: null,
company: null,
logged: true,
});
};
};
Requirements
  • Property names must be limited to 128 characters
  • No more than 1000 attributes
  • Supported types for values: string, number, boolean and Date.

Get current identityโ€‹

Retrieves the current user identity.

import { useScreeb } from "@screeb/sdk-react";

const MyComponent = () => {
const { identityGet } = useScreeb();

const getUserInfo = async () => {
const user = await identityGet();
console.log(user);
// {
// 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,
// }
};
};