Tracking Users
This section demonstrates how to identify users of your application or game to Metrix and manage their profile information. Correct user identification is essential for fully utilizing Automation features and conducting accurate analyses in Metrix.
1. Identifying Users to Metrix and Creating a User Profile
For Metrix to identify users of your application and attribute received actions (events) to the correct user profile, you must send a unique identifier for each user. This ID creates a User Profile on Metrix’s servers, which is accessible in the User Lookup section of the Metrix dashboard.
- When to Call: You should call this method when a user is known in your system (e.g., after login or registration).
- ID Type: The
userIdshould be a unique and persistent identifier for the user within your system (e.g., your internal database User ID).
Metrix.SetUserCustomId("YOUR_USER_ID"); // Call when a user logs in or registers in your system. Replace "YOUR_USER_ID" with your actual user's unique ID.- User Logout:
When a user logs out from your system, you can disconnect the
Custom IDfrom the user’s current session in the SDK by calling the following method. This helps Metrix correctly differentiate between anonymous and identified user sessions.
Metrix.DeleteUserCustomId(); // Call when your user logs out from your system.2. Updating User Information (User Attributes)
You can update existing user information and attributes in User Lookup using the methods below. These attributes are crucial for accurate Segmentation of users and sending personalized messages via the Automation service.
2.1. Adding Custom Attributes
You can add your own custom attributes to a user’s profile using a Dictionary. These attributes can be of type string, int, double, bool, or DateTime.
var attributes = new Dictionary<string, object>();
attributes.Add("manufacturer", "Nike"); // String attribute
attributes.Add("registration_date", "2024-11-20T11:24:03.000Z"); // Date attribute: use ISO 8601 format to be recognized as a date
attributes.Add("loyalty_level", "Gold"); // Another string attribute
attributes.Add("total_purchases", 15); // Integer attribute
attributes.Add("is_premium", true); // Boolean attribute
Metrix.AddUserAttributes(attributes);Note on registration_date: For Metrix to recognize an attribute as a date, it must be sent in ISO 8601 format (e.g., "YYYY-MM-DDTHH:mm:ss.sssZ") and as a String type.
2.2. Adding Predefined Attributes
Metrix provides a set of specific functions for adding common user attributes. Using these functions helps standardize data and improve analysis:
Metrix.SetUserFirstName("UserFirstName");
Metrix.SetUserLastName("UserLastName");
Metrix.SetUserPhoneNumber("09121122333");
Metrix.SetUserHashedPhoneNumber("hashedValueOfThePhoneNumber"); // Use for privacy concerns
Metrix.SetUserEmail("user@example.com");
Metrix.SetUserHashedEmail("hashedValueOfTheEmail"); // Use for privacy concerns
Metrix.SetUserCountry("Iran");
Metrix.SetUserCity("Tehran");
Metrix.SetUserRegion("Tehran Province");
Metrix.SetUserLocality("Vanak");
Metrix.SetUserGender("MALE"); // Use: MALE, FEMALE, OTHER
Metrix.SetUserBirthday(1554321000000L); // Birthday value should be a Unix timestamp in **milliseconds** (Long)Additional Notes:
- Hashed Fields (
HashedPhoneNumber,HashedEmail): These fields are used for scenarios where, due to privacy considerations, you cannot send direct user information (phone number or email). In such cases, Metrix cannot directly use these hashed values for sending communications like email or SMS. SetUserBirthday: Thebirthdayvalue should be a Unix timestamp in milliseconds (of typeLong).
Note: Each User Profile can have a maximum of 50 attributes (including standard and custom attributes), with a maximum key and value length of 512 bytes for each attribute.