Skip to main content

Android SDK+ Integration Guide

This page explains how to implement the Rokt Ecommerce Android 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.

tip

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 Android AppDirect link to 1. Add the Rokt SDK+ to Your Android App

Update your Gradle file to include the necessary dependencies:

dependencies {
implementation("com.mparticle:android-rokt-kit:5.77.0")
implementation("com.mparticle:android-core:5.77.0")
}

2. Initialize the Rokt SDK+Direct link to 2. Initialize the Rokt SDK+

Insert the following initialization snippet in the onCreate() method of your Application class. The mParticle Android 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.

Application.onCreate initialization
import com.mparticle.MParticle
import com.mparticle.MParticleOptions

class YourApplicationClass : Application() {
override fun onCreate() {
super.onCreate()

// Identify the current user:
// If you do not have the user's email address, you can pass in a null value
val identifyRequest = IdentityApiRequest.withEmptyUser()
// Preferred: pass the customer's raw, unhashed email via .email().
// If you can only provide a SHA-256-hashed email, remove .email() and use .userIdentity(Other) instead — do not pass both.
.email("j.smith@example.com")
.userIdentity(MParticle.IdentityType.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(MParticle.IdentityType.Other2, "SHA-256 hashed mobile number") // only if raw mobile unavailable
// Customer phone number in E.164 format.
.userIdentity(MParticle.IdentityType.MobileNumber, "+13125551515")
// Partner's internal customer/account identifier (if the user is logged in).
.customerId("cust_10482")
.build()

// If the user is identified with their email address, set additional user attributes.
val identifyTask = BaseIdentityTask()
.addSuccessListener { identityApiResult ->
val user = identityApiResult.user
user.setUserAttribute("example attribute key", "example attribute value")
}

val options: MParticleOptions = MParticleOptions.builder(this)
.credentials(
"your-key", // The key provided by your Rokt account manager
"your-secret" // The secret provided by your Rokt account manager
)
// 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.
.environment(MParticle.Environment.Development)
.identify(identifyRequest)
.identifyTask(identifyTask)
.build()

MParticle.start(options)
}
}

When inserting the initialization snippet into your Application class, you will see customizable fields for:

  1. Entering your Rokt key and secret.

    Set your-key and your-secret inside credentials to the key and secret values provided by your Rokt account manager.

  2. Setting your data environment.

    Set environment to MParticle.Environment.Development while testing to route data to the Development environment, and MParticle.Environment.Production to send live customer activity to Production.

  3. Identifying your user and setting attributes.

    In identifyRequest, pass the user's raw, un-hashed email via .email(). For hashed emails and other identifiers, see Supported User Identifiers. Once identified, use the identifyTask success listener to set additional user attributes — see User Attributes for the recommended list.

    identifyTask success listener
    val identifyTask = BaseIdentityTask()
    .addSuccessListener { identityApiResult ->
    val user = identityApiResult.user
    user.setUserAttribute("example attribute key", "example attribute value")
    }
    note

    Always include identifyRequest in the initialization snippet. If you don't have the user's email at initialization, omit the .email() call — the SDK+ will still initialize, and you can identify the user later via 3. Identify the User. See Error Handling for how to handle the addFailureListener callback — without error handling you may see data consistency issues at scale.

Initializing with FontsDirect link to Initializing with Fonts

Instead of or in addition to supplying fonts on One Platform, you may use fonts already bundled with your application. This removes the potential for fonts to be downloaded at initialization time, reducing network utilization and the chance of download errors.

Using font assetsDirect link to Using font assets

Pass a map to the roktOptions builder method that maps font PostScript names to their filepath in the assets directory. Check with your account manager if you are unsure of the PostScript names being used in your layout.

Font assets
import com.mparticle.MParticle
import com.mparticle.MParticleOptions

class YourApplication : Application() {
override fun onCreate() {
super.onCreate()
val options: MParticleOptions = MParticleOptions.builder(this)
.credentials("your-key", "your-secret")
.environment(MParticle.Environment.Development)
.roktOptions(RoktOptions(fontFilePathMap = mapOf("Arial-Bold" to "fonts/arialbold.otf")))
.build()
MParticle.start(options)
}
}

3. Identify the UserDirect link to 3. Identify the User

Call MParticle.getInstance()?.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 IdentifiersDirect link to Supported User Identifiers

Show supported user identifiers
FieldTypeDescription
emailstringPass the customer's raw, unhashed email address via .email("j.smith@example.com").
mobilestringPass the customer's phone number in E.164 format via .userIdentity(MParticle.IdentityType.MobileNumber, "+13125551515").
customeridstringPass your internal customer/account identifier via .customerId("cust_10482"). Send on every screen for logged-in users.
otherstringPass a SHA-256-hashed email via .userIdentity(MParticle.IdentityType.Other, "hashed email"). Only use when the raw email cannot be provided.
other2stringPass a SHA-256-hashed mobile number via .userIdentity(MParticle.IdentityType.Other2, "hashed mobile").

To identify the user:

