DocsSDKsAndroid SDK
SDKsOfficial

Android SDK

High-fidelity analytics and session replay for native Android applications.

Source of truthsdks/sankofa_sdk_android

Android SDK 🚀

The Sankofa Android SDK provides a complete solution for product analytics and session replay in native Android applications. It is designed to be lightweight, offline-ready, and privacy-first.


✨ Key Features

  • Event Tracking: Send custom events with arbitrary properties and automatic device metadata.
  • Identity Management: Link anonymous users to permanent customer profiles.
  • Session Replay:
    • Screenshot Mode: Pixel-perfect visual capture for complex UI debugging.
    • Auto-masking: Sensitive data protection via Kotlin extensions and automatic EditText detection.
  • Offline Reliability: Robust local queueing with background auto-flushing via WorkManager.
  • Privacy First: Granular controls over what to track and what to mask.

🚀 Quick Start

1. Install

Add the dependency to your module's build.gradle.kts (or build.gradle):

dependencies {
    implementation("dev.sankofa.sdk:sankofa-android:1.0.0")
}

2. Initialize

Initialize the SDK in your Application class. It auto-registers to all Activities – no per-screen boilerplate required.

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        Sankofa.init(
            context = this,
            apiKey = "YOUR_PROJECT_API_KEY",
            config = SankofaConfig(
                recordSessions = true,
                maskAllInputs = true, // Auto-mask all EditTexts
            )
        )
    }
}

🛠 Configuration Options

The SankofaConfig class allows you to fine-tune the SDK's behavior.

OptionDefaultDescription
endpointhttps://api.sankofa.devBase URL of your Sankofa server
recordSessionstrueEnable or disable high-fidelity session replay
maskAllInputstrueAuto-mask all EditText views in session recordings
debugfalseEnable verbose Logcat output for debugging
trackLifecycleEventstrueAuto-track $app_opened/foregrounded/backgrounded
flushIntervalSeconds30Interval for flushing queued events while foregrounded
batchSize50Maximum number of events to queue before flushing

Example with Custom Configuration

Sankofa.init(
    context = this,
    apiKey = "YOUR_PROJECT_API_KEY",
    config = SankofaConfig(
        endpoint = "https://analytics.yourdomain.com",
        recordSessions = true,
        maskAllInputs = true,
        debug = true
    )
)

📈 Tracking Events

Track any user action with a simple method call. Events are automatically enriched with device metadata and batched for efficient uploading.

1. Simple Event Tracking

Sankofa.track("started_trial")

2. Tracking with Properties

Sankofa.track("completed_purchase", mapOf(
    "item_id" to "cam_001",
    "item_name" to "Vintage Camera",
    "price" to 120.50,
    "currency" to "USD"
))

3. Automatic Metadata

Sankofa automatically captures the following device properties with every event:

  • Device: $brand, $model, $os_version
  • Screen: $screen_width, $screen_height
  • App: $app_version, $app_release

👤 Identity & People

Sankofa allows you to resolve anonymous user identities and manage rich customer profiles.

1. Identifying Users

When a user logs in, use Sankofa.identify() to link their anonymous history to their unique user ID.

Sankofa.identify("user_99")

2. Resetting Identity

When a user logs out, use Sankofa.reset() to clear their current identity and start a fresh anonymous session.

Sankofa.reset()

3. Setting Person Properties

Sankofa.setPerson(
    name = "Jane Doe",
    email = "[email protected]",
    properties = mapOf(
        "membership" to "Gold",
        "signup_source" to "referral"
    )
)

🎥 Session Replay & Privacy

Sankofa's session replay engine captures pixel-perfect recordings of user interactions.

Privacy & Masking 🛡

Privacy is a top priority. Sankofa provides multiple ways to mask sensitive content from session recordings.

Automatic Masking

When maskAllInputs is enabled (default), the SDK automatically blacks out all EditText views.

Manual Masking

Option 1: Kotlin Extension (Recommended)
import dev.sankofa.sdk.util.sankofaMask

mySensitiveView.sankofaMask = true
Option 2: View Tag
mySensitiveView.tag = "sankofa_mask"

📑 API Reference

Sankofa (Singleton)

MethodSignatureDescription
initinit(context: Context, apiKey: String, config: SankofaConfig)Initializes the SDK.
tracktrack(eventName: String, properties: Map<String, Any?>?)Tracks a custom event.
identifyidentify(userId: String)Links anonymous data to a known user ID.
resetreset()Clears identity and starts a new anonymous session.
setPersonsetPerson(name: String?, email: String?, properties: Map<String, Any?>?)Sets common profile attributes.
flushflush()Force-uploads all queued events immediately.
shutdownshutdown()Tears down the SDK and persists state.

SankofaConfig

PropertyTypeDefaultDescription
endpointStringhttps://api.sankofa.devServer URL.
recordSessionsBooleantrueEnable/disable recordings.
maskAllInputsBooleantrueAuto-mask all EditText views.
debugBooleanfalseEnable verbose logging.
trackLifecycleEventsBooleantrueAuto-track app open/close.
flushIntervalSecondsInt30Event flush interval.
batchSizeInt50Event queue limit.