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.
Install the SDK
Section titled Install the SDK-
Add the CSQ SDK dependency to your Gradle build file:
build.gradle.kts implementation("com.contentsquare.android:sdk:1.0.0")build.gradle implementation "com.contentsquare.android:sdk:1.0.0" -
Once the dependencies and the plugin have been added, sync Gradle and rebuild your application.
Start the SDK
Section titled Start the SDK-
Import
com.contentsquare.CSQ
in your application: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 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.start(this)}}MyApplication.java import android.app.Application;import com.contentsquare.CSQ;public class MyApplication extends Application {@Overridepublic void onCreate() {super.onCreate();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...});
Track your first screens
Section titled Track your first screensContentsquare 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.
Sending screenview events
Section titled Sending screenview eventsScreen 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") }}
import com.contentsquare.CSQ;
public class MyActivity extends Activity { @Override public void onResume() { super.onResume();
// Send screenView CSQ.trackScreenview("screen_name"); }}
For more information, see Implementation recommendations
Jetpack Compose support
Section titled Jetpack Compose supportTo enable Jetpack Compose support, add a new dependency to your Gradle build file.
implementation("com.contentsquare.android:sdk-compose:1.0.0")
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.CSQimport com.contentsquare.api.compose.TriggeredOnResume
@Composablefun MyComposable(data: Data) { TriggeredOnResume { CSQ.trackScreenview("screen_name") } // ...}
Tracking app launch
Section titled Tracking app launchMost 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.
Screen name handling
Section titled Screen name handlingIt 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.
Next Steps
Section titled Next StepsWhile 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.