Getting Started
Welcome to the SDK implementation guide!
This guide is designed to help you quickly and seamlessly integrate our SDK into your application. By following the steps outlined here, you’ll be able to start collecting and analyzing data from your app, within a few minutes.
Checklist
Section titled ChecklistTechnical requirements
Section titled Technical requirementsBefore implementing the SDK, make sure your app is technically compatible. This helps prevent potential issues with integration and ensures optimal performance.
Requirement | Version/Details |
---|---|
iOS | iOS 12.4 and later Data collection begins at iOS 13.0. |
Xcode Simulator Support | iOS 12.4 and later |
Swift | 4.2 and later |
Objective-C | Supported |
UI Frameworks | UIKit SwiftUI |
React Native | iOS 12.4 and later |
Device Compatibility | Devices released since 2014 support iOS 12.4 |
Contentsquare project setup
Section titled Contentsquare project setupProvide your bundle ID to Contentsquare
Section titled Provide your bundle ID to ContentsquareProvide the value of the Bundle identifier
property to Contentsquare.
The bundle ID is required to generate your project configuration.
Validate Contentsquare account and project ID
Section titled Validate Contentsquare account and project IDOnce Contentsquare has created your project, make sure you have been provided with access to a Contentsquare account and a valid project ID. Each project ID corresponds to a specific data collection setup. Without a project ID, you won’t be able to send data to your project.
If you don’t have access to a dedicated project, reach our to your Implementation Manager.
Install the SDK
Section titled Install the SDKOur iOS SDK is shipped as a .xcframework
which you need to add as a dependency of your project.
Include the SDK
Section titled Include the SDKThe SDK requires Xcode 15 or later, if you are using older versions of Xcode reach out to your Contentsquare contact for more information.
-
For iOS 13 and later, add the following link via
File > Add Packages…
in XCode: -
Remove
https://github.com/apple/swift-protobuf.git
if you have added it prior to version 4.35.1. -
To ensure the library can start properly you will need to add
-ObjC
as a linker flag underBuild Settings
>Linking
>Other Linker Flags
.
Static linking is the default behavior with use_frameworks!
.
-
Add the following line to your Podfile:
-
Remove
pod 'SwiftProtobuf', '<= 1.26.0'
if you have added it prior to version 4.35.1. -
For iOS 13 and later, add the following line to your Podfile:
Known Issues
-
Updating
IPHONEOS_DEPLOYMENT_TARGET
in yourpost_install
may have the following error.Workaround: Skip updating IPHONEOS_DEPLOYMENT_TARGET for SwiftProtobuf by following these steps.
-
Update your
post_install
to: -
Rerun
pod install
. -
Clean Builder Folder.
-
Rebuild.
-
Not yet supported.
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.
Validate SDK integration
Section titled Validate SDK integrationStart your application, you should see the SDK print a log like this one:
If the SDK does not seem to work, it might mean that your app’s bundle identifier is not tied to any Contentsquare project. In that case, you will have to communicate all variants of your app’s bundle identifier to your Contentsquare contact to be added as a project.
Now that the SDK runs in your app, you will want to implement calls to our SDK to track screenviews, transactions, and more. Keep following along this guide to know how.
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 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 appTo view SDK logs:
-
If using an actual device, make sure it is plugged to your Mac or is on the same Wi-Fi network.
-
Start the macOS Console app or Xcode.
If using the Console app, make sure that info messages are included: Choose Action > Include Info Messages ↗.
-
Filter logs by
CSLIB
Implement in-app features
Section titled Implement in-app featuresIn order to allow Contentsquare users to enable in-app features, you must perform 2 implementation tasks:
1. Add the custom URL scheme in your app Info
Section titled 1. Add the custom URL scheme in your app InfoYou have to allow your app to be opened via a custom URL scheme which can be done using one of the following methods:
Xcode
Section titled Xcode- Open your project settings
- Select the app target
- Select the
Info
settings - Scroll to
URL Types
- Set the URL scheme to
cs-$(PRODUCT_BUNDLE_IDENTIFIER)
Text editor
Section titled Text editor-
Open the
Info.plist
of your project -
Add the following snippet:
2. Call the SDK when the app is launched via a deeplink
Section titled 2. Call the SDK when the app is launched via a deeplinkDepending 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 your WindowSceneDelegate
class, you need to:
-
Update
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions)
with: -
Enrich or implement
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>)
with:
In the body
of your main App struct, add the onOpenURL
modifier and call the Contentsquare
SDK to handle the URL:
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.
On a device: scan the QR code
Section titled On a device: scan the QR codeIf you have access to the Contentsquare platform, you can open the in-app features modal from the menu and scan the QR code with your phone.
On a simulator: with the custom link
Section titled On a simulator: with the custom linkIf you are using an simulator, you can use the custom link to enable in-app features.
If you have access to the Contentsquare platform, you can open the in-app features modal from the menu 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 TerminalIn a Terminal console, open a URL in your current simulator with the following command (replacing CUSTOM_LINK
with yours):
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.
The SDK will consider every new user to be opted-out by default. To start tracking, the SDK Opt-in API must be called.
User opt-in
Section titled User opt-inForward user consent with optIn()
. Calling this method generates a user ID and initiates tracking.
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, 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.
As a general rule of thumb, you should send your screenviews in viewWillAppear(_ animate: Bool)
when using UIKit, in .onAppear()
when using SwiftUI.
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, 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 Xcode, the 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 ContentsquareAs described previously, you can 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 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 iOS sample app.
iOS-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.