Data Subject Request API Version 1 and 2
Data Subject Request API Version 3
Platform API Overview
Accounts
Apps
Audiences
Calculated Attributes
Data Points
Feeds
Field Transformations
Services
Users
Workspaces
Warehouse Sync API Overview
Warehouse Sync API Tutorial
Warehouse Sync API Reference
Data Mapping
Warehouse Sync SQL Reference
Warehouse Sync Troubleshooting Guide
ComposeID
Warehouse Sync API v2 Migration
Bulk Profile Deletion API Reference
Calculated Attributes Seeding API
Data Planning API
Custom Access Roles API
Group Identity API Reference
Pixel Service
Profile API
Events API
mParticle JSON Schema Reference
IDSync
AMP SDK
Initialization
Configuration
Network Security Configuration
Event Tracking
User Attributes
IDSync
Screen Events
Commerce Events
Location Tracking
Media
Kits
Application State and Session Management
Data Privacy Controls
Error Tracking
Opt Out
Push Notifications
WebView Integration
Logger
Preventing Blocked HTTP Traffic with CNAME
Linting Data Plans
Troubleshooting the Android SDK
API Reference
Upgrade to Version 5
Cordova Plugin
Identity
Direct URL Routing FAQ
Web
Android
iOS
Initialization
Configuration
Event Tracking
User Attributes
IDSync
Screen Tracking
Commerce Events
Location Tracking
Media
Kits
Application State and Session Management
Data Privacy Controls
Error Tracking
Opt Out
Push Notifications
Webview Integration
Upload Frequency
App Extensions
Preventing Blocked HTTP Traffic with CNAME
Linting Data Plans
Troubleshooting iOS SDK
Social Networks
iOS 14 Guide
iOS 15 FAQ
iOS 16 FAQ
iOS 17 FAQ
iOS 18 FAQ
API Reference
Upgrade to Version 7
Getting Started
Identity
Upload Frequency
Getting Started
Opt Out
Initialize the SDK
Event Tracking
Commerce Tracking
Error Tracking
Screen Tracking
Identity
Location Tracking
Session Management
Initialization
Content Security Policy
Configuration
Event Tracking
User Attributes
IDSync
Page View Tracking
Commerce Events
Location Tracking
Media
Kits
Application State and Session Management
Data Privacy Controls
Error Tracking
Opt Out
Custom Logger
Persistence
Native Web Views
Self-Hosting
Multiple Instances
Web SDK via Google Tag Manager
Preventing Blocked HTTP Traffic with CNAME
Facebook Instant Articles
Troubleshooting the Web SDK
Browser Compatibility
Linting Data Plans
API Reference
Upgrade to Version 2 of the SDK
Getting Started
Identity
Web
Alexa
Overview
Step 1. Create an input
Step 2. Verify your input
Step 3. Set up your output
Step 4. Create a connection
Step 5. Verify your connection
Step 6. Track events
Step 7. Track user data
Step 8. Create a data plan
Step 9. Test your local app
Overview
Step 1. Create an input
Step 2. Verify your input
Step 3. Set up your output
Step 4. Create a connection
Step 5. Verify your connection
Step 6. Track events
Step 7. Track user data
Step 8. Create a data plan
Overview
Step 1. Create an input
Step 2. Verify your input
Step 3. Set up your output
Step 4. Create a connection
Step 5. Verify your connection
Step 6. Track events
Step 7. Track user data
Step 8. Create a data plan
Step 1. Create an input
Step 2. Create an output
Step 3. Verify output
Node SDK
Go SDK
Python SDK
Ruby SDK
Java SDK
Introduction
Outbound Integrations
Firehose Java SDK
Inbound Integrations
Compose ID
Glossary
Data Hosting Locations
Migrate from Segment to mParticle
Migrate from Segment to Client-side mParticle
Migrate from Segment to Server-side mParticle
Segment-to-mParticle Migration Reference
Rules Developer Guide
API Credential Management
The Developer's Guided Journey to mParticle
Create an Input
Start capturing data
Connect an Event Output
Create an Audience
Connect an Audience Output
Transform and Enhance Your Data
The new mParticle Experience
The Overview Map
Introduction
Data Retention
Connections
Activity
Live Stream
Data Filter
Rules
Tiered Events
mParticle Users and Roles
Analytics Free Trial
Troubleshooting mParticle
Usage metering for value-based pricing (VBP)
Introduction
Sync and Activate Analytics User Segments in mParticle
User Segment Activation
Welcome Page Announcements
Project Settings
Roles and Teammates
Organization Settings
Global Project Filters
Portfolio Analytics
Analytics Data Manager Overview
Events
Event Properties
User Properties
Revenue Mapping
Export Data
UTM Guide
Data Dictionary
Query Builder Overview
Modify Filters With And/Or Clauses
Query-time Sampling
Query Notes
Filter Where Clauses
Event vs. User Properties
Group By Clauses
Annotations
Cross-tool Compatibility
Apply All for Filter Where Clauses
Date Range and Time Settings Overview
Understanding the Screen View Event
Analyses Introduction
Getting Started
Visualization Options
For Clauses
Date Range and Time Settings
Calculator
Numerical Settings
Assisted Analysis
Properties Explorer
Frequency in Segmentation
Trends in Segmentation
Did [not] Perform Clauses
Cumulative vs. Non-Cumulative Analysis in Segmentation
Total Count of vs. Users Who Performed
Save Your Segmentation Analysis
Export Results in Segmentation
Explore Users from Segmentation
Getting Started with Funnels
Group By Settings
Conversion Window
Tracking Properties
Date Range and Time Settings
Visualization Options
Interpreting a Funnel Analysis
Group By
Filters
Conversion over Time
Conversion Order
Trends
Funnel Direction
Multi-path Funnels
Analyze as Cohort from Funnel
Save a Funnel Analysis
Explore Users from a Funnel
Export Results from a Funnel
Saved Analyses
Manage Analyses in Dashboards
Dashboards––Getting Started
Manage Dashboards
Dashboard Filters
Organize Dashboards
Scheduled Reports
Favorites
Time and Interval Settings in Dashboards
Query Notes in Dashboards
User Aliasing
The Demo Environment
Keyboard Shortcuts
Analytics for Marketers
Analytics for Product Managers
Compare Conversion Across Acquisition Sources
Analyze Product Feature Usage
Identify Points of User Friction
Time-based Subscription Analysis
Dashboard Tips and Tricks
Understand Product Stickiness
Optimize User Flow with A/B Testing
User Segments
IDSync Overview
Use Cases for IDSync
Components of IDSync
Store and Organize User Data
Identify Users
Default IDSync Configuration
Profile Conversion Strategy
Profile Link Strategy
Profile Isolation Strategy
Best Match Strategy
Aliasing
Overview
Create and Manage Group Definitions
Introduction
Catalog
Live Stream
Data Plans
Blocked Data Backfill Guide
Predictive Attributes Overview
Create Predictive Attributes
Assess and Troubleshoot Predictions
Use Predictive Attributes in Campaigns
Predictive Audiences Overview
Using Predictive Audiences
Introduction
Profiles
Warehouse Sync
Data Privacy Controls
Data Subject Requests
Default Service Limits
Feeds
Cross-Account Audience Sharing
Approved Sub-Processors
Import Data with CSV Files
CSV File Reference
Glossary
Video Index
Single Sign-On (SSO)
Setup Examples
Introduction
Introduction
Introduction
Rudderstack
Google Tag Manager
Segment
Advanced Data Warehouse Settings
AWS Kinesis (Snowplow)
AWS Redshift (Define Your Own Schema)
AWS S3 Integration (Define Your Own Schema)
AWS S3 (Snowplow Schema)
BigQuery (Snowplow Schema)
BigQuery Firebase Schema
BigQuery (Define Your Own Schema)
GCP BigQuery Export
Snowflake (Snowplow Schema)
Snowplow Schema Overview
Snowflake (Define Your Own Schema)
Aliasing
The SDK surfaces a series of APIs to manage user-identity state. These client-side APIs work in tandem with the mParticle IDSync HTTP API and your configured “identity strategy.” These APIs are designed generically but identity management requirements vary by app - so it’s crucial that you use the APIs correctly per your app’s unique requirements.
See the mParticle IDSync overview for a platform-agnostic overview of the key operations you can perform and read below for how the API is surfaced in the Android SDK.
There are four key APIs exposed via the Android SDK:
The following applies to all of these APIs:
IdentityApiRequest
object typeMParticleTask<IdentityApiResult>
to listen for success and failureidentify
or login
on every app startup - this is not necessary and will result in high network traffic.Populating IDSync requests correctly is crucial to managing the state of your users and the association of events. Reference the complete API reference for specific Android API and parameter-level details.
An IdentityApiRequest
is a holder for a set of identities that you would like to associate with the user. The IdentityApiRequest
provides two static factory methods that return the IdentityApiRequest.Builder
used to construct the request:
IdentityApiRequest.withEmptyUser()
- this will result in an empty user/requestIdentityApiRequest.withUser(user)
- this will result in a request containing the same identities as the given user, which you can then mutate furtherIdentityApiRequest identityRequest = IdentityApiRequest.withEmptyUser()
//the IdentityApiRequest provides several convenience methods for common identity types
.email("foo@example.com")
.customerId("123456")
//alternatively, you can use the setUserIdentity method and supply the MPUserIdentity type
.userIdentity(MParticle.IdentityType.Other, "example-other-id")
.build();
val identityRequest = IdentityApiRequest.withEmptyUser().run {
//the IdentityApiRequest provide convenience methods for common identity types
email("foo@example.com")
customerId("123456")
//alternatively, you can use the setUserIdentity method and supply the MPUserIdentity type
userIdentity(MParticle.IdentityType.Other, "example-other-id")
build()
}
When you invoke any of the four key IDSync APIs with an IdentityApiRequest
:
The “identify” API is unique in that it is called automatically on SDK initialization by the mParticle SDK. The SDK requires this call to succeed in order to establish an mParticle ID to associate with all data.
There are several considerations to account for during SDK initialization:
IdentityApiRequest
and set it to the identify
field of your MParticleOptions
object, and supply that to mParticle’s start
API. See the SDK initialization example below.IdentityApiRequest
during SDK initialization, the mParticle SDK will use its local persistence to generate a IdentityApiRequest
for you based off of the most recent user, supplying the most recent user identities.Here’s an example of how you might initialize the SDK and set a user-attribute once the user object becomes available:
public class ExampleApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
IdentityApiRequest identityRequest = IdentityApiRequest.withEmptyUser()
.email("foo@example.com")
.customerId("123456")
.build();
BaseIdentityTask identifyTask = new BaseIdentityTask()
.addFailureListener(new TaskFailureListener() {
@Override
public void onFailure(IdentityHttpResponse identityHttpResponse) {
//handle failure - see below
}
}).addSuccessListener(new TaskSuccessListener() {
@Override
public void onSuccess(IdentityApiResult identityApiResult) {
MParticleUser user = identityApiResult.getUser();
user.setUserAttribute("example attribute key", "example attribute value");
}
});
MParticleOptions options = MParticleOptions.builder(this)
.credentials("REPLACE WITH API KEY", "REPLACE WITH API SECRET")
.identify(identityRequest)
.identifyTask(identifyTask)
.build();
MParticle.start(options);
}
}
class ExampleApplication : Application() {
override fun onCreate() {
super.onCreate()
val identityRequest = IdentityApiRequest.withEmptyUser()
.email("foo@example.com")
.customerId("123456")
.build()
val identifyTask = BaseIdentityTask()
.addFailureListener { identityHttpResponse ->
//handle failure - see below
}.addSuccessListener { identityApiResult ->
val user = identityApiResult.user
user.setUserAttribute("example attribute key", "example attribute value")
}
val options = MParticleOptions.builder(this)
.credentials("REPLACE WITH API KEY", "REPLACE WITH API SECRET")
.identify(identityRequest)
.identifyTask(identifyTask)
.build()
MParticle.start(options)
}
}
The login and logout APIs should be invoked at the time of the user performing the matching actions in your application. These methods have identical signatures - they both accept an IdentityApiRequest
and return an MParticleTask<IdentityApiResult>
that allows you to listen for both success and failure:
// Define your identityRequest
IdentityApiRequest identityRequest = IdentityApiRequest.withEmptyUser()
// Include any identities you want to associate with the logged in user here. See "Create an IDSync request" above for more details.
// This example shows the addition of the email identity.
.email("foo@example.com").build();
// Call the login method, passing in the identityRequest you just created
MParticle.getInstance().Identity().login(identityRequest);
// Define your identityRequest
val identityRequest = IdentityApiRequest.withEmptyUser()
// Include any identities you want to associate with the logged in user here. See "Create an IDSync request" above for more details.
// This example shows the addition of the email identity.
.email("foo@example.com").build()
// Call the login method, passing in the identityRequest you just created
MParticle.getInstance().Identity().login(identityRequest)
Logout is invoked similarly to login, and you can supply an IdentityApiRequest
if you have anonymous identifiers you would like to associate with the logged-out user state. More commonly, you can exclude the IdentityApiRequest
to denote that the logged-out user should have no associated user identities:
MParticle.getInstance().Identity().logout();
// exluding the identity request from any IDSync API is the same as invoking the following:
MParticle.getInstance().Identity().logout(IdentityApiRequest.withEmptyUser().build());
MParticle.getInstance().Identity().logout()
// exluding the identity request from any IDSync API is the same as invoking the following:
MParticle.getInstance().Identity().logout(IdentityApiRequest.withEmptyUser().build())
Modify also has the identical signature, but note a crucial difference: modify actions are always for a specific mParticle ID (MPID) - they will never result in a new user or MPID. Modify can only add, remove, or change the identities associated with an existing user. Please note that this should not be used to handle registration/login and logout scenarios. Modify is generally used when a user updates their profile in their app, such as updating their email.
For each modify request:
IdentityApiRequest
, and invoke the underlying Identity HTTP APIIn this example, the SDK will change the email of the current user, or add the email to the user’s profile if the user has no existing email on this device:
IdentityApiRequest modifyRequest = IdentityApiRequest.withEmptyUser()
.email("updated-email@example.com")
.build();
MParticle.getInstance().Identity().modify(modifyRequest);
IdentityApiRequest modifyRequest = IdentityApiRequest.withEmptyUser()
.email("updated-email@example.com")
.build()
MParticle.getInstance().Identity().modify(modifyRequest)
In this example, the SDK will remove the email of the current user, or will do nothing if the user has no email on this device:
IdentityApiRequest modifyRequest = IdentityApiRequest.withEmptyUser()
.email(null)
.build();
MParticle.getInstance().Identity().modify(modifyRequest);
val modifyRequest = IdentityApiRequest.withEmptyUser()
.email(null)
.build()
MParticle.getInstance().Identity().modify(modifyRequest)
The mParticle IDSync API is intended to be central to your app’s state and is designed to be fast and highly-available. Similar to how your app may prevent users from logging in, logging out, or modifying their state without an internet connection - we intend you to treat these APIs as gating operations in order to maintain a consistent user state. The SDK will not retry API calls automatically, but provides callback APIs such that you can do so according to your business logic. The tolerance you have for retry and inconsistent state is up to your product requirements.
The SDK will always return the HTTP status and HTTP body of the underlying HTTP response. The SDK will return IdentityApi.UNKNOWN_ERROR
as well as an informative error message for client-side issues including:
For more information about 429 responses and API throttling, see Default Service Limits.
MParticle.getInstance().Identity().login(identityRequest)
.addFailureListener(new TaskFailureListener() {
@Override
public void onFailure(IdentityHttpResponse identityHttpResponse) {
if (identityHttpResponse.getHttpCode() == IdentityApi.UNKNOWN_ERROR) {
//device is likely offline and request should be retried
} else if (identityHttpResponse.getHttpCode() == IdentityApi.THROTTLE_ERROR) {
//on rare occurances you may receive and retry throttling errors (429)
}
Log.d("IDSync Error", identityHttpResponse.toString());
}
})
.addSuccessListener(new TaskSuccessListener() {
@Override
public void onSuccess(IdentityApiResult identityApiResult) {
//proceed with login
}
});
MParticle.getInstance().Identity().login(identityRequest)
.addFailureListener { identityHttpResponse ->
if (identityHttpResponse.httpCode == IdentityApi.UNKNOWN_ERROR) {
//device is likely offline and request should be retried
} else if (identityHttpResponse.httpCode == IdentityApi.THROTTLE_ERROR) {
//on rare occurances you may receive and retry throttling errors (429)
}
Log.d("IDSync Error", identityHttpResponse.toString())
}
.addSuccessListener {
//proceed with login
}
As mentioned in the overview above, the IDSync API is meant to transition the SDK’s “current user.” The SDK maintains values in persistence that are associated with each user, such as user attributes. On completion of a successful login, you can copy user data from the previous user to the new user.
If your organization uses Profile Link or Profile Conversion strategies, you can also create a request to alias the previous user to the current user. See our main documentation on aliasing for more information.
// Basic - Call alias as the result of a successful login
MParticle.getInstance().Identity().login()
.addSuccessListener(new TaskSuccessListener() {
@Override
public void onSuccess(@NonNull IdentityApiResult result) {
login request returns new and previous users
MParticleUser newUser = result.getUser();
MParticleUser previousUser = result.getPreviousUser();
// Copy anything attributes and products from previous to new user
// this example copies everything
newUser.setUserAttributes(previousUser.getUserAttributes());
// Create and send the alias request
AliasRequest request = AliasRequest
.builder(previousUser, newUser)
.build();
MParticle.getInstance().Identity().aliasUsers(request);
}
});
// Call alias at any time
// The getUsers() API now returns users in reverse chronological order
MParticleUser sourceUser = MParticle.getInstance().Identity().getUsers().get(1);
MParticleUser destinationUser = MParticle.getInstance().Identity().getUsers().get(0);
AliasRequest request = AliasRequest.builder()
.sourceMpid(sourceUser.getId())
.destinationMpid(destinationUser.getId())
.startTime(sourceUser.getFirstSeenTime()) // must be within 90 days
.endTime(sourceUser.getLastSeenTime()) // must be between StartTime and now
.build();
MParticle.getInstance().Identity().aliasUsers(request);
// Basic - Call alias as the result of a successful login
MParticle.getInstance()?.Identity()?.login()?.addSuccessListener {
result ->
// login request returns new and previous users
val newUser: MParticleUser = result.getUser()
val previousUser: MParticleUser? = result.getPreviousUser()
// Copy any attributes from previous to new user
// this example copies everything
previousUser?.let { newUser.setUserAttributes(it.userAttributes) }
// Create and send the alias request
val request: AliasRequest = AliasRequest.Builder()
.sourceMpid(previousUser?.id ?: 0)
.destinationMpid(newUser.id)
.build();
MParticle.getInstance()?.Identity()?.aliasUsers(request);
}
// Call alias at any time
// The getUsers() API now returns users in reverse chronological order
val sourceUser: MParticleUser? = MParticle.getInstance()?.Identity()?.users?.get(1)
val destinationUser: MParticleUser? = MParticle.getInstance()?.Identity()?.users?.get(0)
if(sourceUser != null && destinationUser != null) {
val request: AliasRequest = AliasRequest.Builder()
.sourceMpid(sourceUser?.id)
.destinationMpid(destinationUser?.id)
.startTime(sourceUser.firstSeenTime) // must be within 90 days
.endTime(sourceUser.lastSeenTime) // must be between startTime and now
.build()
MParticle.getInstance()?.Identity()?.aliasUsers(request)
}
IdentityStateListener
notifications. This will be fired whenever the MPID changes.IdentityStateListener listener = new IdentityStateListener() {
@Override
public void onUserIdentified(@NonNull MParticleUser user, @Nullable previousUser) {
//
}
};
MParticle.getInstance().Identity().addIdentityStateListener(listener);
MParticle.getInstance()?.Identity()?.addIdentityStateListener { user, previousUser ->
}
In order to stop receiving notifications, you can remove the listener
MParticle.getInstance().Identity().removeIdentityStateListener(listener);
val listener = { user: MParticleUser -> }
MParticle.getInstance()?.Identity()?.removeIdentityStateListener(listener)
See the table below and the complete API reference for supported user identity types:
IdentityType | Description |
---|---|
CustomerId |
If you have an internal ID for your customer |
Email |
The user’s email address |
Other |
Any other identifier that can contribute to user identification |
Other2 |
Any other identifier that can contribute to user identification |
Other3 |
Any other identifier that can contribute to user identification |
Other4 |
Any other identifier that can contribute to user identification |
Other5 |
Any other identifier that can contribute to user identification |
Other6 |
Any other identifier that can contribute to user identification |
Other8 |
Any other identifier that can contribute to user identification |
Other8 |
Any other identifier that can contribute to user identification |
Other9 |
Any other identifier that can contribute to user identification |
Other10 |
Any other identifier that can contribute to user identification |
MobileNumber |
The user’s mobile number |
PhoneNumber2 |
Any other phone number for the user |
PhoneNumber3 |
Any other phone number for the user |
FacebookCustomAudienceId |
The user’s Facebook App User ID that can be retrieved through the Facebook SDK |
Google |
The user’s Google ID |
Twitter |
The user’s Twitter ID |
Microsoft |
The user’s Microsoft ID |
Yahoo |
The user’s Yahoo ID |
Was this page helpful?