Getting Started with Product Analytics

This quick start guide shows you how to get Contentsquare Product Analytics set up in an Android application.

Once you’ve completed the setup process, the Contentsquare SDK will capture a wide variety of user interactions in your application with no additional code required.

  1. In your app-level build.gradle file, add the dependency for the Contentsquare SDK and the Compose Autocapture SDK.

    build.gradle.kts
    dependencies {
    implementation("com.contentsquare.android:sdk:1.0.0")
    implementation("com.contentsquare.android:sdk-compose:1.0.0")
    }
  2. Add the Android View Autocapture Plugin to instrument your app code with direct calls into the CSQ SDK:

    build.gradle.kts
    plugins {
    // ...
    id("io.heap.gradle") version "1.1.0"
    }
  3. Once the dependencies and plugins have been added, sync Gradle and rebuild your application.

  1. In your app, import com.contentsquare.CSQ.

    MyApplication.kt
    import android.app.Application
    import com.contentsquare.CSQ
    class MyApplication : Application() {
    override fun onCreate() {
    super.onCreate()
    }
    }
  2. Add your Product Analytics Environment ID using CSQ.configureProductAnalytics().

    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"
    )
    }
    }
  3. Recommended To capture automatically screenviews and interactions, enable autocapture by setting enableViewAutocapture to 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
    )
    )
    }
    }
  4. (Optional) For Jetpack Compose, add the dedicated import and register the Compose Autocapture SDK.

    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
    )
    )
    }
    }
  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 a call to CSQ.start(this) within onCreate() of a custom Application subclass:

    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(this)
    }
    }
  7. Start your application, and check logs for this output:

    CSQ 1.0.0 is attempting to start Digital eXperience Analytics.
    CSQ 1.0.0 is attempting to start Product Analytics.
    User is drawn for tracking: true

The CSQ SDK treats users as opted-out by default.

Implement the optIn() API to forward user consent to the SDK and generate a user ID.

import android.app.Application
import com.contentsquare.CSQ
// ...
CSQ.start(context)
// ...
val optinButton: Button = ...
optinButton.setOnClickListener {
CSQ.optIn(it.context)
// Then finish initialization and move to the next screen...
}

Once tracking has started, you’re able to take full advantage of the CSQ SDK API to identify users, track custom events, and more.

Contentsquare’s Product Analytics module will also automatically start tracking a wide range of user interactions, view controller changes, and app version changes without any additional code.

Our SDK offers a wide range of features to enhance your implementation, including extended tracking capabilities, and personal data masking.

Session Replay and Error Monitoring are both available with the Experience Analytics Extension, which you can purchase separately.