Step 4: Identify users
Set the user ID and attributes in Digia Engage after login and clear them on logout, so MoEngage campaigns reach the right user.
Call this right after you identify the user in MoEngage.
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.
- React Native
- Android
- iOS (Swift)
- Flutter
// After login
Digia.setUserId('user-123', { userHash });
Digia.setUserAttributes({ city: 'Pune', plan: 'gold' });
// On logout
Digia.clearUserId();
// After login
Digia.setUserId("user-123", userHash = userHash)
Digia.setUserAttributes(mapOf("city" to "Pune", "plan" to "gold"))
// On logout
Digia.clearUserId()
// After login
Digia.setUserId("user-123", userHash: userHash)
Digia.setUserAttributes(["city": "Pune", "plan": "gold"])
// On logout
Digia.clearUserId()
// After login
await Digia.setUserId('user-123', userHash: userHash);
await Digia.setUserAttributes({'city': 'Pune', 'plan': 'gold'});
// On logout
await 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.
clearUserIdclears 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
- In the dashboard, open Project settings → User verification.
- Choose Set up, then Copy.
- 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.
- Node.js
- Python
import { createHmac } from 'node:crypto';
const userHash = createHmac('sha256', process.env.DIGIA_USER_SECRET)
.update(userId)
.digest('hex');
import hashlib
import hmac
import os
user_hash = hmac.new(
os.environ["DIGIA_USER_SECRET"].encode(),
user_id.encode(),
hashlib.sha256,
).hexdigest()