  1. Create an identifyRequest object to contain the user's identifiers. You should integrate the user's raw, unhashed email address into the email field.

  2. To set additional user attributes, create an identifyTask success listener. If the identifyRequest succeeds, then any user attributes you set inside the listener are assigned to the identified user.

  3. After creating the identifyRequest and the identifyTask, send them to Rokt using the MParticle.getInstance()?.Identity()?.identify method.

    For example, to identify a user named Jane Smith with the email address j.smith@example.com, mobile number +13125551515, and customer ID cust_10482, you would use:

    Identify Jane Smith
    // 1. Create the identifyRequest object
    val identifyRequest = IdentityApiRequest.withEmptyUser()
    // Preferred: pass the customer's raw, unhashed email via .email().
    // If you can only provide a SHA-256-hashed email, remove .email() and use .userIdentity(Other) instead — do not pass both.
    .email("j.smith@example.com")
    .userIdentity(MParticle.IdentityType.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(MParticle.IdentityType.Other2, "SHA-256 hashed mobile number") // only if raw mobile unavailable
    .userIdentity(MParticle.IdentityType.MobileNumber, "+13125551515")
    .customerId("cust_10482")
    .build()

    // 2. User attributes are set using the identifyTask success listener
    val identifyTask = BaseIdentityTask()
    .addSuccessListener { identityApiResult ->
    val user = identityApiResult.user
    user.setUserAttribute("firstname", "Jane")
    user.setUserAttribute("lastname", "Smith")
    }

    // 3. Call the identify method, including the identifyRequest object and identifyTask
    MParticle.getInstance()?.Identity()?.identify(identifyRequest, identifyTask)

4. Set User AttributesDirect link to 4. 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.

Set user attributes
import com.mparticle.MParticle

// Retrieve the current user. This will only succeed if you have identified the user during SDK+ initialization or by calling the identify method.
val currentUser = MParticle.getInstance()?.Identity()?.currentUser

// Once you have successfully set the current user to `currentUser`, 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?.setUserAttributeList("favorite-genres", listOf("documentary", "comedy", "romance", "drama"))

// To remove a user attribute, call removeUserAttribute and pass in the attribute name. All user attributes share the same key space.
currentUser?.removeUserAttribute("attribute-to-remove")

User AttributesDirect link to User Attributes

Set as many of the following as you can collect:

Show all user attributes
FieldTypeDescription
firstnamestringCustomer's first name. Used for personalization.
lastnamestringCustomer's last name. Used for personalization.
mobilestringPhone number formatted as 1112345678 or +1 (222) 345-6789. Used for identity resolution and relevance.
birthyearintegerCustomer's birth year (e.g. 1990). Preferred date-of-birth field. Alternates: dob, age. Used for eligibility and relevance.
ageintegerCustomer's age. Alternate to dob. Used for eligibility and relevance.
dobstringDate of birth, yyyymmdd. Alternate to age. Used for eligibility and relevance.
genderstringCustomer's gender. For example, M, F, Male, or Female. Used for relevance.
titlestringHonorific. For example, Mr, Mrs, Ms. Used for personalization.
languagestringISO 639-1 language code associated with the purchase. Used for relevance.
billingaddress1stringStreet address (e.g. 123 Main St). Used for identity resolution and relevance.
billingaddress2stringApartment/unit (e.g. Apt 4B). Used for identity resolution.
billingcitystringBilling city. Used for relevance.
billingstatestringBilling state / province / region. Used for relevance and eligibility.
billingzipcodestringFull ZIP or postcode (US preference is ZIP+4). Used for identity resolution and relevance.
countrystringISO 3166-1 alpha-2 country code (e.g. US, GB, AU). Used for eligibility and relevance.
newcustomerbooleanWhether this is a first-time buyer. Used for relevance.
customertypestringWhether the user is authenticated (guest / logged_in). Used for relevance.
loyaltytierstringPartner loyalty program tier. Used for relevance and eligibility.
loyaltyidstringLoyalty program member ID. Used for identity resolution.
predictedltvdecimalPredicted total lifetime value, typically from a partner ML model. Used for relevance.
subscriptionstatusstringSubscription state if applicable (active, trial, churned, paused, none). Used for relevance and eligibility.
customersegmentstringPartner internal segmentation (e.g. vip, at_risk, new, reactivated). Used for relevance.
acquisitionchannelstringHow the customer was originally acquired. Used for relevance.

All user attributes (including list attributes) must have distinct names.

5. Track Funnel EventsDirect link to 5. 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 ViewsDirect link to Screen Views

Call MParticle.getInstance()?.logScreen() with the name of the screen (e.g. "homepage", "product detail page"). Include any additional custom attributes in the info map.

Log a screen view
MParticle.getInstance()?.logScreen(
"homepage",
mapOf("custom-attribute" to "custom-value")
)

Account Lifecycle EventsDirect link to Account 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 typesDirect link to Supported lifecycle event types

Show lifecycle event types
Lifecycle Event TypeWhen to triggerSupported method values
sign_upNew account createdemail, social, guest
loginUser logs inemail, social, sso
logoutUser logs outNot applicable.

Example lifecycle eventsDirect link to Example lifecycle events

Signup, login, logout
// Signup event
val signupEvent = MPEvent.Builder("sign_up", EventType.Other)
.customAttributes(mapOf("method" to "email"))
.build()
MParticle.getInstance()?.logEvent(signupEvent)

// Login event
val loginEvent = MPEvent.Builder("login", EventType.Other)
.customAttributes(mapOf("method" to "email"))
.build()
MParticle.getInstance()?.logEvent(loginEvent)

// Logout event
val logoutEvent = MPEvent.Builder("logout", EventType.Other).build()
MParticle.getInstance()?.logEvent(logoutEvent)

Commerce EventsDirect link to Commerce 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 typesDirect link to Product action types

Show all product action types
Customer actionProduct action constant
Product detail page viewedProduct.VIEW_DETAIL
Product clickedProduct.CLICK
Item added to cartProduct.ADD_TO_CART
Item removed from cartProduct.REMOVE_FROM_CART
Item added to wishlistProduct.ADD_TO_WISHLIST
Item removed from wishlistProduct.REMOVE_FROM_WISHLIST
Checkout flow initiatedProduct.CHECKOUT
Checkout option selectedProduct.CHECKOUT_OPTION
Order confirmedProduct.PURCHASE
Order refundedProduct.REFUND

Tracking a commerce event requires three steps:

1. Define the productDirect link to 1. Define the product

Create a Product with the product's name, SKU, and price. Set additional fields using the builder.

Define a product
import com.mparticle.commerce.Product

val product = Product.Builder("Double Room - Econ Rate", "econ-1", 100.00)
.quantity(4.0)
.category("room")
.brand("lodge-o-rama")
.variant("standard")
// Add optional custom attributes as key/value pairs
.customAttributes(mapOf("ocean-view" to "true", "balcony" to "false"))
.build()

2. Summarize the transactionDirect link to 2. Summarize the transaction

Create a TransactionAttributes object for Product.PURCHASE, Product.CHECKOUT, and Product.CHECKOUT_OPTION events. Include shipping and coupon code when applicable — order-level coupons belong here, not on individual products.

Summarize the transaction
import com.mparticle.commerce.TransactionAttributes

val transactionAttributes = TransactionAttributes("ORDER-12345")
.setRevenue(149.99)
.setTax(12.50)
.setShipping(5.99)
.setCouponCode("SUMMER20")

3. Log the commerce eventDirect link to 3. Log the commerce event

Create a CommerceEvent with a product action constant from the table above, attach the transactionAttributes, and log it.

Log a Purchase commerce event
import com.mparticle.commerce.CommerceEvent
import com.mparticle.commerce.Product

val event = CommerceEvent.Builder(Product.PURCHASE, product)
.transactionAttributes(transactionAttributes)
.customAttributes(mapOf("sale" to "true"))
.build()

MParticle.getInstance()?.logEvent(event)

The same structure applies to every product action constant — swap Product.PURCHASE for the action that matches the customer behavior you're logging. See the Product action types table for the full list.

Custom EventsDirect link to Custom Events

Track custom events using MPEvent.Builder, passing an event name, event type, and optional custom attributes.

Supported custom event typesDirect link to Supported custom event types

Show custom event types
TypeUse for
EventType.NavigationUser navigation flows and screen transitions within your app.
EventType.LocationLocation-based interactions and movements.
EventType.SearchSearch queries and search-related actions.
EventType.TransactionFinancial transactions and purchase-related activity.
EventType.UserContentUser-generated content like reviews, comments, or posts.
EventType.UserPreferenceUser settings, preferences, and customization choices.
EventType.SocialSocial media interactions and sharing activities.
EventType.OtherAnything that doesn't fit the categories above.

Example custom eventDirect link to Example custom event

Log a custom event
val event = MPEvent.Builder("Video Watched", EventType.Navigation)
.customAttributes(mapOf("category" to "Destination Intro", "title" to "Paris"))
.build()

MParticle.getInstance()?.logEvent(event)

6. Show a PlacementDirect link to 6. Show a Placement

Call selectPlacements on every payment and confirmation screen you want Rokt to render content on. Include one of the following page identifiers to specify the screen type and whether it's for testing or production:

  • stg.rokt.conf: A confirmation screen in a staging (or testing) environment.
  • prod.rokt.conf: A confirmation screen in a production environment.
  • stg.rokt.payments: A payments screen in a staging (or testing) environment.
  • prod.rokt.payments: A payments screen in a production environment.

Placement AttributesDirect link to Placement Attributes

Pass these attributes in the attributes map of selectPlacements. Always supply the most recent value — attributes passed here override any earlier setUserAttribute calls.

Show all placement attributes
FieldTypeDescription
emailstringCustomer email (unhashed). Used for identity resolution.
firstnamestringCustomer first name. Used for personalization.
lastnamestringCustomer last name. Used for personalization.
mobilestringCustomer mobile number in E.164 format. Used for identity resolution.
confirmationrefstringOrder / confirmation reference number. Used for relevance and deduplication.
currencystringTransaction currency (ISO 4217, e.g. USD, GBP, AUD). Used for relevance.
countrystringISO 3166-1 alpha-2 country code. Used for eligibility and relevance.
languagestringCustomer's preferred language (ISO 639-1). Used for relevance.
totalpricedecimalTotal cart value including tax and shipping. Used for relevance.
amountdecimalCart subtotal before tax and shipping. Distinct from totalprice. Used for relevance.
cartItemsarrayStructured array of cart-line objects. Must be camelCase. Used for relevance.
couponcodestringPromo code applied to the order, if any. Used for relevance.
newcustomerbooleanWhether this is a first-time buyer. Used for relevance.
customertypestringguest or logged_in. Used for relevance.
valuedecimalCustomer's cumulative purchase value. Used for relevance.
subscriptionstatusstringSubscription state if applicable (active, trial, churned, paused, none). Used for relevance and eligibility.
customersegmentstringPartner internal segmentation (e.g. vip, at_risk, new, reactivated). Used for relevance.
paymenttypestringPayment method selected (credit_card, paypal, apple_pay, etc.). Used for Pay+ eligibility.
paymentServiceProviderstringPayment services offered on the screen (single value, e.g. apple_pay, paypal, cardpayment). Must be camelCase. Used for Pay+ eligibility.
ccbinstringCredit card BIN (first 6 digits). Used for relevance.
billingaddress1stringBilling street address. Used for identity resolution and relevance.
billingaddress2stringBilling apartment / unit. Used for identity resolution.
billingcitystringBilling city. Used for relevance.
billingstatestringBilling state or province. Used for relevance.
billingzipcodestringBilling ZIP / postcode. Used for identity resolution and relevance.
billingnamestringFull cardholder name on the billing address. Used for identity resolution.
shippingmethodstringShipping method selected (standard, express, next_day). Used for relevance.
shippingnamestringFull recipient name on the shipping address. Used for relevance.
shippingaddress1stringShipping street address. Used for relevance.
shippingcitystringShipping city. Used for relevance.
shippingstatestringShipping state or province. Used for relevance.
shippingzipcodestringShipping ZIP or postcode. Used for relevance.
shippingcountrystringShipping country (ISO 3166-1 alpha-2). Used for relevance.
partnerpaymentreferencestringNon-guessable identifier for the customer's vaulted payment method. Used for Shoppable Ads card forwarding.
last4digitsstringLast 4 digits of the card used. Used for identity resolution.
plccstring"yes" or "no" — whether the customer has a private-label credit card. Used for Pay+ relevance.
discountamountdecimalOrder-level discount applied. Used for Pay+ relevance.
prescreenstring"yes" or "no" — whether the customer has pre-qualified for a credit offer. Used for Pay+ relevance.
adsExperiencestringPass "shoppable" when targeting a Shoppable Ads experience. Must be camelCase.

Overlay PlacementsDirect link to Overlay Placements

Overlay placements render on top of your confirmation screen in a Rokt-managed container, requiring no changes to your app's existing layout.

To insert an overlay placement, call selectPlacements once the confirmation screen loads:

Overlay placement
import com.mparticle.MParticle
import com.mparticle.rokt.RoktConfig

val attributes = mapOf(
// Identity
"email" to "j.smith@example.com",
"firstname" to "Jenny",
"lastname" to "Smith",
"mobile" to "+13125551515",

// Transaction
"confirmationref" to "54321",
"currency" to "USD",
"country" to "US",
"language" to "en",
"totalprice" to "149.99",
"couponcode" to "SUMMER20",

// Customer context
"newcustomer" to "false",
"customertype" to "logged_in",
"value" to "2340.00",
"subscriptionstatus" to "active",
"customersegment" to "vip",

// Payment (include paymenttype and paymentServiceProvider for Pay+)
"paymenttype" to "credit_card",
"paymentServiceProvider" to "card",
"ccbin" to "411112",

// Billing address
"billingaddress1" to "123 Main St",
"billingcity" to "Brooklyn",
"billingstate" to "NY",
"billingzipcode" to "11201",

// Shipping
"shippingmethod" to "express",
"shippingaddress1" to "175 Varick St",
"shippingcity" to "New York",
"shippingstate" to "NY",
"shippingzipcode" to "10014",
"shippingcountry" to "US"
)

val roktConfig = RoktConfig.Builder().colorMode(RoktConfig.ColorMode.LIGHT).build()

MParticle.getInstance()?.Rokt()?.selectPlacements(
identifier = "RoktExperience",
attributes = attributes,
config = roktConfig
)

Embedded PlacementsDirect link to Embedded Placements

Embedded placements render inline at a fixed position in your app that you control (for example, above the payment options on a cart screen). Both Thanks and Pay+ use embedded placements, but Pay+ must use embedded placements.

Add the RoktEmbeddedView to your layout XML at the position where you want the placement to render. Set its height to wrap_content so the placement can resize dynamically.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.mparticle.rokt.RoktEmbeddedView
android:id="@+id/roktEmbeddedView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Use the MpRoktEventCallback interface to respond to placement events (load, unload, loading indicator state, etc.).

Embedded placement with callbacks
import com.mparticle.rokt.RoktConfig
import com.mparticle.rokt.RoktEmbeddedView
import com.mparticle.MpRoktEventCallback
import com.mparticle.UnloadReasons

class ConfirmActivity : Activity() {
val callbacks = object : MpRoktEventCallback {
override fun onLoad() {
// Optional callback for when the Rokt placement loads
}

override fun onUnload(reason: UnloadReasons) {
// Optional callback for when the Rokt placement unloads
}

override fun onShouldShowLoadingIndicator() {
// Optional callback to show a loading indicator
}

override fun onShouldHideLoadingIndicator() {
// Optional callback to hide a loading indicator
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val attributes = mapOf(
"email" to "j.smith@example.com",
"firstname" to "Jenny",
"lastname" to "Smith",
"billingzipcode" to "90210",
"confirmationref" to "54321"
)

val roktWidget = findViewById<RoktEmbeddedView>(R.id.roktEmbeddedView)
val embeddedViews = mapOf("RoktEmbedded1" to WeakReference(roktWidget))
val roktConfig = RoktConfig.Builder().colorMode(RoktConfig.ColorMode.LIGHT).build()

MParticle.getInstance()?.Rokt()?.selectPlacements(
identifier = "RoktExperience",
attributes = attributes,
callbacks = callbacks,
embeddedViews = embeddedViews,
config = roktConfig
)
}
}
Pay+

For Pay+ placements, include paymenttype and paymentServiceProvider in the selectPlacements call on each screen. paymentServiceProvider communicates what payment methods are available on the payment screen; paymenttype communicates what method the user paid with.

Optional FunctionsDirect link to Optional Functions

FunctionPurpose
Rokt.close()Auto-close overlay placements.

Additional ConfigurationDirect link to Additional Configuration

Pass optional parameters such as RoktConfig to customize the placement UI (e.g. dark/light mode, caching). Font typefaces can also be supplied as a map of PostScript names to Typeface objects.

selectPlacements with RoktConfig and font typefaces
val fontTypefaces: MutableMap<String, WeakReference<android.graphics.Typeface>> = HashMap()
fontTypefaces["Arial-Bold"] = WeakReference(yourTypefaceObject)

val roktConfig = RoktConfig.Builder().colorMode(RoktConfig.ColorMode.LIGHT).build()

MParticle.getInstance()?.Rokt()?.selectPlacements(
identifier = "RoktExperience",
attributes = attributes,
fontTypefaces = fontTypefaces,
config = roktConfig
)
note

If you want to update the identifier RoktExperience or embedded identifier RoktEmbedded1 with a different value, contact your Rokt account manager to ensure Rokt placements are configured consistently.

Events APIDirect link to Events API

The SDK+ provides placement lifecycle events as a stream through the MParticle.getInstance()?.Rokt()?.events API. Use Kotlin Flow to consume events produced by the SDK+.

Subscribe to placement events
import com.mparticle.MParticle

// owner: LifecycleOwner
owner.lifecycleScope.launch {
owner.lifecycle.repeatOnLifecycle(Lifecycle.State.CREATED) {
MParticle.getInstance()?.Rokt()?.events("RoktExperience")?.collect { roktEvent ->
// Handle the event
}
}
}

Standard eventsDirect link to Standard events

Show all standard events
EventDescriptionParams
ShowLoadingIndicatorTriggered before the SDK+ calls the Rokt backend.
HideLoadingIndicatorTriggered when the SDK+ receives a success or failure from the Rokt backend.
PlacementInteractiveTriggered when a placement has been rendered and is interactable.placementId: String
PlacementReadyTriggered when a placement is ready to display but has not rendered content yet.placementId: String
OfferEngagementTriggered when the user engages with the offer.placementId: String
PositiveEngagementTriggered when the user positively engages with the offer.placementId: String
FirstPositiveEngagementTriggered when the user positively engages with the offer for the first time.placementId: String, fulfillmentAttributes: FulfillmentAttributes
OpenUrlTriggered when the user presses a URL that is configured to be sent to the partner app.placementId: String, url: String
PlacementClosedTriggered when a placement is closed by the user.placementId: String
PlacementCompletedTriggered when the offer progression reaches the end and no more offers are available to display. Also triggered when cache is hit but the retrieved placement will not be displayed as it has previously been dismissed.placementId: String
PlacementFailureTriggered when a placement could not be displayed due to some failure or when no placements are available to show.placementId: String (optional)
CartItemInstantPurchaseTriggered when the catalog item purchase is initiated by the user.placementId: String, cartItemId: String, catalogItemId: String, currency: String, description: String, linkedProductId: String, totalPrice: Double, quantity: Int, unitPrice: Double

Global eventsDirect link to Global events

Use Rokt.globalEvents() to subscribe to SDK+-level events that are not tied to a specific placement.

Subscribe to global events
import com.rokt.roktsdk.RoktEvent

// owner: LifecycleOwner
owner.lifecycleScope.launch {
Rokt.globalEvents().collect { event ->
if (event is RoktEvent.InitComplete) {
// SDK+ initialization is complete
}
}
}

7. AppendixDirect link to 7. Appendix

Appendix A: App ConfigurationDirect link to Appendix A: App Configuration

Applications can pass configuration settings through RoktConfig so the Android SDK+ uses your app's custom configuration instead of system defaults.

ColorMode objectDirect link to ColorMode object

ValueDescription
LIGHTApplication is in Light Mode
DARKApplication is in Dark Mode
SYSTEMApplication defaults to System Color Mode

EdgeToEdgeDisplayDirect link to EdgeToEdgeDisplay

ValueDescription
true (default)Application supports Edge to Edge display mode
falseApplication does not support Edge to Edge display mode
RoktConfig with ColorMode and EdgeToEdgeDisplay
import com.mparticle.MParticle
import com.mparticle.rokt.RoktConfig

val roktConfig = RoktConfig.Builder()
.colorMode(RoktConfig.ColorMode.LIGHT)
.edgeToEdgeDisplay(true)
.build()

MParticle.getInstance()?.Rokt()?.selectPlacements(
identifier = "RoktExperience",
attributes = attributes,
config = roktConfig
)

CacheConfig objectDirect link to CacheConfig object

ParameterDescription
cacheDurationInSecondsOptional duration in seconds for which the Rokt SDK+ should cache the experience. Maximum allowed value is 90 minutes; default is 90 minutes if not provided or invalid.
cacheAttributesOptional attributes to be used as cache key. If null, all attributes sent in selectPlacements will be used as the cache key.
Cache for 1200 seconds
import com.mparticle.rokt.CacheConfig
import com.mparticle.rokt.RoktConfig

// Cache the experience for 1200 seconds, using email and orderNumber as the cache key.
val roktConfig = RoktConfig.Builder()
.cacheConfig(CacheConfig(
cacheDurationInSeconds = 1200,
cacheAttributes = mapOf("email" to "j.smith@example.com", "orderNumber" to "123")
))
.build()

MParticle.getInstance()?.Rokt()?.selectPlacements(
identifier = "RoktExperience",
attributes = attributes,
config = roktConfig
)

Appendix B: Jetpack Compose Support with RoktLayoutDirect link to Appendix B: Jetpack Compose Support with RoktLayout

For screens implemented using Jetpack Compose, the SDK+ provides the RoktLayout composable for a modern, declarative integration of Rokt placements. RoktLayout supports Overlay, BottomSheet, and Embedded placement types without manually invoking selectPlacements.

Jetpack Compose placement with RoktLayout
import com.mparticle.kits.RoktLayout
import com.mparticle.MpRoktEventCallback
import com.mparticle.UnloadReasons

@Composable
fun MainScreen(modifier: Modifier = Modifier) {
Column(
modifier = modifier
.background(Color.LightGray)
.padding(8.dp),
) {
val attributes = mapOf(
"email" to "j.smith@example.com",
"firstname" to "Jenny",
"lastname" to "Smith",
"billingzipcode" to "90210",
"confirmationref" to "54321"
)
val callbacks = object : MpRoktEventCallback {
override fun onLoad() = println("View loaded")
override fun onUnload(reason: UnloadReasons) = println("View unloaded due to: $reason")
override fun onShouldShowLoadingIndicator() = println("Show loading indicator")
override fun onShouldHideLoadingIndicator() = println("Hide loading indicator")
}
val roktConfig = RoktConfig.Builder()
.colorMode(RoktConfig.ColorMode.DARK)
.cacheConfig(CacheConfig(
cacheDurationInSeconds = 1200,
cacheAttributes = mapOf("email" to "j.smith@example.com")
))
.build()

RoktLayout(
sdkTriggered = true,
identifier = "RoktExperience",
attributes = attributes,
location = "RoktEmbedded1",
modifier = Modifier
.fillMaxWidth()
.background(Color.Black),
mpRoktEventCallback = callbacks,
config = roktConfig
)
}
}

ParametersDirect link to Parameters

ParameterTypeDescription
sdkTriggeredBooleanControls when the placement should be triggered.
identifierStringThe identifier of the Rokt experience (e.g. "RoktExperience").
locationString?Optional location name for embedded placements (e.g. "RoktEmbedded1").
attributesMap<String, String>Map of attributes to pass to the placement.
modifierModifierCompose Modifier to customize layout, styling, and UI behavior.
mpRoktEventCallbackMpRoktEventCallbackOptional callback to handle placement events (load, unload, loading state).
configRoktConfig?Optional configuration for color mode, caching, etc.

Appendix C: Error HandlingDirect link to Appendix C: Error Handling

The 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 — treat these APIs as gating operations to maintain a consistent user state. The SDK+ will not retry API calls automatically, but provides callback APIs so you can do so according to your business logic.

If you do not implement error handling, you may see data consistency issues at scale.

The SDK+ always returns the HTTP status and body of the underlying HTTP response. For client-side issues (device out of coverage, client-side timeout, invalid identity requests), the SDK+ returns IdentityApi.UNKNOWN_ERROR along with an informative error message.

IDSync error handling
MParticle.getInstance()?.Identity()?.identify(identifyRequest)
?.addFailureListener { identityHttpResponse ->
if (identityHttpResponse?.httpCode == IdentityApi.UNKNOWN_ERROR) {
// Device is likely offline — retry the request
} else if (identityHttpResponse?.httpCode == IdentityApi.THROTTLE_ERROR) {
// Throttled (429) — retry with backoff
}
}
?.addSuccessListener { identityApiResult ->
// Proceed with the identified user
}

Appendix D: Passing Session ID from Web to NativeDirect link to Appendix D: Passing Session ID from Web to Native

When a user journey spans both web and native platforms, you can maintain a consistent Rokt session by passing the session ID from the Web SDK+ to the mParticle Android SDK+. This is useful for hybrid flows where users complete an action in a WebView (such as a payment page) and return to the native app for confirmation.

Getting the session ID from Web SDK+Direct link to Getting the session ID from Web SDK+

After calling selectPlacements, the session ID is available on the selection context:

Retrieve sessionId from the selection context
const selection = await launcher.selectPlacements({
identifier: "checkout",
attributes: {
email: "user@example.com",
// ... other attributes
}
});

const sessionId = await selection.context.sessionId;

Pass the session ID to your native app using a deep link:

Deep-link to native app
const deepLink = `myapp://confirmation?sessionId=${encodeURIComponent(sessionId)}`;
window.location.href = deepLink;

Setting the session IDDirect link to Setting the session ID

Extract the session ID from the deep link and pass it to the mParticle SDK+ before calling selectPlacements.

Handle deep link and set sessionId
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

intent.data?.getQueryParameter("sessionId")?.let { sessionId ->
MParticle.getInstance()?.Rokt()?.setSessionId(sessionId)
}

// Proceed with your confirmation flow
}

NotesDirect link to Notes

  • Call setSessionId before selectPlacements to ensure the session is used.
  • Empty strings are ignored and will not update the session.
  • Always URL-encode the session ID when passing as a query parameter.

8. Test Your IntegrationDirect link to 8. Test Your Integration

To confirm the SDK+ initializes and events log correctly:

  1. Enable verbose SDK+ logging before initialization so you can see what's being sent.
  2. Build and run your app with environment = MParticle.Environment.Development.
  3. Trigger selectPlacements on the screen where the placement should render and confirm the placement loads.
  4. Verify events appear in your mParticle workspace's Live Stream, and confirm the identifyRequest call succeeds.
Enable verbose SDK+ logging
MParticle.setLogLevel(MParticle.LogLevel.VERBOSE)

TroubleshootingDirect link to Troubleshooting

If the placement doesn't render or events don't appear, check the Android Logcat for Rokt SDK+ errors. Common issues:

Initialization errorsDirect link to Initialization errors

  • Confirm credentials key and secret match the values from your Rokt account manager.
  • Confirm MParticle.start(options) runs in Application.onCreate() before any selectPlacements or logEvent call.

Identity errorsDirect link to Identity errors

If the identifyTask failure listener fires, see Error Handling for the IdentityApi error codes and retry guidance. Without error handling you may see data consistency issues at scale.

Placement not renderingDirect link to Placement not rendering

  • Confirm the placement identifier (e.g. RoktExperience) matches what your Rokt account manager configured.
  • For embedded placements, confirm the embedded view identifier (e.g. RoktEmbedded1) matches the layout configuration.
  • Check that the attributes map contains at least email, firstname, lastname, billingzipcode, and confirmationref.
Was this article helpful?