User Identification
Associate telemetry with specific users to track user behavior and debug user-specific issues.
Set User ID
// Set user ID
PulseSDK.INSTANCE.setUserId("user-12345")
// Clear user ID
PulseSDK.INSTANCE.setUserId(null)
Set User Properties
Individual Properties
PulseSDK.INSTANCE.setUserProperty("email", "user@example.com")
PulseSDK.INSTANCE.setUserProperty("subscription", "premium")
Multiple Properties
Set multiple user properties at once:
PulseSDK.INSTANCE.setUserProperties {
put("name", "John Doe")
put("age", 30)
put("verified", true)
}
Complete Example
// After user login
fun handleLogin(user: User) {
PulseSDK.INSTANCE.setUserId(user.id)
PulseSDK.INSTANCE.setUserProperties {
put("email", user.email)
put("subscription", user.subscription)
put("verified", user.isVerified)
}
}
// On logout
fun handleLogout() {
PulseSDK.INSTANCE.setUserId(null)
}
Best Practices
- Set user context immediately after authentication - This ensures all subsequent telemetry is associated with the user
- Clear user on logout - Set user ID to
nullwhen the user logs out - Include relevant user metadata - Add properties that help you understand user segments and behavior
Example:
// After user login
fun handleLogin(user: User) {
// Set user context immediately
PulseSDK.INSTANCE.setUserId(user.id)
PulseSDK.INSTANCE.setUserProperties {
put("email", user.email)
put("subscription", user.subscription)
put("verified", user.isVerified)
}
}
Next Steps
- Learn about Global Attributes
- Explore Custom Event Instrumentation
- Check out Custom Span Instrumentation