Skip to main content

Overview

Trodo automatically assigns anonymous IDs to track users. When you know who a user is (for example after login or signup), use identify() to link their anonymous activity to their known identity.
Trodo’s CQ Intelligence merge engine automatically consolidates user profiles across sessions and devices when you call identify().

Trodo.identify()

Associate the current user with a unique identifier.
Trodo.identify(identifyId)

Parameters

identifyId
string
required
A unique identifier for the user. This could be:
  • User ID from your database (recommended)
  • Email address (if stable and unique in your system)
  • Any unique string that identifies this person or account
Maximum length: 255 characters

Returns

void

Basic Usage

// After user logs in
Trodo.identify('user_12345');

// Using email
Trodo.identify('[email protected]');


When to Call identify()

1

After Login

When a user logs into your application:
async function handleLogin(email, password) {
  const user = await login(email, password);
  
  // Identify after successful login
  Trodo.identify(user.id);
  
  // Optionally set user properties
  Trodo.people.set({
    email: user.email,
    plan: user.subscription,
    signupDate: user.createdAt
  });
}
2

After Signup

When a new user creates an account:
async function handleSignup(userData) {
  const newUser = await createUser(userData);
  
  // Identify the new user
  Trodo.identify(newUser.id);
  
  // Track signup event
  Trodo.track('Signup Completed', {
    source: userData.referralSource
  });
  
  // Set initial user properties
  Trodo.people.set({
    email: newUser.email,
    signupDate: new Date().toISOString()
  });
}
3

On Page Load (Returning Users)

When a logged-in user returns:
// On app initialization
async function initApp() {
  await Trodo.init({ siteId: 'your-site-id' });
  
  // If user is already logged in
  const currentUser = getCurrentUser();
  if (currentUser) {
    Trodo.identify(currentUser.id);
  }
}

Cross-Domain Identification

Trodo can merge user profiles across domains when you use the same identifyId:
// On app.example.com
Trodo.identify('user_12345');

// On dashboard.example.com (same user)
Trodo.identify('user_12345');

// Trodo merges all sessions for user_12345 automatically

Trodo.reset()

Clear the current user identity and start a new anonymous session. Use this when a user logs out.
Trodo.reset()

Returns

void

Usage

function handleLogout() {
  // Clear user session in your app
  logout();
  
  // Reset Trodo identity
  Trodo.reset();
  
  // Future events will use a new anonymous ID
}
Always call reset() when a user logs out. Without this, the next user on the same device could be associated with the previous user’s data.

Identity merge behavior

When you call identify():
  1. New User: If the identifyId hasn’t been seen before, the current anonymous profile is converted to an identified profile.
  2. Existing User, Same Device: If the identifyId matches a profile already on this device, sessions merge seamlessly.
  3. Existing User, New Device: If the identifyId exists from another device, Trodo’s CQ Intelligence merges the profiles automatically.
  4. Group memberships: When the server returns group_memberships for this user, the SDK restores them locally so group assignments stay in sync across devices.

Best Practices

Use Persistent IDs

// Good - Stable, unique identifiers
Trodo.identify(user.databaseId);    // e.g. '12345'
Trodo.identify(user.uuid);          // e.g. 'a1b2c3d4-e5f6-...'

// Avoid - IDs that might change
Trodo.identify(user.username);      // User might change this
Trodo.identify(user.displayName);   // Not unique

Don’t Over-Identify

// Bad - Calling identify too frequently
function onClick() {
  Trodo.identify(userId);  // Don't identify on every action
  Trodo.track('Button Clicked');
}

// Good - Identify once per session
async function initApp() {
  await Trodo.init({ siteId: 'your-site-id' });
  
  if (currentUser) {
    Trodo.identify(currentUser.id);
  }
}

Handle Auth State Changes

// React example with auth state listener
useEffect(() => {
  const unsubscribe = auth.onAuthStateChanged((user) => {
    if (user) {
      Trodo.identify(user.uid);
    } else {
      Trodo.reset();
    }
  });
  
  return () => unsubscribe();
}, []);

Complete Authentication Flow

// Initialize
await Trodo.init({ siteId: 'your-site-id' });

// Check for existing session
const user = getCurrentUser();
if (user) {
  Trodo.identify(user.id);
  Trodo.people.set({
    email: user.email,
    lastSeen: new Date().toISOString()
  });
}

// Login handler
async function login(credentials) {
  const user = await authService.login(credentials);
  
  Trodo.identify(user.id);
  Trodo.people.set({
    email: user.email,
    lastLogin: new Date().toISOString()
  });
  Trodo.track('Login Completed');
}

// Logout handler
function logout() {
  Trodo.track('Logout Completed');
  Trodo.reset();
  authService.logout();
}

User Properties

Set persistent user attributes

Groups

Company and team associations