Tracking User Attributes
campaign

Notice

Microsoft is replacing Xamarin with .NET MAUI and the support for the latest release of Xamarin is till November 2023. MoEngage will stop providing updates for the MoEngage Xamarin SDK due to the deprecation. Deprecation impacts Xamarin In-App Messaging and will stop working after June 2022. All other features will continue to work in the Xamarin SDK until November 2023.

User attributes are specific traits of a user, like an email, username, mobile, gender, etc.
This is crucial and helps in targeting users based on these attributes across devices or installs.

Implementing Login / Logout Mechanism for a User

Setting Unique ID in order to Login User :

  • It's important to set the unique identifier when a user logs into your app. This is to unify the new user with an existing user, if any exists, and will help prevent creating unnecessary/stale users.
  • Setting the Unique ID is a critical piece to tie a user across devices and installs/uninstalls as well across all platforms (i.e. iOS, Android, Windows, The Web). Set the attribute as soon as the user is logged in. A unique Identifier can be something like an email ID, a username (unique), or a database ID or any Backend generated identifier which can be used to uniquely identify the user.
  • Do not set this for the user who not logged in.
C#
MoEXamarin.Current.SetUniqueId();

Note: The following values are not allowed in the UniqueID field: "unknown", "guest", "null", "0", "1", "true", "false", "user_attribute_unique_id", "(empty)", "na", "n/a", "", "dummy_seller_code", "user_id", "id", "customer_id", "uid", "userid", "none", "-2", "-1", "2"

Notifying the SDK when the user log's out of the app

C#
MoEXamarin.Current.Logout();

Updating Unique Identifier

In a scenario where you have to update the Unique Identifier value for an already logged-in user use SetAlias()

C#
MoEXamarin.Current.SetAlias();
warning

Note

Please make sure that you use SetAlias() for updating the Unique Identifier and not SetUniqueId() as calling SetUniqueId() with a new value will reset the current user and lead to the creation of unintended users in our system.

Tracking User Attributes

To track user attributes line First Name, Last Name, email, phone number, etc use the below APIs

C#
MoEXamarin.Current.SetFirstName();
MoEXamarin.Current.SetLastName();
MoEXamarin.Current.SetEmail();
MoEXamarin.Current.SetUniqueId();
MoEXamarin.Current.SetPhoneNumber();
MoEXamarin.Current.SetGender();

For setting other User Attributes you can use the generic method SetUserAttribute(key,value)

C#
MoEXamarin.Current.SetUserAttribute();

Tracking Date as user attributes

To track any date as user attributes use the MoEXamarin.Current.SetUserAttributeISODate(). This API takes attribute name and ISO Date as input.
Date Format - yyyy-MM-dd'T'HH:mm:ss.fff'Z'
Example:

C#
MoEXamarin.Current.SetUserAttributeISODate("userAttrDate", "2019-01-02T08:26:21.170Z");
Was this article helpful?
0 out of 0 found this helpful

How can we improve this article?