MAUI SDK+ Integration Guide
This page explains how to implement the Rokt Ecommerce MAUI SDK+. The SDK+ passes user and transaction data to Rokt on configured screens so Rokt can render relevant experiences, such as offers on confirmation screens.
Work with your Rokt account manager to first implement the SDK+ in a development environment so you can thoroughly test before going live.
1. Add the Rokt SDK+ to Your MAUI App1. Add the Rokt SDK+ to Your MAUI App への直接リンク
Add the mParticle MAUI packages to your project:
dotnet add package mParticle.MAUI
dotnet add package mParticle.MAUI.Kits.Rokt
For Android you also need to ensure your activity extends MauiAppCompatActivity.
2. Initialize the Rokt SDK+2. Initialize the Rokt SDK+ への直接リンク
Insert the following initialization snippet in your application startup. The mParticle MAUI SDK+ must be initialized before any other SDK+ API calls. Replace your-key and your-secret with the key and secret provided by your Rokt team.
using mParticle.MAUI;
string key = "";
string secret = "";
#if __ANDROID__
key = "your-key";
secret = "your-secret";
#elif __IOS__
key = "your-key";
secret = "your-secret";
#endif
// Initialize the SDK+
var options = new MParticleOptions()
{
ApiKey = key,
ApiSecret = secret
};
// Specify the data environment with Environment:
// Set it to Development if you are still testing your integration.
// Set it to Production if your integration is ready for production data.
// The default is AutoDetect which attempts to detect the environment automatically.
options.Environment = mParticle.MAUI.Environment.Development;
// Identify the current user:
var identifyRequest = new IdentityApiRequest();
identifyRequest.UserIdentities = new Dictionary<UserIdentity, string>()
{
#if __ANDROID__
// Preferred: pass the customer's raw, unhashed email.
// If you can only provide a SHA-256-hashed email, use UserIdentity.Other instead — do not pass both.
{ UserIdentity.Email, "j.smith@example.com" },
{ UserIdentity.Other, "SHA-256 hashed email" }, // only if raw email unavailable
// If you can only provide a SHA-256-hashed mobile number, use Other2 instead of MobileNumber — do not pass both.
{ UserIdentity.Other2, "SHA-256 hashed mobile number" }, // only if raw mobile unavailable
{ UserIdentity.MobileNumber, "+13125551515" },
{ UserIdentity.CustomerId, "cust_10482" }
#elif __IOS__
// Preferred: pass the customer's raw, unhashed email.
// If you can only provide a SHA-256-hashed email, use UserIdentity.Other instead — do not pass both.
{ UserIdentity.Email, "j.smith@example.com" },
{ UserIdentity.Other, "SHA-256 hashed email" }, // only if raw email unavailable
// Customer phone number in E.164 format.
{ UserIdentity.MobileNumber, "+13125551515" },
// If you can only provide a SHA-256-hashed mobile number, use Other4 instead of MobileNumber — do not pass both.
{ UserIdentity.Other2, "SHA-256 hashed mobile number" }, // only if raw mobile unavailable
{ UserIdentity.CustomerId, "cust_10482" }
#endif
};
// If the user is identified with their email address, set additional user attributes.
options.IdentifyRequest = identifyRequest;
OnUserIdentified onIdentifyComplete = newUser =>
{
if (newUser != null)
{
newUser.SetUserAttribute("example attribute key", "example attribute value");
}
};
options.IdentityStateListener = onIdentifyComplete;
// Register the Rokt kit with mParticle before initialization
RoktKit.Register();
MParticle.Instance.Initialize(options);
When inserting the initialization snippet into your application startup, you will see customizable fields for:
-
Entering your Rokt key and secret.
Set
your-keyandyour-secretinside the platform-specific blocks to the key and secret values provided by your Rokt account manager. -
Setting your data environment.
Set
options.EnvironmenttomParticle.MAUI.Environment.Developmentwhile testing to route data to the Development environment, andmParticle.MAUI.Environment.Productionto send live customer activity to Production. -
Identifying your user and setting attributes.
In
identifyRequest.UserIdentities, pass the user's raw, un-hashed email viaUserIdentity.Email. For hashed emails and other identifiers, see Supported User Identifiers. Once identified, use theIdentityStateListenercallback to set additional user attributes — see User Attributes for the recommended list.IdentityStateListenerOnUserIdentified onIdentifyComplete = newUser =>
{
if (newUser != null)
{
newUser.SetUserAttribute("example attribute key", "example attribute value");
}
};
options.IdentityStateListener = onIdentifyComplete;注記Always include
identifyRequestin the initialization snippet. If you don't have the user's email at initialization, omit theUserIdentity.Emailentry — the SDK+ will still initialize, and you can identify the user later via 3. Identify the User. See Error Handling for how to handle identity failures — without error handling you may see data consistency issues at scale.
3. Identify the User3. Identify the User への直接リンク
Call MParticle.Instance.Identity.Identify with a fresh identifyRequest any time the user provides their email address after the SDK+ has initialized (for example, when they log in, create an account, or make a purchase). This ensures event data is attributed to the correct user.
Supported User IdentifiersSupported User Identifiers への直接リンク
Show supported user identifiers
| Field | Type | Description |
|---|---|---|
email | string | Pass the customer's raw, unhashed email address. |
mobile | string | Pass the customer's phone number in E.164 format. |
customerid | string | Pass your internal customer/account identifier. Send on every screen for logged-in users. |
other | string | Pass a SHA-256-hashed email. Only use when the raw email cannot be provided — do not pass both email and other. (Android path only.) |
other2 | string | Pass a SHA-256-hashed mobile number. Only use when the raw mobile number cannot be provided — do not pass both mobile and other2. (Android path only.) |
emailSha256 | string | Pass a SHA-256-hashed email. Only use when the raw email cannot be provided — do not pass both email and emailSha256. (iOS path only.) |
mobileSha256 | string | Pass a SHA-256-hashed mobile number. Only use when the raw mobile number cannot be provided — do not pass both mobile and mobileSha256. (iOS path only.) |
To identify the user:
-
Create an
identifyRequestobject to contain the user's identifiers. You should integrate the user's raw, unhashed email address into theUserIdentity.Emailfield. -
To set additional user attributes, use the
AddSuccessListenercallback on the identify result. If theidentifyRequestsucceeds, any user attributes you set inside the listener are assigned to the identified user. -
After creating the
identifyRequest, send it to Rokt usingMParticle.Instance.Identity.Identify.For example, to identify a user named Jane Smith with the email address
j.smith@example.com, mobile number+13125551515, and customer IDcust_10482, you would use:Identify Jane Smith// 1. Create the identifyRequest object
var identifyRequest = new IdentityApiRequest();
identifyRequest.UserIdentities = new Dictionary<UserIdentity, string>()
{
#if __ANDROID__
// Preferred: pass the customer's raw, unhashed email.
// If you can only provide a SHA-256-hashed email, use UserIdentity.Other instead — do not pass both.
{ UserIdentity.Email, "j.smith@example.com" },
{ UserIdentity.Other, "SHA-256 hashed email" }, // only if raw email unavailable
// If you can only provide a SHA-256-hashed mobile number, use Other2 instead of MobileNumber — do not pass both.
{ UserIdentity.Other2, "SHA-256 hashed mobile number" }, // only if raw mobile unavailable
{ UserIdentity.MobileNumber, "+13125551515" },
{ UserIdentity.CustomerId, "cust_10482" }
#elif __IOS__
// Preferred: pass the customer's raw, unhashed email.
// If you can only provide a SHA-256-hashed email, use UserIdentity.Other instead — do not pass both.
{ UserIdentity.Email, "j.smith@example.com" },
{ UserIdentity.Other, "SHA-256 hashed email" }, // only if raw email unavailable
// Customer phone number in E.164 format.
{ UserIdentity.MobileNumber, "+13125551515" },
// If you can only provide a SHA-256-hashed mobile number, use Other4 instead of MobileNumber — do not pass both.
{ UserIdentity.Other2, "SHA-256 hashed mobile number" }, // only if raw mobile unavailable
{ UserIdentity.CustomerId, "cust_10482" }
#endif
};
// 2. User attributes are set using the AddSuccessListener callback
// 3. Call the identify method, including the identifyRequest object
MParticle.Instance.Identity.Identify(identifyRequest)
.AddSuccessListener(result =>
{
result.User.SetUserAttribute("firstname", "Jane");
result.User.SetUserAttribute("lastname", "Smith");
});
4. Set User Attributes4. Set User Attributes への直接リンク
Set user attributes progressively as the user navigates your app, not just at checkout. The more attributes you set, the better Rokt can resolve the customer and deliver relevant offers.
using mParticle.MAUI;
// Retrieve the current user. This will only succeed if you have identified the user during SDK+ initialization or by calling the identify method.
var currentUser = MParticle.Instance.Identity.CurrentUser;
// Once you have successfully set the current user, you can set user attributes with:
currentUser.SetUserAttribute("custom-attribute-name", "custom-attribute-value");
// Note: all user attributes (including list attributes and tags) must have distinct names.
// Rokt recommends setting as many of the following user attributes as possible:
currentUser.SetUserAttribute("firstname", "John");
currentUser.SetUserAttribute("lastname", "Doe");
// Phone numbers can be formatted either as '1234567890', or '+1 (234) 567-8901'
currentUser.SetUserAttribute("mobile", "3125551515");
currentUser.SetUserAttribute("age", "33");
currentUser.SetUserAttribute("gender", "M");
currentUser.SetUserAttribute("billingcity", "Brooklyn");
currentUser.SetUserAttribute("billingstate", "NY");
currentUser.SetUserAttribute("billingzipcode", "123456");
currentUser.SetUserAttribute("dob", "yyyymmdd");
currentUser.SetUserAttribute("title", "Mr");
currentUser.SetUserAttribute("language", "en");
currentUser.SetUserAttribute("predictedltv", "136.23");
// You can create a user attribute to contain a list of values
currentUser.SetUserAttribute("favorite-genres", string.Join(", ", new string[] { "documentary", "comedy", "romance", "drama" }));
// To remove a user attribute, call RemoveUserAttribute and pass in the attribute name.
currentUser.RemoveUserAttribute("attribute-to-remove");
User AttributesUser Attributes への直接リンク
Set as many of the following as you can collect:
Show all user attributes
| Field | Type | Description |
|---|---|---|
firstname | string | Customer's first name. Used for personalization. |
lastname | string | Customer's last name. Used for personalization. |
mobile | string | Phone number formatted as 1112345678 or +1 (222) 345-6789. Used for identity resolution and relevance. |
age | integer | Customer's age. Alternate to dob. Used for eligibility and relevance. |
dob | string | Date of birth, yyyymmdd. Alternate to age. Used for eligibility and relevance. |
gender | string | Customer's gender. For example, M, F, Male, or Female. Used for relevance. |
title | string | Honorific. For example, Mr, Mrs, Ms. Used for personalization. |
language | string | ISO 639-1 language code associated with the purchase. Used for relevance. |
billingcity | string | Billing city. Used for relevance. |
billingstate | string | Billing state / province / region. Used for relevance and eligibility. |
billingzipcode | string | Full ZIP or postcode (US preference is ZIP+4). Used for identity resolution and relevance. |
billingaddress1 | string | Billing street address line 1. Used for identity resolution and relevance. |
billingaddress2 | string | Billing street address line 2. Used for identity resolution. |
country | string | ISO 3166-1 alpha-2 country code (e.g. US, GB, AU). Used for eligibility and relevance. |
birthyear | integer | Customer's birth year (e.g. 1990). Used for eligibility and relevance. |
newcustomer | boolean | Whether this is a first-time buyer. Used for relevance. |
customertype | string | Whether the user is authenticated (guest / logged_in). Used for relevance. |
loyaltytier | string | Partner loyalty program tier. Used for relevance and eligibility. |
loyaltyid | string | Loyalty program member ID. Used for identity resolution. |
predictedltv | decimal | Predicted total lifetime value, typically from a partner ML model. Used for relevance. |
subscriptionstatus | string | Subscription state if applicable (active, trial, churned, paused, none). Used for relevance and eligibility. |
customersegment | string | Partner internal segmentation (e.g. vip, at_risk, new, reactivated). Used for relevance. |
acquisitionchannel | string | Channel through which the customer was acquired. Used for relevance. |
All user attributes (including list attributes) must have distinct names.
5. Track Funnel Events5. Track Funnel Events への直接リンク
Track screen views, account lifecycle events, commerce events, and custom events so Rokt can maintain identity continuity and understand where each customer is in their journey.
Screen ViewsScreen Views への直接リンク
Call MParticle.Instance.LogScreen with the name of the screen (e.g. "homepage", "product detail page"). Include any additional custom attributes in the info dictionary.
MParticle.Instance.LogScreen(
"homepage",
new Dictionary<string, string>() { { "custom-attribute", "custom-value" } }
);
Account Lifecycle EventsAccount Lifecycle Events への直接リンク
Log account lifecycle events when the user signs up, logs in, or logs out so Rokt can maintain identity continuity across sessions and devices. Signup and login events accept a method attribute describing how the user signed up or logged in.
Supported lifecycle event typesSupported lifecycle event types への直接リンク
Show lifecycle event types
| Lifecycle Event Type | When to trigger | Supported method values |
|---|---|---|
sign_up | New account created | email, social, guest |
login | User logs in | email, social, sso |
logout | User logs out | Not applicable. |
Example lifecycle eventsExample lifecycle events への直接リンク
// Signup event
MParticle.Instance.LogEvent(
"sign_up",
EventType.Other,
new Dictionary<string, string>() { { "method", "email" } }
);
// Login event
MParticle.Instance.LogEvent(
"login",
EventType.Other,
new Dictionary<string, string>() { { "method", "email" } }
);
// Logout event
MParticle.Instance.LogEvent("logout", EventType.Other, null);
Commerce EventsCommerce Events への直接リンク
Commerce events carry product-level details for the user's journey. Trigger a separate commerce event for each product action the customer takes.
Investing in full commerce event coverage is one of the highest-leverage things you can do during your integration. Each event tells Rokt something different about where the customer is in their journey: a product view signals exploration, an add-to-cart signals consideration, a checkout start signals purchase intent, and a completed purchase confirms conversion. With a richer signal, Rokt can personalize offers more effectively, measure placement performance accurately, and attribute conversions to the right touchpoints. Doing this work during your initial integration also avoids a retrofit later. The signal compounds over time: each event Rokt receives adds context used to sharpen personalization, improve attribution accuracy, and better resolve and segment your customer base on future visits.
Commerce events are logged with CommerceEvent, using a product action constant that identifies the customer action (viewing a product, adding to cart, starting checkout, completing a purchase, etc.). The sections below list the supported action types and walk through assembling the event.
Product action typesProduct action types への直接リンク
Show all product action types
| Customer action | Product action constant |
|---|---|
| Product detail page viewed | ProductAction.ViewDetail |
| Product clicked | ProductAction.Click |
| Item added to cart | ProductAction.AddToCart |
| Item removed from cart | ProductAction.RemoveFromCart |
| Item added to wishlist | ProductAction.AddToWishlist |
| Item removed from wishlist | ProductAction.RemoveFromWishlist |
| Checkout flow initiated | ProductAction.Checkout |
| Checkout option selected | ProductAction.CheckoutOption |
| Order confirmed | ProductAction.Purchase |
| Order refunded | ProductAction.Refund |
Tracking a commerce event requires three steps: