Merge behavioral and preferential data to create AI digital twins of your customers
In order to merge behavioral and preferential data to create AI digital twins of your customers, Rehearsals needs to identify individual users. This is the most guaranteed way to build accurate customer profiles and get a complete picture of how they’re using your product across different sessions, devices, and platforms.
While Rehearsals can also extract user information through visual events (automatically detecting emails and names in your UI), programmatically identifying users is the most efficient and consistent method.
When a user visits your website, Rehearsals automatically assigns them an anonymous session, which is stored locally. This enables us to track anonymous users even across different page visits.By calling identify() with a unique user ID from your system (usually from your database), you link all of that user’s sessions together.This enables you to:
Track a user’s behavior across multiple sessions
See what they did before they logged in for the first time
Associate their activity across different devices
Build comprehensive user profiles with behavioral insights
A Promise that resolves when the user is successfully identified. You typically don’t need to await this - it runs in the background without blocking your page.
// Simple usage (recommended)rehearsals.identify('user-123');// With email and full namerehearsals.identify('user-123', { email: 'user@example.com', fullName: 'John Doe'});// With just emailrehearsals.identify('user-123', { email: 'user@example.com'});// With await (if you need to know when it completes)await rehearsals.identify('user-123', { email: 'user@example.com', fullName: 'John Doe'});
1. Call identify() as soon as the user is authenticated
Call identify() immediately after a user logs in or when your app loads if the user is already authenticated:
Copy
Ask AI
// After login successasync function handleLogin(email, password) { const user = await loginUser(email, password); // Identify the user rehearsals.identify(user.id, { email: user.email, fullName: user.name });}// On app load (if user is already logged in)window.addEventListener('load', () => { const currentUser = getCurrentUser(); if (currentUser) { rehearsals.identify(currentUser.id, { email: currentUser.email, fullName: currentUser.name }); }});
You only need to call identify() once per session. If you call it multiple times with the same data, subsequent calls will update the user information if needed but won’t create duplicates.
// Run this on every page loadwindow.addEventListener('load', () => { const currentUser = JSON.parse(localStorage.getItem('currentUser')); if (currentUser && currentUser.id) { // User is logged in, identify them rehearsals.identify(currentUser.id, { email: currentUser.email, fullName: currentUser.name }); }});
// In your Vue app or routerexport default { mounted() { // Check if user is logged in const user = this.$store.state.user; if (user) { window.rehearsals.identify(user.id, { email: user.email, fullName: user.name }); } }, methods: { async logout() { await this.$store.dispatch('logout'); window.rehearsals.reset(); this.$router.push('/login'); } }}