Skip to main content

Android UX Helper

Rokt UX Helper is an open source project that helps you render beautiful customer experiences in a server to server environment. You can find and contribute to the project on the Github page.

This document outlines the process for integrating the Rokt UX Helper into your Android app, which works alongside the Server-to-Server integration(S2S) to deliver relevant experiences to your customers as they checkout.

SystemVersion
UX Helper0.4.0
Android Version/API Level5.0+ (API Level 21)
Package ManagerMaven / Gradle
Compose BOM2024.09.02

Installation Guide

In your module (app-level) Gradle file (usually <project>/<app-module>/build.gradle.kts or <project>/<app-module>/build.gradle), add the Rokt UX Helper dependency.

build.gradle.kts
implementation("com.rokt:roktux:0.1.0")

Initialize RoktLayout

Add RoktLayout to your Compose view

// Retrieve the experience response from your server
val experienceResponse = viewModel.experienceResponse.collectAsState()

experienceResponse.value?.let { experienceResponse ->
RoktLayout(
experienceResponse = experienceResponse,
location = "RoktEmbedded1",
onUxEvent = { println("RoktEvent: UxEvent Received $it") },
onPlatformEvent = { println("RoktEvent: onPlatformEvent received $it") },
roktUxConfig = RoktUxConfig.builder()
.imageHandlingStrategy(NetworkStrategy())
.build(),
)
}

UX Events

Use the onUXEvent handler to receive real-time feedback on user interactions.

At a minimum you must handle when a RoktUXEvent.OpenUrl event is triggered so you can open the link using the below example.

info

OpenUrl - onClose

When handling an event of type OpenUrl it is critical to call the onClose callback which will notify the RoktUXHelper to execute some logic like moving to the next offer.

openUrlEvent.onClose.invoke(openUrlEvent.id)
onUxEvent = { event ->
println("RoktEvent: onUxEvent received $event")

if (event is RoktUxEvent.OpenUrl) {
val openUrlEvent = event as RoktUxEvent.OpenUrl
when (openUrlEvent.type) {
OpenLinks.Internally -> {
// Open AndroidX browser or similar functionality to keep the user in app
val customTabsIntent = CustomTabsIntent.Builder().build()
customTabsIntent.launchUrl(context, Uri.parse(openUrlEvent.url))

openUrlEvent.onClose.invoke(openUrlEvent.id) // This must be called when the user is ready for the next offer
}
OpenLinks.Externally, OpenLinks.Passthrough -> {
// Open external browser allowing user to leave the app
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(openUrlEvent.url))
context.startActivity(intent)

openUrlEvent.onClose.invoke(openUrlEvent.id) // This must be called when the user is ready for the next offer
}
}
}
}
All events
### UX Events
EventDescriptionParams
OfferEngagementTriggered when the user engages with the offerlayoutId: String
PositiveEngagementTriggered when the user positively engages with the offerlayoutId: String
LayoutInteractiveTriggered when a layout has been rendered and is interactablelayoutId: String
LayoutReadyTriggered when a layout is ready to display but has not rendered content yetlayoutId: String
LayoutClosedTriggered when a layout is closed by the userlayoutId: String
LayoutCompletedTriggered when the offer progression reaches the end and no more offers are available to displaylayoutId: String
LayoutFailureTriggered when a layout could not be displayed due to some failurelayoutId: String (optional)
OpenUrlTriggered when a link needs to be openedurl: String, id: String, type: OpenLinks (internally/externally/Passthrough), onClose: (id: String) -> Unit, onError: (id: String, throwable: Throwable)

PlatformEvents

Platform events are an essential part of integration and they have to be sent to Rokt via your backend. To ease integration the object is of type RoktPlatformEventsWrapper, implements @Serializable and offers a toJsonString function.

onPlatformEvent = { events ->
// Send these platform events to Rokt API including the event body
}

You can find a full list of events here.

Optional: App Configurations

Color mode

Color mode allows you to fix the theme used when displaying Rokt layouts. By default Rokt matches the current system theme.

val config = RoktUxConfig.builder()
.colorMode(ColorMode.DARK)
.build()

RoktUxColorMode object

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

ImageLoader

In Rokt UX Helper coil is used for loading images, UX Helper has several built in image loaders that you can utilise in your app. The easiest and recommended approach to implement is NetworkStrategy, however depending on your networking library or preferences you can create custom image loading strategies.

val roktUxConfig = RoktUxConfig.builder()
.imageHandlingStrategy(NetworkStrategy())
.build()

Fonts

val fontFamily = remember {
val robotoLight = Font(resId = R.font.roboto_light, weight = FontWeight.W100)
val robotoItalic = Font(resId = R.font.roboto_italic, weight = FontWeight.W400)
FontFamily(robotoLight, robotoItalic)
}

RoktUxConfig.builder()
.composeFontMap(mapOf("roboto" to fontFamily))
.build()
Was this article helpful?