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.
After a user logs in or signs up, call identify() to link their sessions to their user profile
Copy
Ask AI
// After user authenticatesrehearsals.identify('[email protected]');
We also allow custom parameters to be injected with {} . By default, we allow an identifier, email and fullName, to add additional properties see NEW SECTION, the code you write would look like this:
Copy
Ask AI
// After user authenticatesrehearsals.identify('user-123', { email: '[email protected]', fullName: 'John Doe', customAttribute: 1234});
When a user logs out, call reset() to start a fresh anonymous session:
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('[email protected]');// With custom attributesrehearsals.identify('user-123', { email: '[email protected]', fullName: 'John Doe', customAttribute: 1234});// With await (if you need to know when it completes)await rehearsals.identify('[email protected]');
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.email);}// On app load (if user is already logged in)window.addEventListener('load', () => { const currentUser = getCurrentUser(); if (currentUser) { rehearsals.identify(currentUser.email); }});
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 load, but remember to manage your localStoragewindow.addEventListener('load', () => { const currentUser = JSON.parse(localStorage.getItem('currentUser')); if (currentUser && currentUser.id) { // User is logged in, identify them rehearsals.identify(currentUser.email); }});
You can create custom attributes that will apear and be filterable in your sessions table by leveraging our Identify() API. To get started, head to the sessions table and hit the + in the top right header of the table, and hit Programmatic API :
This allows you to create:
a name that will display in your sessions table and be filterable
a machine_readable_name that you can customize and is what you will use if passing in a custom property to the Identify API’s optional {} param. So if you add a custom number attribute with the machine readable name: exampleCustomAttribute, you would call the api with:
Copy
Ask AI
// After user authenticatesrehearsals.identify('[email protected]', { exampleCustomAttribute: 1234});
// 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.email); } }, methods: { async logout() { await this.$store.dispatch('logout'); window.rehearsals.reset(); this.$router.push('/login'); } }}
// In your main JavaScript file(function() { // Check for logged-in user on page load const user = getCurrentUserFromYourSystem(); if (user) { rehearsals.identify(user.email); } // Add logout handler document.getElementById('logout-button')?.addEventListener('click', async () => { await logoutUser(); rehearsals.reset(); window.location.href = '/login'; });})();