Set up Product Analytics data capture

This page instructs how to set up data capture in the context of the User Lifecycle Extension for Experience Analaytics.

  1. Initialize the Product Analytics configuration with your environment ID.

    MyApplication.kt
    import android.app.Application
    import com.contentsquare.CSQ
    class MyApplication : Application() {
    override fun onCreate() {
    super.onCreate()
    CSQ.configureProductAnalytics(
    context = this,
    envId = "YOUR_ENVIRONMENT_ID"
    )
    CSQ.start()
    }
    }
  2. Add the Android View Autocapture Plugin to instrument your app code:

    build.gradle.kts
    plugins {
    // ...
    id("io.heap.gradle") version "1.1.0"
    }
  3. Set up autocapture by adding enableViewAutocapture = true.

    MyApplication.kt
    import android.app.Application
    import com.contentsquare.CSQ
    class MyApplication : Application() {
    override fun onCreate() {
    super.onCreate()
    CSQ.configureProductAnalytics(
    context = this,
    envId = "YOUR_ENVIRONMENT_ID",
    options = ProductAnalyticsOptions(
    enableViewAutocapture = true
    )
    )
    CSQ.start()
    }
    }
  4. (Optional) For Jetpack Compose, add the dedicated import and register the Compose Autocapture SDK.

    build.gradle.kts
    dependencies {
    implementation("com.contentsquare.android:sdk:1.3.0")
    implementation("com.contentsquare.android:sdk-compose:1.3.0")
    }
    MyApplication.kt
    import android.app.Application
    import com.contentsquare.CSQ
    import io.heap.autocapture.compose.ComposeAutocaptureSDK
    class MyApplication : Application() {
    override fun onCreate() {
    super.onCreate()
    ComposeAutocaptureSDK.register()
    CSQ.configureProductAnalytics(
    context = this,
    envId = "YOUR_ENVIRONMENT_ID",
    options = ProductAnalyticsOptions(
    enableViewAutocapture = true
    )
    )
    CSQ.start()
    }
    }
  5. (Optional) If your Product Analytics environment is hosted in the EU, set the baseUri option to https://mh.ba.contentsquare.net.

    MyApplication.kt
    import android.app.Application
    import com.contentsquare.CSQ
    class MyApplication : Application() {
    override fun onCreate() {
    super.onCreate()
    CSQ.configureProductAnalytics(
    context = this,
    envId = "YOUR_ENVIRONMENT_ID",
    options = ProductAnalyticsOptions(
    enableViewAutocapture = true,
    baseUri = URI("https://mh.ba.contentsquare.net")
    )
    )
    }
    }
  6. Add the resumePreviousSession: true and disablePageviewAutocapture: true options to the configuration.

    MyApplication.kt
    import android.app.Application
    import com.contentsquare.CSQ
    class MyApplication : Application() {
    override fun onCreate() {
    super.onCreate()
    CSQ.configureProductAnalytics(
    context = this,
    envId = "YOUR_ENVIRONMENT_ID",
    options = ProductAnalyticsOptions(
    enableViewAutocapture = true,
    resumePreviousSession = true,
    disablePageviewAutocapture = true
    )
    )
    CSQ.start()
    }
    }