Getting Started with Experience Analytics

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

After completing the setup process, you’ll be able to take full advantage of the CSQ API to collect data from your app, within just a few minutes.

  1. Add the CSQ SDK dependency to your Gradle build file:

    build.gradle.kts
    implementation("com.contentsquare.android:sdk:1.0.0")
  2. Once the dependencies and the plugin have been added, sync Gradle and rebuild your application.

  1. Import com.contentsquare.CSQ in your application:

    MyApplication.kt
    import android.app.Application
    import com.contentsquare.CSQ
    class MyApplication : Application() {
    override fun onCreate() {
    super.onCreate()
    }
    }
  2. 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.start(this)
    }
    }
  3. 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...
}

Contentsquare aggregates the user behavior and engagement at the screen level. Start your SDK implementation by tracking key screens like the home screen, product list, product details, or conversion funnel.

Once tracking has started, you’re able to take full advantage of the CSQ SDK API to track screen views, monitor user interactions, and capture app behavior data.

Contentsquare Experience Analytics also comes with powerful Session Replay and Error Monitoring capabilities as paid options.

Screen tracking is achieved by sending a screenview event when:

  • The screen appears on the device
  • A modal or pop-up is displayed
  • A modal or pop-up is closed, returning the user to the screen
  • The app is brought back to the foreground (after being minimized)

To trigger a screenview each time an activity becomes visible, place the call in the onResume() method (XML layouts only):

import com.contentsquare.CSQ
class MyActivity : Activity() {
override fun onResume() {
super.onResume()
// Send screenView
CSQ.trackScreenview("screen_name")
}
}

For more information, see Implementation recommendations

To enable Jetpack Compose support, add a new dependency to your Gradle build file.

build.gradle.kts
implementation("com.contentsquare.android:sdk-compose:1.0.0")

Attention must be paid to recompositions. The call should be wrapped using TriggeredOnResume to ensure only one screenview is triggered when a given screen is presented to the user.

import com.contentsquare.CSQ
import com.contentsquare.api.compose.TriggeredOnResume
@Composable
fun MyComposable(data: Data) {
TriggeredOnResume {
CSQ.trackScreenview("screen_name")
}
// ...
}

Most events collected by the SDK require a screenview event to be sent first so they can be associated with that screen; otherwise, they will be discarded. If you need to collect events from the moment the app launches, you should trigger a screenview event immediately after the SDK has started.

Refer to our guide for implementation examples.

It is necessary to provide a name for each screen when calling the screenview API.

As a general rule, keep distinct screen names under 100. As they are used to map your app in Contentsquare, you will want something comprehensive. The screen name length is not limited on the SDK side. However, the limit is 2083 characters on the server side.

More on screen name handling.

While screen tracking gives an overview of user navigation, capturing session, screen, or user metadata provides a deeper understanding of the context behind user behavior.

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

Proceed with these how-to’s to refine your implementation.