Getting Started with Experience Analytics

This quick start guide shows you how to get Contentsquare Experience Analytics set up in an iOS 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.

This guide assumes you are using Xcode with either Swift Package Manager or CocoaPods to manage external dependencies.

  1. In your XCode project > Package Dependencies, add this repository location:

    https://github.com/ContentSquare/apple-sdk-prereleases.git
  2. Set the Dependency Rule to Exact Version 1.1.0-rc.1.

  3. Select Add Package.

  4. To ensure the library can start properly, add -ObjC as a linker flag under Build Settings > Linking - General > Other Linker Flags.

  1. Import the ContentsquareSDK module in AppDelegate:

    AppDelegate.swift
    import UIKit
    import ContentsquareSDK
    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    ...
    }
    }
  2. Add a call to CSQ.start() after the configuration:

    AppDelegate.swift
    import UIKit
    import ContentsquareSDK
    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Configure and start the SDK
    CSQ.start()
    return true
    }
    }
  3. Start your application, and check logs for this output:

    CSLIB ℹ️ Info: Contentsquare SDK v1.0.0 starting in app: com.example.testapp

The 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 UIKit
import ContentsquareSDK
optinButton.addTarget(self, action: #selector(optInButtonTapped), for: .touchUpInside)
@objc func optInButtonTapped(_ sender: UIButton) {
CSQ.start()
CSQ.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.

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.

Screen tracking is achieved by sending a screenview event:

  • Right after the SDK has started
  • When the screen appears
  • When a modal/pop-up is closed and the user is back on the screen
  • When the app is put in the foreground (after an app hide)

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

import ContentsquareSQK
CSQ.trackScreenview(String, cvars: [CustomVar] = [])

For more information see Implementation recommendations

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.