Android

MetaRouter Android SDK

Capture behavioral data directly from your Android app and route it through MetaRouter to any destination — without juggling multiple vendor SDKs.

View on GitHub GitHub release

Why use the Mobile SDK?

One integration, unlimited destinations
Stop embedding separate SDKs for analytics, marketing, and data warehouses. Collect once, route everywhere through MetaRouter.

Update routing without app releases
Add or remove destinations server-side. No code changes, no app store review cycles.

Reliable delivery, even offline
Events are queued locally and delivered automatically when connectivity returns. Built-in retry logic handles transient failures.

Automatic identity resolution
Track users from first app open through sign-up and beyond. The SDK manages anonymous IDs, persists identity across sessions, and connects pre-login activity to known users.

Privacy-ready by design
Built-in support for advertising ID consent, easy opt-out handling, and clean user data reset for GDPR/CCPA compliance.

Lightweight footprint
No bloated dependencies. Minimal impact on app size and startup time.

Quick start

1) Add the SDK

Add JitPack to your project's settings.gradle.kts:

dependencyResolutionManagement {
    repositories {
        maven { url = uri("https://jitpack.io") }
    }
}

Then add the dependency in your module’s build.gradle.kts:

dependencies {
    implementation("com.github.metarouterio:android-sdk:1.0.1")
}

2) Initialize

Add this to your Application.onCreate():

val analytics = MetaRouter.Analytics.initialize(
    context = applicationContext,
    options = InitOptions(
        writeKey = "YOUR_WRITE_KEY",
        ingestionHost = "https://YOUR_CLUSTER.YOUR_SITE.com"
    )
)

Your writeKey and ingestionHost are available in the MetaRouter dashboard.

3) Start tracking

// Track user actions
analytics.track(
    "Product Viewed",
    "sku" to "SHOE-123",
    "price" to 89.99
)

// Identify known users
analytics.identify(
    "user-456",
    "email" to "[email protected]",
    "plan" to "premium"
)

// Track screen views
analytics.screen(
    "Product Detail",
    "category" to "Footwear"
)

Events are batched and delivered automatically. No additional setup required.


Core capabilities

Event tracking

MethodPurpose
track(event, properties)Capture user actions — purchases, clicks, feature usage
screen(name, properties)Record screen views for navigation analytics
page(name, properties)Record page views (web semantics, if applicable)

User identity

MethodPurpose
identify(userId, traits)Associate events with a known user
group(groupId, traits)Associate users with a company, team, or account
alias(newUserId)Link anonymous activity to a newly identified user

Lifecycle & privacy

MethodPurpose
flush()Send queued events immediately
reset()Clear all user data (use on logout)
setAdvertisingId(id)Set GAID for attribution (with user consent)
clearAdvertisingId()Remove GAID when user opts out

Identity that just works

The SDK automatically handles the complexity of user identity:

Before login — Users are assigned a stable anonymous ID
On login — Call identify() to attach a known user ID
Across sessions — Identity persists through app restarts
On logout — Call reset() to clear everything and start fresh

Connect anonymous browsing to authenticated users with alias():

// User browses anonymously, then signs up
analytics.track("Product Viewed", "sku" to "ABC") // tracked as anonymous

// User creates account
analytics.alias("new-user-789") // links anonymous → known
analytics.identify("new-user-789", "email" to "[email protected]")

// Full journey is now connected in your downstream tools

Advertising & attribution

For ad attribution, you can include the Google Advertising ID (GAID):

// Only after obtaining user consent
analytics.setAdvertisingId(advertisingId)

// When user opts out
analytics.clearAdvertisingId()

Privacy note: Always obtain explicit consent before collecting advertising IDs. See the GitHub docs for implementation details:
https://github.com/metarouterio/android-sdk#advertising-id-gaid


Requirements

ComponentVersion
AndroidAPI 23+ (6.0 Marshmallow)
Kotlin2.0+