Respectlytics Respect lytics
Menu
Kotlin (Android) Content shared Privacy-first

How to track content share events in Kotlin (Android) without personal data

Content share — "share to Messages", "share to Twitter", "copy link" — is a viral-loop signal in social and content apps. Most analytics SDKs default to logging the destination app, the shared content ID, and sometimes the recipient. Respectlytics helps developers avoid collecting personal data in the first place: in Kotlin (Android), share is one named event per channel, with no payload. Below: the Kotlin (Android) share-sheet integration, why channel goes in the event name, and what stays out.

Fire the call inside the share-sheet completion callback when the user has actually completed the share (not when they open the sheet — abandonment is common). Encode the chosen channel into the event name.

Install the Kotlin (Android) SDK

kotlin Respectlytics
// build.gradle.kts (app module)
dependencies {
    implementation("com.respectlytics:respectlytics-kotlin:3.0.0")
}

Pure Kotlin coroutines implementation. No Java dependencies, no Google Play Services dependencies. ~300KB DEX overhead — compare to roughly 3.8MB for Firebase Analytics (a measurable cold-start improvement on lower-end devices).

Initialize Respectlytics in Kotlin (Android)

kotlin Respectlytics
import com.respectlytics.android.Respectlytics

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        Respectlytics.configure(this, appKey = "<YOUR_APP_KEY>")
    }
}

Initialize once in Application.onCreate. No additional permissions in the manifest — INTERNET is sufficient. The SDK does not request AD_ID, does not query AdvertisingIdClient, and does not declare ACCESS_NETWORK_STATE.

Track the event in Kotlin (Android)

kotlin Respectlytics
import android.content.Intent
import androidx.activity.result.contract.ActivityResultContracts
import com.respectlytics.android.Respectlytics

fun shareContent(activity: ComponentActivity, text: String) {
    val intent = Intent.createChooser(
        Intent(Intent.ACTION_SEND).apply {
            type = "text/plain"
            putExtra(Intent.EXTRA_TEXT, text)
        },
        "Share via",
    )
    val launcher = activity.registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
        if (result.resultCode == android.app.Activity.RESULT_OK) {
            // Android's chooser doesn't reliably tell you which app — fire generic.
            Respectlytics.track("share_completed")
        } else {
            Respectlytics.track("share_cancelled")
        }
    }
    launcher.launch(intent)
}

Android's chooser intent doesn't reliably return the chosen activity until API 33+. For finer-grained channel attribution, call individual share intents per-channel and fire distinct event names there.

Privacy & implementation notes

Putting the channel as a parameter ({ channel: 'twitter' }) is the natural first instinct and is exactly what Respectlytics's API rejects. Encode it as the event name — share_twitter — and you get the same downstream queryability without storing parameters.

Fire on share completion, not on share-sheet presentation. Share-sheet presentation is fairly common (the user is just exploring); actual completion is much rarer and is the meaningful signal. The two rates differ by 5–10× in most apps.

Many teams discover the com.google.android.gms.permission.AD_ID permission in their merged manifest only after Google Play flags them — usually because a transitive dependency dragged it in. Respectlytics's Kotlin SDK has no Google Play Services dependency at all, so it cannot contribute to that merge.

The SDK is implemented as pure Kotlin coroutines with no Java sources, no RxJava, and no platform channels. Events are queued in a Channel<Event> buffered to a small ring (RAM-only), drained by a coroutine that flushes every 30 seconds or on backgrounding. There is no SharedPreferences usage.

How this compares to other analytics SDKs

Share eventFirebase AnalyticsMixpanelRespectlytics
Share channel as parameterRecommendedRecommendedUse distinct event_name
Shared content IDRecommendedRecommendedOut of scope (use content backend)
Recipient data (when accessible)PossiblePossibleForbidden (PII)
Per-user share countYesYesOut of scope
Share rate by content / channelPer-userPer-userUse distinct event_names + content backend

Frequently asked questions

How do we know which channels are most popular?

Distinct event names per channel: share_imessage, share_email, share_twitter, share_copy_link. Aggregation gives per-channel rate. iOS's UIActivityViewController and Android's Intent chooser deliver the selected channel in the completion callback — encode it into the event name.

What about shared content metadata?

Stays in your content backend. The CMS or content database knows what was shared. Respectlytics tells you that a share happened in this session — the join to specific content is a backend concern.

Can we measure share-induced installs?

Server-side via deferred deep links and install attribution. App Store Connect / Play Console deliver the attribution; your backend correlates the shared link's tracking parameter with the resulting install. Respectlytics doesn't ingest install attribution — it's not the right system for that.

What if the share sheet completes but the user cancels?

iOS's UIActivityViewController and Android's Intent chooser both call back with a cancellation flag. Don't fire share_* on cancel — fire share_cancelled (a single event regardless of channel) if you want to track abandonment.

Related guides

Track what matters. Collect nothing you don't.

Five-field event schema, RAM-only event queue, no IDFA, no AAID, no persistent user IDs. Helps developers avoid collecting personal data in the first place.