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.

Our iOS SDK is shipped as a .xcframework which you need to add as a dependency of your project.

See Compatibility for more information.

The SDK requires Xcode 15 or later, if you are using older versions of Xcode reach out to your Contentsquare contact for more information.

  1. For iOS 13 and later, add the following link via File > Add Packages… in XCode:

    https://github.com/ContentSquare/apple-sdk.git
  2. Remove https://github.com/apple/swift-protobuf.git if you have added it prior to version 4.35.1.

  3. To ensure the library can start properly you will need to add -ObjC as a linker flag under Build Settings > Linking > Other Linker Flags.

The SDK autostarts when your application launches, requiring no manual initialization.

Start your application, and check logs for this output:

CSLIB ℹ️ Info: Contentsquare SDK v4.40.1 starting in app: com.example.testapp

Contentsquare provides logging capabilities that allow you to inspect the raw event data logged by your app in Xcode, the macOS Console app, 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 Xcode or the Console app

Section titled Viewing logs in Xcode or the Console app

To view SDK logs:

  1. If using an actual device, make sure it is plugged to your Mac or is on the same Wi-Fi network.

  2. Start the macOS Console app or Xcode.

    If using the Console app, make sure that info messages are included: Choose Action > Include Info Messages.

  3. Filter logs by CSLIB

In-app features are essential for your implementation, as it includes key functionalities like snapshot creation and replay configuration.

In order to allow Contentsquare users to enable in-app features:

  1. Add the custom URL scheme in your app Info
  2. Call the SDK when the app is launched via a deeplink

1. Add the custom URL scheme in your app Info

Section titled 1. Add the custom URL scheme in your app Info

You have to allow your app to be opened via a custom URL scheme which can be done using one of the following methods:

  1. Open your project settings
  2. Select the app target
  3. Select the Info settings
  4. Scroll to URL Types
  5. Set the URL scheme to cs-$(PRODUCT_BUNDLE_IDENTIFIER)
  1. Open the Info.plist of your project

  2. Add the following snippet:

    Info.plist
    <key>CFBundleURLTypes</key>
    <array>
    <dict>
    <key>CFBundleURLSchemes</key>
    <array>
    <string>cs-$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    </array>
    </dict>
    </array>
Section titled 2. Call the SDK when the app is launched via a deeplink

Depending of the project, there are multiple ways to handle the deeplink opening. Choose the method matching your project structure:

In your AppDelegate class, enrich or implement the function application(app, open url:, options:) with: Contentsquare.handle(url: url)

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

Scan the QR Code (iOS)
Section titled On a simulator: with the custom link

If you are using a simulator, use the custom link to enable in-app features.

In Contentsquare, select the Mobile icon in the menu top bar then select your Bundle ID, and select “Copy this link”. Paste it in Safari on your simulator to trigger the in-app features.

On a simulator: with the Terminal

Section titled On a simulator: with the Terminal

In a Terminal console, open a URL in your current simulator with the following command (replacing CUSTOM_LINK with yours):

Terminal window
xcrun simctl openurl booted "CUSTOM_LINK"

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.

Log visualizer iOS app start

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.

Handle user consent by implementing a UI for privacy preferences.

Contentsquare.optIn()

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.

As a general rule of thumb, you should send your screenviews in viewWillAppear(_ animate: Bool) when using UIKit, in .onAppear() when using SwiftUI.

import ContentsquareModule
Contentsquare.send(screenViewWithName: String, cvars: [CustomVar] = [])

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

Testing 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 Xcode, macOS Console App, 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.

Log visualizer iOS activity

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 iOS sample app.

iOS-sample-app

A sample app giving an example implementation of the Contentsquare SDK

Swift

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.