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.

Before implementing the SDK, verify that you can create a project with React Native and make sure your app meets the following technical prerequisites to avoid integration issues and ensure optimal performance.

RequirementVersion
Bridge Version4.11.2
iOS SDK Version4.37.1
Android SDK Version4.33.1
Min React Native Version0.70.0
Max React Native Version0.75.x

For more details on Native environments, see:

Provide your bundle ID to Contentsquare

Section titled Provide your bundle ID to Contentsquare

Provide the value of the applicationId or Bundle Identifier from your build/configuration file to Contentsquare. The identifier is required to generate your project configuration.

build.gradle
android {
namespace 'com.example.testapp'
compileSdk Versions.compileSdkVersion
defaultConfig {
applicationId "com.example.testapp"
minSdk Versions.minSdkVersion
targetSdk Versions.targetSdkVersion
versionCode 1
versionName "1"
}
// ...
}

Validate Contentsquare account and project ID

Section titled Validate Contentsquare account and project ID

Once your project is created, ensure you have access to:

  • A Contentsquare account
  • A valid project ID

Each project ID corresponds to a specific data collection setup.

In Contentsquare, ensure that the applicationId or bundle identifier you provided matches the one in Contentsquare.

If it doesn’t or if you can’t connect to Contentsquare, reach out to your Implementation Manager.

The Contentsquare Bridge for React Native integrates the Contentsquare SDKs for both iOS and Android with your React Native JavaScript code.

The Contentsquare Bridge is available as an NPM package, which includes the bridge and the necessary dependencies for specific versions of the SDKs.

To install the bridge, open a terminal and run the following commands from your application’s root directory:

Terminal window
npm install @contentsquare/react-native-bridge
cd ios && pod install

The Contentsquare module is the main module and the default export of our bridge.
The Currency module is only used to send Transactions, and contains all supported currencies.

import Contentsquare, { Currency } from '@contentsquare/react-native-bridge';

You do not need to do anything to start the SDK. Now that the SDK is a dependency of your app, it will autostart itself when your application starts.

Start your application, and check logs for this output:

CSLIB: Contentsquare SDK 4.11.2 starting in app: com.example.testapp

If the SDK isn’t working, verify that your app’s package name is tied to a Contentsquare project. Make sure you’ve communicated all variants of your app identifier to your Contentsquare.

Contentsquare provides logging capabilities that allow you to view the raw event data logged by your app in IDE (Android Studio, Xcode), 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.

To view SDK logs:

  1. Plug your Android phone into your computer (or use an emulator)
  2. Open Android Studio and start your app
  3. Open the Logcat view and select your phone or emulator
  4. Filter logs by CSLIB

In-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, you have to first make sure your app is launched in the background. Then, follow the appropriate method described as follows.

In Contentsquare, select the Mobile icon in the menu top bar and scan the QR code with your phone.

In Contentsquare, select the Mobile icon in the menu top bar then select your application ID, and “Copy this ADB command”.

Log 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.

  1. Start your app.
  2. Select the Mobile icon in the menu top bar then select Log Visualizer.
  3. Select the device to inspect.

At this stage, you should see an ‘App start’ or ‘App show’ event being logged.

Contentsquare collects usage data from your app users. To start tracking, you need your users’ consent for being tracked.

The 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.

For example, you can call optIn() when the user accepts your app’s privacy policy or tracking terms.

import React, { useState } from "react";
import { View, Text, Button } from "react-native";
import Contentsquare from "@contentsquare/react-native-bridge";
const PolicyConsentScreen = () => {
const [isTrackingAccepted, setIsTrackingAccepted] = useState(false);
const handleAcceptPolicy = () => {
setIsTrackingAccepted(true);
Contentsquare.optIn();
};
return (
<View>
<Text>Please accept our privacy policy to proceed.</Text>
<Button title="Accept Policy" onPress={handleAcceptPolicy} />
</View>
);
};
export default PolicyConsentScreen;

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.

Screen tracking is achieved by sending a screenview event each time a new screen is displayed on the user’s device.

Sending Screenview Events using the React Navigation Library

Section titled Sending Screenview Events using the React Navigation Library

The sending of screenview events can be handled within the NavigationContainer in React Navigation, which centralizes the logic and helps avoid unnecessary calls.

// This associates the screen name sent to Contentsquare to the screen name defined in the code
const screenEventByScreenName: Record<string, string> = {
Home: 'Home',
ProductList: 'Product List',
ProductDetails: 'Product #1',
};
export const Navigation = () => {
const navigationRef = useNavigationContainerRef<RootStackParamList>();
const routeNameRef = useRef<string>();
return (
<NavigationContainer
ref={navigationRef}
onReady={() => {
// Getting initial route name from navigation and sending a screen view event with Contentsquare SDK
const currentRouteName = navigationRef.getCurrentRoute()?.name;
if (currentRouteName && screenEventByScreenName[currentRouteName]) {
Contentsquare.send(screenEventByScreenName[currentRouteName]);
}
}}
onStateChange={() => {
// Getting route name from navigation and sending a screen view event with Contentsquare SDK
const currentRouteName = navigationRef.getCurrentRoute()?.name;
routeNameRef.current = currentRouteName;
if (currentRouteName && screenEventByScreenName[currentRouteName]) {
Contentsquare.send(screenEventByScreenName[currentRouteName]);
}
}}
>
<RootNavigator />
<PrivacyManager />
</NavigationContainer>
);
};

Implementation recommendations

Section titled Implementation recommendations

From 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)

Most events collected by the SDK require a screenview event to be sent first in order to associate the events with the correct screen. If a screenview event is not sent, the events will be discarded. To ensure proper tracking from the moment the app launches, trigger a screenview event immediately after the SDK has started.

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.

Testing your SDK implementation is essential to make sure data is being accurately captured and reported.

To test your setup, you should 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, Xcode or Log Visualizer to monitor data transmission and ensure everything is running smoothly.

Visualize events in Contentsquare

Section titled Visualize events in Contentsquare

Use 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 Contentsquare

Open 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.

Open Session Replay in Contentsquare and replay the full user session across your app.

See how to use Session Replay on the Help Center

To explore some of these features in context, check our React Native sample apps.

react-native-sample-app

Sample apps illustrating how to use the Contentsquare Bridge for React Native in your app

TypeScript

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.