Getting Started
Welcome to the SDK implementation guide!
This guide is designed to help you seamlessly integrate our SDK into your application. By following the outlined steps, you’ll be able to collect and analyze data from your app, within just a few minutes.
Install the SDK
Section titled Install the SDKOur Android SDK is shipped as an Android library (AAR) which you need to add as a dependency to your Gradle file.
See Compatibility for more information.
Include the SDK
Section titled Include the SDKFor distribution of our API we use Maven Central Repository which is supported by the Android build system by default. To add our SDK (or library), add the following line to your application’s dependency list.
implementation "com.contentsquare.android:sdk:0.5.0"
implementation("com.contentsquare.android:sdk:0.5.0")
The SDK autostarts when your application launches, requiring no manual initialization.
If you are using with an older Kotlin version, see Compatibility.
Validate SDK integration
Section titled Validate SDK integrationStart your application, and check logs for this output:
CSLIB: Contentsquare SDK 4.36.0 starting in app: com.example.testapp
Check the logs
Section titled Check the logsContentsquare provides logging capabilities that allow you to inspect the raw event data logged by your app in Android Studio, or on the Contentsquare platform.
To view all logs, you must enable in-app features: logging is linked to in-app features being enabled or disabled.
Viewing logs in Android Studio
Section titled Viewing logs in Android StudioTo view SDK logs:
- Plug your Android phone into your computer (or use an emulator)
- Open Android Studio and start your app
- Open the
Logcat
view and select your phone or emulator - Filter logs by
CSLIB
Enable in-app features
Section titled Enable in-app featuresIn-app features are essential for your implementation, as it includes key functionalities like snapshot creation and replay configuration.
To enable in-app features within your app, make sure your app is launched in the background. To do so, start it and press the Android home button. Then, follow the appropriate method described as follows.
On a device: scan the QR code
Section titled On a device: scan the QR codeIn Contentsquare, select the Mobile icon in the menu top bar and scan the QR code with your phone.

On an emulator: use the ADB command
Section titled On an emulator: use the ADB commandIf you are using an emulator, use the ADB command to enable in-app features.
In Contentsquare, select the Mobile icon in the menu top bar then select your application ID, and “Copy this ADB command”.
The following command is copied to the clipboard:
adb shell "am start -W -a android.intent.action.VIEW -d cs-{{packageName}}://contentsquare.com?activationKey={{uniqueActivationKey}}\&userId={{userId}}"
To execute the ADB command:
- Plug your Android phone into your Computer (or use an emulator).
- Make sure that only one phone or emulator is connected or running.
- Start Android Studio.
- Open the Terminal view.
- Paste the ADB command into the Terminal and press Enter.
- Switch to your phone or emulator and follow the steps on the screen.
Contentsquare Log Visualizer
Section titled Contentsquare Log VisualizerLog Visualizer is a feature integrated into the Contentsquare SDK. As you navigate and interact with your app, it provides a live view of events detected by the SDK, visible directly on the Contentsquare platform ↗.
- Start your app.
- Select the Mobile icon in the menu top bar then select
Log Visualizer
. - Select the device to inspect.
At this stage, you should see an ‘App start’ or ‘App show’ event being logged.

Get user consent
Section titled Get user consentContentsquare collects usage data from your app users. To start tracking, you need your users’ consent for being tracked.
User opt-in
Section titled User opt-inThe SDK treats users as opted-out by default.
To start tracking, forward user consent with optIn()
.
Calling this method generates a user ID and initiates tracking.
Handle user consent by implementing a UI for privacy preferences. Assuming you have an opt-in screen with a button to give consent, the code could look like this:
import com.contentsquare.android.Contentsquare;
Button optinButton = ...optinButton.setOnClickListener(view -> { Contentsquare.optIn(view.getContext()); // Then finish initialization and move to the next screen...});
import com.contentsquare.android.Contentsquare
val optinButton: Button = ...optinButton.setOnClickListener { Contentsquare.optIn(it.context) // 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.
Sending screenview events
Section titled Sending screenview eventsScreen tracking is achieved by sending a screenview
event each time a new screen is displayed on the user’s device.
To trigger a screenview each time an activity becomes visible, place the call in the onResume()
method (XML layouts only):
import com.contentsquare.android.Contentsquare;
public class MyActivity extends Activity { @Override public void onResume() { super.onResume();
// Send screenView Contentsquare.send("screen_name"); }}
import com.contentsquare.android.Contentsquare
class MyActivity : Activity() { override fun onResume() { super.onResume()
// Send screenView Contentsquare.send("screen_name") }}
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:compose:4.36.0'
implementation("com.contentsquare.android:compose:4.36.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.android.Contentsquareimport com.contentsquare.android.compose.analytics.TriggeredOnResume
@Composablefun MyComposable(data: Data) { TriggeredOnResume { Contentsquare.send("screen_name") } // ...}
Implementation recommendations
Section titled Implementation recommendationsFrom a functional perspective, a screenview should be triggered in the following cases:
- When the screen appears on the device
- When a modal or pop-up is displayed
- When a modal or pop-up is closed, returning the user to the screen
- When the app is brought back to the foreground (after being minimized)
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.
Test your setup
Section titled Test your setupTesting your SDK implementation is essential to make sure data is being accurately captured and reported.
To test your setup, simulate user interactions in your app and check that the events are logged correctly in our analytics platform.
You can also use debugging tools such as Android Studio or Log Visualizer to monitor data transmission and ensure everything is running smoothly.
Visualize events in Contentsquare
Section titled Visualize events in ContentsquareUse Log Visualizer to view incoming events within the Contentsquare pipeline. This allows you to monitor the stream in real time.
By simulating user activity, you see incoming screenview and gesture events.

Visualize data in Contentsquare
Section titled Visualize data in ContentsquareIn Journey Analysis
Section titled In Journey AnalysisOpen Journey Analysis ↗ in Contentsquare and visualize the user journeys main steps across your app, screen by screen.
See how to use Journey Analysis on the Help Center ↗.
In Session Replay
Section titled In Session ReplayOpen Session Replay ↗ in Contentsquare and replay the full user session across your app.
See how to use Session Replay on the Help Center ↗
Sample app
Section titled Sample appTo explore some of these features in context, check our Android sample app.
Android-sample-app
A sample app giving an example implementation of the Contentsquare SDK
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.