Skip to main content

Request flow

Installation

Add the GitHub Packages repository and dependency to your build.gradle.kts:
// settings.gradle.kts
dependencyResolutionManagement {
    repositories {
        maven {
            url = uri("https://maven.pkg.github.com/reelevant-tech/reelevant-sdk-android")
        }
    }
}

// app/build.gradle.kts
dependencies {
    implementation("com.reelevant.analytics:analytics-android:0.0.3-SNAPSHOT")
}

Initialization

import com.reelevant.analytics_android.*

val rlvt = ReelevantSDK(
    context = applicationContext,
    companyId = "your-company-id",
    datasourceId = "your-datasource-id",
    // Optional personalization config
    runnerUrl = "https://reelevant.run",       // default
    personalizationTimeout = 5000L,            // ms, default
    fallback = FallbackStrategy.Empty           // default
)

// Set user identity (shared between analytics and personalization)
rlvt.setUser("user@example.com")

Analytics (event tracking)

// Page view
rlvt.send(rlvt.pageView(mapOf("lang" to "en")))

// Product page
rlvt.send(rlvt.productPage("product-123", mapOf("category" to "shoes")))

// Purchase
rlvt.send(rlvt.purchase(listOf("p1", "p2"), 99.99f, mapOf(), "order-456"))

// Add to cart
rlvt.send(rlvt.addCart(listOf("p1"), mapOf()))

Personalization

Single workflow run

val result = rlvt.run(RunOptions(
    workflowId = "wf-hero",
    entrypoint = "43a490a0"
))

when (result.body) {
    is RunContent.Json  -> renderCard((result.body as RunContent.Json).content)
    is RunContent.Html  -> renderWebView((result.body as RunContent.Html).content)
    is RunContent.Image -> renderImage((result.body as RunContent.Image).content)
    is RunContent.Empty -> showDefault()
}

Multiple workflows in parallel

val results = rlvt.runAll(listOf(
    RunOptions(workflowId = "wf-hero", entrypoint = "entry1"),
    RunOptions(workflowId = "wf-reco", entrypoint = "entry2")
))
// results[0] corresponds to wf-hero, results[1] to wf-reco

Click tracking

// Fire-and-forget — registers the click without following redirects
result.trackClick()

RunOptions

ParameterTypeRequiredDescription
workflowIdStringYesWorkflow ID from the platform
entrypointStringYesEntrypoint ID within the workflow
userIdString?NoOverride identity (default: auto-resolved from setUser() / device ID)
paramsMap<String, String>?NoAdditional URL parameters forwarded to the runner
localeString?NoLocale for content resolution
timeoutLong?NoPer-call timeout override in milliseconds

RunResult

FieldTypeDescription
statusIntHTTP status code (0 for fallback)
sourceRunSource.RUNNER or .FALLBACK
bodyRunContentDiscriminated content: Json, Html, Image, or Empty
metadataMap<String, Any>Metadata from x-rlvt-output-node-metadata header
propertiesMap<String, Any>Properties from x-rlvt-output-properties header
runIdString?Workflow run ID for tracking correlation
executionPathList<String>Branch IDs taken during execution
redirectionUrlStringPre-built click-through URL

Fallback strategies

// Return empty result on error (default)
FallbackStrategy.Empty

// Re-throw the error
FallbackStrategy.Error

// Custom handler
FallbackStrategy.Custom { options, error ->
    RunResult(/* your fallback result */)
}