Product Analytics

This quick start guide shows you how to get Contentsquare Product Analytics set up in an iOS application.

Once you’ve completed the setup process, the Contentsquare SDK will capture a wide variety of user interactions in your application with no additional code required.

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.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. Initialize SDK configuration with CSQ.configureProductAnalytics().

    AppDelegate.swift
    import UIKit
    import ContentsquareSDK
    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // ...
    CSQ.configureProductAnalytics(
    environmentID: "YOUR_ENVIRONMENT_ID"
    )
    }
    }
  3. Recommended for UIKit Enable autocapture.

    CSQ.configureProductAnalytics(
    environmentID: "YOUR_ENVIRONMENT_ID",
    additionalOptions: [
    .enableUIKitAutocapture: true
    ]
    )
  4. (Optional) If your Product Analytics environment is hosted in the EU, set the baseURL option to https://mh.ba.contentsquare.net.

    CSQ.configureProductAnalytics(
    environmentID: "YOUR_ENVIRONMENT_ID",
    additionalOptions: [
    .enableUIKitAutocapture: true,
    .baseURL: "https://mh.ba.contentsquare.net"
    ]
    )
  5. Add a call to CSQ.start() after the configuration:

    CSQ.configureProductAnalytics(
    environmentID: "YOUR_ENVIRONMENT_ID",
    additionalOptions: [
    .enableUIKitAutocapture: true
    ]
    )
    CSQ.start()
  6. 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()
...
}

Once tracking has started, you’re able to take full advantage of the CSQ SDK API to identify users, track custom events, and more.

Contentsquare’s Product Analytics module will also automatically start tracking a wide range of user interactions, view controller changes, and app version changes without any additional code.

Our SDK offers a wide range of features to enhance your implementation, including extended tracking capabilities, and personal data masking.

Session Replay and Error Monitoring are both available with the Experience Analytics Extension, which you can purchase separately.