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
Each of our Dart methods is mapped to an underlying mParticle SDK at the platform level. Note that per Dart’s documentation, calling into platform-specific code is asynchronous to ensure the user interface remains responsive. In your code, you can swap usage between async
and then
in accordance with your app’s requirements.
Importing the module:
import 'package:mparticle_flutter_sdk/mparticle_flutter_sdk.dart';
You must first call getInstance
on MparticleFlutterSdk
before each method is called. This ensures the underlying mParticle SDK has been initialized. Per Flutter’s plugin documentation, messages between the Dart plugin and underlying platforms must be passed asynchronously to ensure the user interface remains responsive. Therefore, to ensure code is performant to your team’s requirements, you may refactor instances of await
with then
and vice versa in the examples below.
MparticleFlutterSdk? mpInstance = await MparticleFlutterSdk.getInstance();
To log events, import mParticle EventTypes
and MPEvent
to write proper event logging calls:
import 'package:mparticle_flutter_sdk/events/event_type.dart';
import 'package:mparticle_flutter_sdk/events/mp_event.dart';
MPEvent event = MPEvent('Clicked Search Bar', EventType.Search)
..customAttributes = { 'key1': 'value1' }
..customFlags = { 'flag1': 'value1' };
mpInstance?.logEvent(event);
If you have a high-volume event that you would like to forward to client side kits but exclude from uploading to mParticle, set a boolean flag per event.
import 'package:mparticle_flutter_sdk/events/event_type.dart';
import 'package:mparticle_flutter_sdk/events/mp_event.dart';
MPEvent event = MPEvent('Test event logged', EventType.Navigation)
..customAttributes = {'key1': 'value1'}
..customFlags = {'flag1': 'flagValue1'}
..shouldUploadEvent = false;
mpInstance?.logEvent(event);
By default, all events upload to the mParticle server unless explicitly set not to. This is also available on Commerce Events when calling logCommerceEvent
. mParticle expects to support logScreenEvent
in a future release.
To log screen events, import mParticle ScreenEvent
:
import 'package:mparticle_flutter_sdk/events/screen_event.dart';
ScreenEvent screenEvent = ScreenEvent('Screen event logged')
..customAttributes = { 'key1': 'value1' }
..customFlags = { 'flag1': 'value1' };
mpInstance?.logScreenEvent(screenEvent);
To log product commerce events, import CommerceEvent
, Product
and ProductActionType
(optionally TransactionAttributes
):
import 'package:mparticle_flutter_sdk/events/commerce_event.dart';
import 'package:mparticle_flutter_sdk/events/product.dart';
import 'package:mparticle_flutter_sdk/events/product_action_type.dart';
import 'package:mparticle_flutter_sdk/events/transaction_attributes.dart';
final Product product1 = Product('Orange', '123abc', 5.0, 1);
final Product product2 = Product('Apple', '456abc', 10.5, 2);
final TransactionAttributes transactionAttributes =
TransactionAttributes('123456', 'affiliation', '12412342',
1.34, 43.232, 242.2323);
CommerceEvent commerceEvent = CommerceEvent.withProduct(ProductActionType.Purchase, product1)
..products.add(product2)
..transactionAttributes = transactionAttributes
..currency = 'US'
..screenName = 'One Click Purchase';
mpInstance?.logCommerceEvent(commerceEvent);
To log promotion commerce events, import CommerceEvent
, Promotion
and PromotionActionType
:
import 'package:mparticle_flutter_sdk/events/commerce_event.dart';
import 'package:mparticle_flutter_sdk/events/promotion.dart';
import 'package:mparticle_flutter_sdk/events/promotion_action_type.dart';
final Promotion promotion1 = Promotion('12312', 'Jennifer Slater', 'BOGO Bonanza', 'top');
final Promotion promotion2 = Promotion('15632', 'Gregor Roman', 'Eco Living', 'mid');
CommerceEvent commerceEvent = CommerceEvent.withPromotion(PromotionActionType.View, promotion1)
..promotions.add(promotion2)
..currency = 'US'
..screenName = 'PromotionScreen';
mpInstance?.logCommerceEvent(commerceEvent);
To log impression commerce events, import CommerceEvent
, Impression
and Product
:
import 'package:mparticle_flutter_sdk/events/commerce_event.dart';
import 'package:mparticle_flutter_sdk/events/impression.dart';
import 'package:mparticle_flutter_sdk/events/product.dart';
final Product product1 = Product('Orange', '123abc', 2.4, 1);
final Product product2 = Product('Apple', '456abc', 4.1, 2);
final Impression impression1 = Impression('produce', [product1, product2]);
final Impression impression2 = Impression('citrus', [product1]);
CommerceEvent commerceEvent = CommerceEvent.withImpression(impression1)
..impressions.add(impression2)
..currency = 'US'
..screenName = 'ImpressionScreen';
mpInstance?.logCommerceEvent(commerceEvent);
Get the current user in order to apply and remove attributes, tags, and similar items:
var user = await mpInstance?.getCurrentUser();
User Attributes:
user?.setUserAttribute('age', '45');
user?.setUserAttributeArray('Test key', ['Test value 1', 'Test value 2']);
user?.setUserTag('tag1');
user?.getUserAttributes();
user?.removeUserAttribute('age')
user?.getUserIdentities().then((identities) {
print(identities); // Map<IdentityType, String>
});
IDSync is mParticle’s identity framework, enabling our customers to create a unified view of the customer. To read more about IDSync, see the IDSync documentation.
All IDSync calls require an Identity Request
.
import 'package:mparticle_flutter_sdk/identity/identity_type.dart';
var identityRequest = MparticleFlutterSdk.identityRequest;
identityRequest
.setIdentity(IdentityType.CustomerId, 'customerid5')
.setIdentity(IdentityType.Email, 'email5@gmail.com');
After an IdentityRequest is passed to one of the following IDSync methods - identify
, login
, logout
, or modify
.
Import the SuccessResponse
and FailureResponse
classes to write proper callbacks for Identity methods. For brevity, we included an example of full error handling in only the identify
example below, but this error handling can be used for any of the Identity calls.
The following is a full Identify example with error and success handling. You can adapt the following example with login
, modify
, and logout
.
import 'package:mparticle_flutter_sdk/identity/identity_api_result.dart';
import 'package:mparticle_flutter_sdk/identity/identity_api_error_response.dart';
var request = MparticleFlutterSdk.identityRequest();
mpInstance?.identity
.identify(identityRequest: identityRequest)
.then(
(IdentityApiResult successResponse) =>
print("Success Response: $successResponse"),
onError: (error) {
var failureResponse = error as IdentityAPIErrorResponse;
print("Failure Response: $failureResponse");
// It is possible for either a client error or a server error to occur during identity calls.
// First check for the client side error, then you can check the http code for the server error.
// More details can be found in the platform specific IDSync error handling:
// iOS - https://docs.mparticle.com/developers/client-sdks/ios/idsync/#error-handling
// Web - https://docs.mparticle.com/developers/client-sdks/web/idsync/#error-handling
// Android - https://docs.mparticle.com/developers/client-sdks/android/idsync/#idsync-status-codes
if (failureResponse.clientErrorCode != null) {
switch (failureResponse.clientErrorCode) {
case IdentityClientErrorCodes.RequestInProgress:
// there is an Identity request in progress, wait for it to complete before attempting another
case IdentityClientErrorCodes.ClientSideTimeout:
case IdentityClientErrorCodes.ClientNoConnection:
// retry the IDSync request
case IdentityClientErrorCodes.SSLError:
// SSL configuration issue.
case IdentityClientErrorCodes.OptOut:
// The user has opted out of data collection
case IdentityClientErrorCodes.Unknown:
//
case IdentityClientErrorCodes.ActiveSession:
case IdentityClientErrorCodes.ValidationIssue:
// A web error that should never arise due to Dart's stronger typing
case IdentityClientErrorCodes.NativeIdentityRequest:
default:
print(failureResponse.clientErrorCode);
}
}
int? httpCode = failureResponse.httpCode;
if (httpCode != null && httpCode >= 400) {
switch (httpCode) {
case 400:
case 401:
case 429:
case 529:
default:
failureResponse.errors.forEach(
(error) => print('${error.code}\n${error.message}'));
}
}
}
);
Partial example - you can adapt the identify
example above with login
, modify
, and logout
.
var identityRequest = MparticleFlutterSdk.identityRequest;
identityRequest
.setIdentity(IdentityType.CustomerId, 'customerid2')
.setIdentity(IdentityType.Email, 'email2@gmail.com');
mpInstance?.identity
.login(identityRequest: identityRequest)
.then(
(IdentityApiResult successResponse) =>
print("Success Response: $successResponse"),
onError: (error) {
var failureResponse = error as IdentityAPIErrorResponse;
print("Failure Response: $failureResponse");
}
);
Partial example - you can adapt the identify
example above with login
, modify
, and logout
.
var identityRequest = MparticleFlutterSdk.identityRequest;
identityRequest
.setIdentity(IdentityType.CustomerId, 'customerid3')
.setIdentity(IdentityType.Email, 'email3@gmail.com');
mpInstance?.identity
.modify(identityRequest: identityRequest)
.then(
(IdentityApiResult successResponse) =>
print("Success Response: $successResponse"),
onError: (error) {
var failureResponse = error as IdentityAPIErrorResponse;
print("Failure Response: $failureResponse");
}
);
Partial example - you can adapt the identify
example above with login
, modify
, and logout
.
var identityRequest = MparticleFlutterSdk.identityRequest;
// Depending on your identity strategy, you may have identities added to your identityRequest
// To log out, insert the identities used for login and set value to empty ('')
identityRequest
.setIdentity(IdentityType.CustomerId, '')
.setIdentity(IdentityType.Email, '');
mpInstance?.identity
.logout(identityRequest: identityRequest)
.then(
(IdentityApiResult successResponse) =>
print("Success Response: $successResponse"),
onError: (error) {
var failureResponse = error as IdentityAPIErrorResponse;
print("Failure Response: $failureResponse");
}
);
Use aliasing to transition data from anonymous users to known users. To learn more about user aliasing, see the aliasing documentation.
mpInstance?.identity.login(identityRequest: identityRequest).then(
(IdentityApiResult successResponse) {
String? previousMPID = successResponse.previousUser?.getMPID();
if (previousMPID != null) {
var userAliasRequest = AliasRequest(
previousMPID, successResponse.user.getMPID()
);
mpInstance?.identity.aliasUsers(aliasRequest: userAliasRequest);
}
}
);
A few methods are currently supported only on iOS/Android SDKs:
Get the SDK’s opt-out status:
var isOptedOut = await mpInstance?.getOptOut;
mpInstance?.setOptOut(optOutBoolean: !isOptedOut!);
Check if a kit is active:
import 'package:mparticle_flutter_sdk/kits/kits.dart';
mpInstance?.isKitActive(kit: Kits['Braze']!).then((isActive) {
print(isActive);
});
Push Registration
The method mpInstance.logPushRegistration()
accepts two parameters. For Android, provide both pushToken
and senderId
. For iOS, provide the push token in the first parameter, and simply pass null
for the second parameter.
mpInstance?.logPushRegistration(pushToken: 'pushToken123', senderId: 'senderId123');
mpInstance?.logPushRegistration(pushToken: 'pushToken123', senderId: null);
Set App Tracking Transparency (ATT) Status
For iOS, you can set a user’s ATT status as follows: import ‘package:mparticle_flutter_sdk/apple/authorization_status.dart’;
mpInstance?.setATTStatus(
attStatus: MPATTAuthorizationStatus.Authorized,
timestampInMillis: DateTime.now().millisecondsSinceEpoch);
Was this page helpful?