Create User Profile
This document will cover the methods to create a user and set communication channel preferences along with push notification token
Pre-requisites
How Suprsend identifies a user
Suprsend identifies Users by unique identifier distinct_id
. The identifier for a user is important as we use this key to create user profile and all the information related to a user, like channel preferences, is attached to that profile. It's best to send the user's distinct_id
from your DB to map it across different devices and platforms. You can view user profile by searching distinct_id
on Subscribers page
Please note: you cannot change a user's id once it has been set, so we recommend you use a non-transient id like a primary key rather than a phone number or email address.
Step 1 : Create/Identify a new user
You can identify a user using suprsend.identify()
method.
Call this method as soon as you know the identity of user, that is after login authentication. If you don't call this method, user will be identified using distinct_id (uuid) that sdk generates internally.
When you call this method, we internally create an event called $user_login. You can see this event on SuprSend workflows event list and you can configure a workflow on it.
suprsend.identify(distinct_id);
//Sample Values
suprsend.identify("291eaa13-62f5-4d52-b2dd");
suprsend.identify("[email protected]");
Parameters | Type | Description |
---|---|---|
distinct_id | int, bigint, string, UUID | mandatory Unique identifier for a user across devices or between multiple logins. |
Step 2 : Call reset to clear user data on log out
As soon as the user logs out, call suprsend.reset()
method to clear data attributed to a user. This will generate a new random distinct_id
and clear all super properties. This allows you to handle multiple users on a single device.
When you call this method, we internally create an event called $user_logout. You can see this event on SuprSend workflows event list and you can configure a workflow on it.
suprsend.reset();
Mandatory to call reset on logout
Don't forget to call reset on user logout. If not called, user id will not reset and multiple tokens and channels will get added to the user_id who logged in first on the device.
Step 3: Set Communication Channel preferences
You can send communication channel details of a user to the SuprSend SDK. We will store the channel details in the user profile. This will allow us to send communications to a user on the channels available for that user whenever there is any communication trigger.
1. Add User Channels
You can add SMS, Email and Whatsapp channel information by using below methods. You can call this on signup, or whenever a user provides the above channel information.
suprsend.user.setEmail("[email protected]"); // To add Email
suprsend.user.setSms("+91XXXXXXXXXX"); // To add SMS
suprsend.user.setWhatsApp("+91XXXXXXXXXX"); // To add Whatsapp
Android Push and iOS Push token will automatically be set at the time of user login. All you have to do is to integrate the push notification service in your application
Android Push Integration guide
Country Code Mandatory
Make sure you are sending the country code when you are calling communication methods for SMS and Whatsapp.
2. Remove User Channels
You can remove SMS, Email and Whatsapp channel information by using below methods. You can call this when a user updates his channel information. You need not call this when a user unsubscribes from a particular channel notification, as that will be handled in user preferences.
suprsend.user.unSetEmail("[email protected]"); // To remove Email
suprsend.user.unSetSms("+91XXXXXXXXXX"); // To remove SMS
suprsend.user.unSetWhatsApp("+91XXXXXXXXXX"); // To remove Whatsapp
Advanced Configuration - Set User Properties
(currently not available in iOS SDK)
You can use SuprSend SDK to set advanced user properties, which will help in creating a user profile. You can use these properties to create user cohorts on SuprSend's platform with future releases.
1. Set
Set is used to set the custom user property or properties. The given name and value will be assigned to the user, overwriting an existing property with the same name if present. It can take key as first param, value as second param for setting single user property or object for setting multiple user properties.
suprsend.user.set(key, value); // for single property
suprsend.user.set(property_obj); // for multiple properties
// Sample values for setting single property:
suprsend.user.set("name", "john doe");
// Sample values for setting multiple properties:
suprsend.user.set({"name" : "john doe", "age" : "27"});
Parameters | Type | Description |
---|---|---|
key | string | Mandatory This is property key that will be attached to user. Should not start with $ or ss_ |
value | any | Optional This will be value that will be attached to key property. |
JSONObject | object | Optional This is used in case of setting multiple user properties. |
Naming Guidelines
When you create a key, please ensure that the Key Name does not start with
$
orss_
, as we have reserved these symbols for our internal events and property names.
2. Set Once
Works just like user.set
, except it will not overwrite existing property values. This is useful for properties like First login date
suprsend.user.setOnce(key, value); // for single property
suprsend.user.setOnce(properties); // for multiple properties
// Sample values for setting once a single property:
suprsend.user.setOnce("first_login", "2021-11-02");
// Sample values for setting once multiple properties:
suprsend.user.setOnce({"first_login" : "2021-11-02", "DOB" : "1991-10-02"});
3. Increment
Add the given amount to an existing property on the user. If the user does not already have the associated property, the amount will be added to zero. To reduce a property, provide a negative number for the value.
suprsend.user.increment(key, value); // for single property
suprsend.user.increment(property_obj); // for multiple properties
// Sample values for incrementing a single property:
suprsend.user.increment("login_count", 1);
// Sample values for incrementing multiple properties:
suprsend.user.increment({"login_count" : 1, "order_count" : 1});
4. Append
This method will append a value to the list for a given property.
suprsend.user.append(key, value); // for single property
suprsend.user.append(property_obj); // for multiple properties
// Sample values for appending a single property:
suprsend.user.append("wishlist", "iphone12");
// Sample values for appending multiple properties:
suprsend.user.append({"wishlist" : "iphone12", "wishlist" : "Apple airpods"});
5. Remove
This method will remove a value from the list for a given property.
suprsend.user.remove(key, value); // for single property
suprsend.user.remove(property_obj); // for multiple properties
// Sample values for removing a single property:
suprsend.user.remove("wishlist", "iphone12");
// Sample values for removing multiple properties:
suprsend.user.remove({"wishlist" : "iphone12", "wishlist": "Apple airpods"});
6. Unset
This will remove a property permanently from user properties.
suprsend.user.unSet(key); // for single property
suprsend.user.unSet(property_list); // for multiple properties
// Sample values for unsetting a single property:
suprsend.user.unSet("wishlist");
// Sample values for unsetting multiple properties:
suprsend.user.unSet(["wishlist", "cart"]);
Updated 7 months ago
Once the user info is set, you can send events from your SDK by passing user distinct_id
and trigger notification from the SuprSend platform