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.
Install the SDK
Section titled Install the SDK-
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")}build.gradle dependencies {implementation 'com.contentsquare.android:sdk:1.0.0'implementation 'com.contentsquare.android:sdk-compose:1.0.0'} -
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"}build.gradle plugins {// ...id 'io.heap.gradle' version '1.1.0'} -
Once the dependencies and plugins have been added, sync Gradle and rebuild your application.
Start the SDK
Section titled Start the SDK-
In your app, import
com.contentsquare.CSQ
.MyApplication.kt import android.app.Applicationimport com.contentsquare.CSQclass MyApplication : Application() {override fun onCreate() {super.onCreate()}}MyApplication.java import android.app.Application;import com.contentsquare.CSQ;public class MyApplication extends Application {@Overridepublic void onCreate() {super.onCreate();}} -
Add your Product Analytics Environment ID using
CSQ.configureProductAnalytics()
.MyApplication.kt import android.app.Applicationimport com.contentsquare.CSQclass MyApplication : Application() {override fun onCreate() {super.onCreate()CSQ.configureProductAnalytics(context = this,envId = "YOUR_ENVIRONMENT_ID")}}MyApplication.java import android.app.Application;import com.contentsquare.CSQ;public class MyApplication extends Application {@Overridepublic void onCreate() {super.onCreate();CSQ.configureProductAnalytics(this, "YOUR_ENVIRONMENT_ID");}} -
Recommended To capture automatically screenviews and interactions, enable autocapture by setting
enableViewAutocapture
totrue
.MyApplication.kt import android.app.Applicationimport com.contentsquare.CSQclass MyApplication : Application() {override fun onCreate() {super.onCreate()CSQ.configureProductAnalytics(context = this,envId = "YOUR_ENVIRONMENT_ID",options = ProductAnalyticsOptions(enableViewAutocapture = true))}}MyApplication.java import android.app.Application;import com.contentsquare.CSQ;public class MyApplication extends Application {@Overridepublic void onCreate() {super.onCreate();ProductAnalyticsOptions options = new ProductAnalyticsOptions.Builder().enableViewAutocapture(true).build();CSQ.configureProductAnalytics(this, "YOUR_ENVIRONMENT_ID", options);}} -
(Optional) For Jetpack Compose, add the dedicated import and register the Compose Autocapture SDK.
MyApplication.kt import android.app.Applicationimport com.contentsquare.CSQimport io.heap.autocapture.compose.ComposeAutocaptureSDKclass MyApplication : Application() {override fun onCreate() {super.onCreate()ComposeAutocaptureSDK.register()CSQ.configureProductAnalytics(context = this,envId = "YOUR_ENVIRONMENT_ID",options = ProductAnalyticsOptions(enableViewAutocapture = true))}}MyApplication.java import android.app.Application;import com.contentsquare.CSQ;import io.heap.autocapture.compose.ComposeAutocaptureSDK;public class MyApplication extends Application {@Overridepublic void onCreate() {super.onCreate();ComposeAutocaptureSDK.register();ProductAnalyticsOptions options = new ProductAnalyticsOptions.Builder().enableViewAutocapture(true).build();CSQ.configureProductAnalytics(this, "YOUR_ENVIRONMENT_ID", options);}} -
(Optional) If your Product Analytics environment is hosted in the EU, set the
baseUri
option tohttps://mh.ba.contentsquare.net
.MyApplication.kt import android.app.Applicationimport com.contentsquare.CSQclass 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")))}}MyApplication.java import android.app.Application;import com.contentsquare.CSQ;public class MyApplication extends Application {@Overridepublic void onCreate() {super.onCreate();ProductAnalyticsOptions options = new ProductAnalyticsOptions.Builder().enableViewAutocapture(true).baseUri(URI.create("https://mh.ba.contentsquare.net")).build();CSQ.configureProductAnalytics(this, "YOUR_ENVIRONMENT_ID", options);}} -
Add a call to
CSQ.start(this)
withinonCreate()
of a custom Application subclass:MyApplication.kt import android.app.Applicationimport com.contentsquare.CSQclass MyApplication : Application() {override fun onCreate() {super.onCreate()CSQ.configureProductAnalytics(context = this,envId = "YOUR_ENVIRONMENT_ID",options = ProductAnalyticsOptions(enableViewAutocapture = true))CSQ.start(this)}}MyApplication.java import android.app.Application;import com.contentsquare.CSQ;public class MyApplication extends Application {@Overridepublic void onCreate() {super.onCreate();ProductAnalyticsOptions options = new ProductAnalyticsOptions.Builder().enableViewAutocapture(true).build();CSQ.configureProductAnalytics(this, "YOUR_ENVIRONMENT_ID", options);CSQ.start(this);}} -
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
Get user consent
Section titled Get user consentThe 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.Applicationimport com.contentsquare.CSQ
// ...CSQ.start(context)// ...
val optinButton: Button = ...optinButton.setOnClickListener { CSQ.optIn(it.context) // Then finish initialization and move to the next screen...}
import android.app.Application;import com.contentsquare.CSQ;
// ...CSQ.start(context);// ...
Button optinButton = ...optinButton.setOnClickListener(view -> { CSQ.optIn(view.getContext()); // 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.
Next steps
Section titled Next stepsOur 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.