Tracking User
Smartech SDK enables developers to identify a user and create a profile for the user with all its attributes. Assigning a unique user identity helps collect the user's activity and information across systems in a single unified view.
Important
- Unique user identity must be your primary key set on the Smartech Panel to identify users in your database.
- We recommend not to use any user identity that can change over time.
Normally you can set the user identity in the following flow of your app:
- On user sign-in/login success.
- On user sign-up/register success.
- On screen or page where user identity becomes known.
- When the user context changes (apps with multiple accounts).
User Profile
You can pass additional information associated with a user to Smartech as user attributes. These attributes can be used to segment users and target campaigns to a specific group. Attributes can also be used to personalize the campaigns for each user.
NetcoreSDK.profile(context, USER_PROFILE_DETIAL_PAYLOAD);
// Sample code for reference purpose only
JSONObject UserProfile = new JSONObject();
try {
UserProfile.put("NAME", "Ram");
UserProfile.put("AGE", 25);
UserProfile.put("MOBILE", "9876543210");
NetcoreSDK.profile(this, UserProfile);
}
catch (JSONException e) {
e.printStackTrace();
}
Important:
- Smartech supports following data types - String, Integer, Float, Date, Array, Objects.
- Bool/Boolean data type in the payload is NOT supported by Smartech.
- Date should be sent as yyyy-mm-dd format
Identifying users
Use the below method to set a user’s identity. In case the user’s identity is not available at the time of login, you can also use this method after the availability of identity. Once you set this identity, all corresponding events will be mapped to this identified user. Following method is used to set the Identity of the user.
Please ensure that the user identity that you pass here is the primary key which is set in the Smartech Panel.
NetcoreSDK.setIdentity(context, "USER'S_IDENTITY");
Login Event
Call Smartech login
method as soon as the user successfully logs in to the app and also please ensure that you set user’s identity before calling this login method of SDK.
NetcoreSDK.setIdentity(context, "USER'S_IDENTITY");
NetcoreSDK.login(context);
Note
In addition to calling these methods after a successful login and sign-up, it is recommended to call setIdentity() and login() methods where the app finds the user is already logged in and navigates the user to the homepage.
Clear Identity
To clear the user's identity you need to explicitly call clearIdentity()
method. This method clears the identity and further all the events carried out after this call will be treated as Anonymous users activity.
NetcoreSDK.clearIdentity(context);
Logout Event
To track log out of the user via Smartech, ensure you call the logout method on successfully logging out the user. When you logout the user, user won't receive any personalised push notifications.
NetcoreSDK.logout(context);
NetcoreSDK.clearIdentity(context);
Important
Avoid calling
clearIdentity()
method if you want to track user activity against its identity even if the user has logged out of the application
Updated about 4 years ago