-
Notifications
You must be signed in to change notification settings - Fork 6
Users and installations
Mobile Messaging SDK employs specific terms in order to address different type of information that you can synchronize
towards Infobip Platform. You will see User
and Installation
terms in the SDK similarly to what you can see
at People section at Infobip Portal.
-
Installation
is a specific installation of your application. Each application installation on a device receives unique installation ID -pushRegistrationId
.pushRegistrationId
is a permanent ID assigned to the app once it’s launched up until the moment it’s uninstalled from the device. In this documentation, the terms 'installation' and 'push registration' are used interchangeably and denote the same concept. You can see it asMobile App Messaging (Push Notifications)
destination underContact Information
tab of a user profile. A single user can have zero or more installations of different applications. You can change some specific settings of each installation of a user, addCustom attributes
to it or do a remoteLogout
of a specific installation. -
User
represents a single person profile withStandard attributes
,Custom attributes
andTags
which you can set via the SDK.
Both user and installation objects are initialized once Mobile Messaging SDK is successfully started.
Installation
is a specific installation (or instance) of your application on a user's device. Standard attributes and their descriptions are available in docs, code - Installation. One user can have multiple installations.
You can get current installation details from server:
var installation = await InfobipMobilemessaging.fetchInstallation();
All the current users' installations are also available under UserData
:
var user = await InfobipMobilemessaging.fetchUser();
if (user.installations != null) {
for (var installation in user.installations!) {
log('Installation is: ${installation.toJson()}');
}
}
Infobip creates an empty user profile as soon as device registers on the platform. Afterwards you should be able to find this user profile at Infobip Portal using for example pushRegistrationId
(or other attributes, such as phone number, in case the installation was personalized) provided via the SDK:
You can temporarily "disable" your installation if you don't want to receive push notifications:
Installation installation = await InfobipMobilemessaging.getInstallation();
installation.isPushRegistrationEnabled = false;
InfobipMobilemessaging.saveInstallation(installation);
On the Infobip account, a single user profile can have one or more mobile devices with the application installed. You might want to mark one of these devices as the primary device and send push messages only to this device (e.g. receive bank authorization codes only on one device). To achieve this and similar use-cases, you can utilize the APIs provided by the Mobile Messaging SDK.
For this feature to work, the API request for sending the push notification must include a special parameter targetOnlyPrimaryDevices
set to true
. Parameters for sending a single push notification can be checked in the Infobip API Docs. With this parameter, push notifications will not be sent to any installations that are not marked as primary. This means that for this feature to work, both the mobile implementation and the API request parameter must be used in conjunction.
By default, all installations are marked as non-primary. To set a particular installation as primary, either the Contact Information API or the following Mobile Messaging SDK API can be used:
Installation installation = await InfobipMobilemessaging.getInstallation();
installation.isPrimaryDevice = false;
InfobipMobilemessaging.saveInstallation(installation);
You can set/reset primary setting for any other installation of a current user:
var pushRegId = '< Push Registration ID of another installation >';
InfobipMobilemessaging.setInstallationAsPrimary(InstallationPrimary(pushRegistrationId: pushRegId, primary: true));
An Installation
can have custom attributes the same way as User
does, so that you would be able to reach only specific installation of a user.
Installation installation = await InfobipMobilemessaging.getInstallation();
installation.customAttributes = {'OneTimePassword': true};
InfobipMobilemessaging.saveInstallation(installation);
These custom attributes can be seen under push destination on portal:
You can provide additional user's data to the server, so that you will be able to send personalised targeted messages to exact user and have other nice features. Library supports a set of predefined attributes as well as custom ones.
You can always get current user data from server via the SDK API. The request produce an HTTP call, so make sure to handle failures if any.
var userData = await InfobipMobilemessaging.fetchUser();
There are two types of user profiles: Lead
and Customer
:
Leads are profiles with the person`s name and contact information that has not been verified.
Leads are changed to Customers during personalization using the provided identifiers. If profile is already a Customer
, profile is updated with the information about the installation.
var user = await InfobipMobilemessaging.fetchUser();
var type = user.type; //LEAD or CUSTOMER
Each user can have External user ID
, Emails
and Phone numbers
. These fields are unique identifiers of a user profile on Infobip platform and provide capability to personalize any app installation with a user profile. The platform provides data grouping functions based on these parameters. For example, if two installations of a particular app will try to save the same External user ID
, then both of them will be collected under a single user. Phone number
, Email
and External user ID
are also widely used when targeting users with messages across different channels via Infobip platform.
Following restrictions apply:
- External User Id: any string, except any form of "null", "Null", "NULL" etc are not supported and would be considered as JSON
null
- Phone number: string, https://en.wikipedia.org/wiki/E.164, i.e.
"38516419710"
) - Email: string, format described in https://tools.ietf.org/html/rfc2822, i.e.
"[email protected]"
)
It is also possible to set User attributes on personalization using UserAttributes. It will override any existing values, so use carefully.
var user = UserIdentity(
externalUserId: 'extID',
// OR
// emails: ['[email protected]'],
// phones: ['38516419710'],
);
// Optional, replaces existing values set to the person with provided ones
var userAttributes = {
'firstName': 'John',
'lastName': 'Doe',
'gender': 'Male',
'birthday': "1968-02-10",
'tags': ["Promotions", "Transactions"],
};
var personalizeContext = PersonalizeContext(userIdentity: user, userAttributes: userAttributes, forceDepersonalize: true);
try {
InfobipMobilemessaging.personalize(personalizeContext);
} on PlatformException catch (e) {
switch (e.code) {
case 'PHONE_INVALID':
{
//the phone provided was not recognized as a valid one
}
break;
case 'EMAIL_INVALID':
{
//the email provided was not recognized as a valid one
}
break;
case 'AMBIGUOUS_PERSONALIZE_CANDIDATES':
{
//several People profiles satisfy supplied user identity, check at Customer Portal
}
break;
default:
{
log('MobileMessaging: error is $e');
}
}
}
You can use External User ID to uniquely target your user. External User ID is meant to be an ID of a user in an external (non-Infobip) service. It can be any string and can be shared across different instances of your app, so that a user with multiple devices can still be targeted as a single user of your app. Notice: for externalUserId
any string values such as "null", "Null" or "NULL" are not supported and would be considered as JSON null
You can depersonalize
current installation to detach it from current user profile so that the user won't receive messages when targeted by any person attribute:
InfobipMobilemessaging.depersonalize();
You also can depersonalize any installation that is personalized with the current user:
var pushRegId = '< push reg id of another installation of user >';
InfobipMobilemessaging.depersonalizeInstallation(pushRegId);
Q: When should I log out my users? A: Application users can (and probably should) be logged out if the app meets all the following conditions:
- you leverage user attributes functionality
- your application has "log out"/"sign out" feature
- you don't want a newly logged in (signed up) user to be targeted by other user's data (such as phone numbers, first name, custom attributes etc.) and receive personalized messages
- you want logged out (signed out) user to still receive broadcast notifications (if not, you need to disable push registration)
If you want previous personalization to be reset, in other words, depersonalize this particular installation, provide a special argument forceDepersonalize
:
var user = UserIdentity(
externalUserId: 'externalUserID',
// OR
// emails: ['[email protected]'],
// phones: ['38516419710'],
);
var personalizeContext = PersonalizeContext(userIdentity: user, userAttributes: null, forceDepersonalize: true);
try {
await InfobipMobilemessaging.personalize(personalizeContext);
} on PlatformException catch (e) {
//check the error
}
If you want to do a personalization without promoting profile to Customer
you can set keepAsLead
parameter to true
.
await InfobipMobilemessaging.personalize(
PersonalizeContext(
userIdentity: userIdentity,
userAttributes: null,
forceDepersonalize: true,
keepAsLead: true
),
);
You can set different standard attributes of a user, such as First name
, Last name
, Birthday
etc.:
var user = UserData(
firstName: 'John',
lastName: 'Doe',
birthday: '1968-02-10',
gender: Gender.Male,
);
try {
await InfobipMobilemessaging.saveUser(user);
} on PlatformException catch (e) {
//check the error
}
Please note that saveUser()
may return a USER_MERGE_INTERRUPTED
error if you have provided an already existing Phone number, Email, or External User Id that are already taken by another existing user profile. In other words, that particular phone/email/externalUserId is a unique identifier of an already existing user, different from the one that this installation is currently personalized with. You can find more details about this, and other possible errors at Server errors. If you wish to personalize the app installation with another existing user, that is, merge current user with another one, please use our Personalize API or SDK method.
For editing any attributes of the existing user, perform fetchUser()
first to get server data. Setting values to null (and saving user afterwards) will remove them from the user.
Apart from a list of standard attributes, each User
can have a set of custom ones. These are commonly used to cover any use-cases about targeting and segmentation, which are not covered by the platform out of the box. Custom attributes are key-value pairs. Keys are of string
type, values can be of string
, number
(converted all to Decimal number
type), boolean
, date
, datetime
or list of objects
data type. SDK allows both getting and setting these custom attributes.
Difference between date
and datetime
types is that usage of date
doesn't sync time to the server (e.g. "2020-11-30"), but with datetime
we provide timestamp as well that can be visible on web.
You can easily update custom attributes of a user with the same api:
User user = {
customAttributes: {
'alList': [
{
'alDate': '2021-10-11',
'alWhole': 2,
'alString': 'someAnotherString',
'alBoolean': true,
'alDecimal': 0.66
}
]
}};
InfobipMobilemessaging.saveUser(user);
With this data, you can segment users by using Segments and target them by their custom attribute values:
Detailed description on what list of objects is, some common use cases and how to set it on web are provided here. Mobile implementation specifics:
- as provided in the upper example of updating custom attributes, list of objects can be set as a custom attribute, but this type is more complex
- list of objects needs to be created on web
- it needs to have the same structure as on web when it's provided from SDK, otherwise error will be returned as an error response
- supported types are:
string
,number
,boolean
,date
anddatetime
You can add or remove Tags
from users based on their preferences or interests. Using Tags
you can easily segment users which are interested in any specific topic and send messages only to such users.
User user = {
tags: ['Promotions', 'Transactions']
};
InfobipMobilemessaging.saveUser(user);
Afterwards you will see these tags in a user profile and will be able to segment such users when sending targeted messages or campaigns.
- Library events
- Server errors
- Users and installations
- Messages and notifications management
- Inbox
- Privacy settings
- In-app chat
- WebRTC Calls and UI
- Migration Guides