For the complete documentation index, see llms.txt.

Product Analytics data capture

Dernière mise à jour Voir en Markdown

This page instructs how to set up Product Analytics data capture in combination with Experience Analytics.

  1. Initialize the SDK with your environment ID.

    MyApplication.kt
    import android.app.Application
    import com.contentsquare.CSQ
    class MyApplication : Application() {
    override fun onCreate() {
    super.onCreate()
    CSQ.start(
    context = this,
    StartConfig.withEnvironmentId(
    id = "YOUR_ENVIRONMENT_ID"
    )
    )
    }
    }
  2. Apply the Contentsquare Gradle plugin to your Android application module to instrument your app code. If the root build file declares plugin versions with apply false, declare the version there and apply the plugin in the application module without repeating the version.

    build.gradle.kts
    plugins {
    // ...
    id("com.contentsquare.gradle") version "1.1.0"
    }

    When upgrading from io.heap.gradle, remove the old plugin declaration. Do not apply both plugins to the same module.

  3. Set up autocapture by adding enableViewAutocapture = true. With this option, CSQ.start() registers both Views and Jetpack Compose autocapture.

    MyApplication.kt
    import android.app.Application
    import com.contentsquare.CSQ
    class MyApplication : Application() {
    override fun onCreate() {
    super.onCreate()
    CSQ.start(
    context = this,
    StartConfig.withEnvironmentId(
    id = "YOUR_ENVIRONMENT_ID",
    options = AnalyticsOptions(
    enableViewAutocapture = true
    )
    )
    )
    }
    }
  4. For Jetpack Compose, add the sdk-compose dependency.

    build.gradle.kts
    dependencies {
    implementation("com.contentsquare.android:sdk:1.13.0")
    implementation("com.contentsquare.android:sdk-compose:1.13.0")
    }
  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.start(
    context = this,
    StartConfig.withEnvironmentId(
    id = "YOUR_ENVIRONMENT_ID",
    options = AnalyticsOptions(
    enableViewAutocapture = true,
    baseUri = URI.create("https://mh.ba.contentsquare.net")
    )
    )
    )
    }
    }
  6. Add disablePageviewAutocapture = true to prevent automatic screenviews and keep tracking screens with CSQ.trackScreenview(). Interaction autocapture stays on, but interactions have no automatic screenview to attach to. See the screenview options.

    MyApplication.kt
    import android.app.Application
    import com.contentsquare.CSQ
    class MyApplication : Application() {
    override fun onCreate() {
    super.onCreate()
    CSQ.start(
    context = this,
    StartConfig.withEnvironmentId(
    id = "YOUR_ENVIRONMENT_ID",
    options = AnalyticsOptions(
    enableViewAutocapture = true,
    disablePageviewAutocapture = true
    )
    )
    )
    }
    }