MAUI SDK Integration Guide
This page explains how to implement the MAUI SDK for Rokt Ecommerce to deliver more relevant customer experiences at checkout. The SDK allows you to trigger and track these experiences (like displaying offers on confirmation pages) by firing on configured pages and passing user and transaction data back to Rokt for personalization and measurement.
Your dedicated account representative will help configure your account for the MAUI SDK. They will provide you with a key and secret for both Android and iOS, which are required to initialize the SDK and additional resources needed to render the most relevant experiences for your customers.
These instructions require development resources to complete. If you require additional assistance, please reach out to your Rokt account manager.
1. Add the Rokt SDK to your app
dotnet add package mParticle.MAUI
dotnet add package mParticle.MAUI.Kits.Rokt
2. Initialize the Rokt SDK
To initialize the SDK, insert the following initialization snippet in your AppDelegate file:
- Make sure to replace
your-keyandyour-secretwith the key and secret provided by your dedicated 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();
// If you're using an un-hashed email address, set it in 'email'.
identifyRequest.UserIdentities = new Dictionary<UserIdentity, string>()
{
{ UserIdentity.Email, "j.smith@example.com" }
};
// 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);
For Android you also need to ensure your activty extends MauiAppCompatActivity
2.1 Identify the User on initialization
When the SDK is initialized, it can identify the current user so that any collected data is correctly attributed to them and to ensure they are shown the most relevant ads based on their behavior.
The SDK initialization script includes an object called identifyRequest:
var identifyRequest = new IdentityApiRequest();
identifyRequest.UserIdentities = new Dictionary<UserIdentity, string>()
{
{ UserIdentity.Email, "j.smith@example.com" }
};
options.IdentifyRequest = identifyRequest;
2.2 Set additional user attributes
The initialization script includes a callback function that allows you to set additional user attributes for the user if they are successfully identified with their email address:
OnUserIdentified onIdentifyComplete = newUser =>
{
if (newUser != null)
{
newUser.SetUserAttribute("example attribute key", "example attribute value");
}
};
options.IdentityStateListener = onIdentifyComplete;
3. Identify the User as data becomes available
Whenever the user provides their email address after the SDK has initialized (for example, when they log in or make a purchase), you should call the identify method to pass their email to Rokt. This ensures that data is correctly attributed to the current user.
3.1 Create an identifyRequest
To identify the user, first create an identifyRequest object to contain the user’s email address.
If you are providing an un-hashed email address, use:
var identifyRequest = new IdentityApiRequest();
identifyRequest.UserIdentities = new Dictionary<UserIdentity, string>()
{
{ UserIdentity.Email, "j.smith@example.com" }
};
3.2 Call the identify method
Finally, after creating your identifyRequest, to set any additional attributes, call the Identify method, passing in the identifyRequest object you just created:
MParticle.Instance.Identity.Identify(identifyRequest);
For example, to identify a user named Jane Smith with the email address j.smith@example.com (and you don't need to hash their email address) you would use:
var identifyRequest = new IdentityApiRequest();
identifyRequest.UserIdentities = new Dictionary<UserIdentity, string>()
{
{ UserIdentity.Email, "j.smith@example.com" }
};
MParticle.Instance.Identity.Identify(identifyRequest)
.AddSuccessListener(success =>
{
success.User.SetUserAttribute("example attribute key", "example attribute value");
});