Skip to main content
Digia as CEPChange your setup in the sidebar

Step 4: Identify users

Call setUserId and setUserAttributes after login and clear them on logout, so Digia Engage targets campaigns at the right user.

Tell Digia who the user is after login, and clear it on logout.

Set the user​

Call setUserId after login. Pass the user hash too if you turned on user verification. Call setUserAttributes for anything your campaigns should target, such as city or plan.

// After login
Digia.setUserId('user-123', { userHash });
Digia.setUserAttributes({ city: 'Pune', plan: 'gold' });

// On logout
Digia.clearUserId();
  • The user ID is remembered across launches. Set it once after login.
  • Attributes add up. Each call adds to what is already set.
  • Attribute values can be text, numbers, true/false, or a list of text.
  • clearUserId clears the user and their attributes. Also clear any inline content you kept. See Managing Inline Content.

Verify your users​

Your app's API key ships inside the app, so anyone can claim to be any user ID. User verification fixes that. Your server signs the user ID with a secret. The app sends the result, the user hash, with setUserId. Digia checks it.

Gamification needs a user ID. When verification is on, it needs the hash too. Turn verification on for any project that gives out rewards.

Turn it on​

  1. In the dashboard, open Project settings → User verification.
  2. Choose Set up, then Copy.
  3. Keep the secret on your server. Never put it in the app.

Compute the hash on your server​

The hash is the HMAC-SHA256 of the user ID, with the secret as the key, as lowercase hex. Use the user ID exactly as you pass it to setUserId. Send the hash to the app, for example in your login response.

import { createHmac } from 'node:crypto';

const userHash = createHmac('sha256', process.env.DIGIA_USER_SECRET)
.update(userId)
.digest('hex');