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.
Before you begin
Section titled Before you beginThis guide assumes you are using Xcode with either Swift Package Manager ↗ or CocoaPods ↗ to manage external dependencies.
Install the SDK
Section titled Install the SDK-
In your XCode project >
Package Dependencies
, add this repository location:https://github.com/ContentSquare/apple-sdk.git -
Set the Dependency Rule to
Exact Version
1.1.0-rc.1
. -
Select
Add Package
. -
To ensure the library can start properly, add
-ObjC
as a linker flag underBuild Settings
>Linking - General
>Other Linker Flags
.
-
Add the following line to your Podfile:
Podfile pod 'ContentsquareSDK', '~> 1.0.0' -
Build your app target.
Start the SDK
Section titled Start the SDK-
Import the
ContentsquareSDK
module inAppDelegate
:AppDelegate.swift import UIKitimport ContentsquareSDK@UIApplicationMainclass AppDelegate: UIResponder, UIApplicationDelegate {var window: UIWindow?func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {// ...}}AppDelegate.m #import <UIKit/UIKit.h>#import <ContentsquareSDK/ContentsquareSDK.h>@interface AppDelegate : UIResponder <UIApplicationDelegate>@property (strong, nonatomic) UIWindow *window;@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// ...}@end -
Initialize SDK configuration with
CSQ.configureProductAnalytics()
.AppDelegate.swift import UIKitimport ContentsquareSDK@UIApplicationMainclass AppDelegate: UIResponder, UIApplicationDelegate {var window: UIWindow?func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {// ...CSQ.configureProductAnalytics(environmentID: "YOUR_ENVIRONMENT_ID")}}AppDelegate.m #import <UIKit/UIKit.h>#import <ContentsquareSDK/ContentsquareSDK.h>@interface AppDelegate : UIResponder <UIApplicationDelegate>@property (strong, nonatomic) UIWindow *window;@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// ...[CSQ configureProductAnalyticsWithEnvironmentID:@"YOUR_ENVIRONMENT_ID"];return YES;}@end -
Recommended for UIKit Enable autocapture.
CSQ.configureProductAnalytics(environmentID: "YOUR_ENVIRONMENT_ID",additionalOptions: [.enableUIKitAutocapture: true])[CSQ configureProductAnalyticsWithEnvironmentID:@"YOUR_ENVIRONMENT_ID"additionalOptions:@{CSQProductAnalyticsOptionEnableUIKitAutocapture: @(YES)}]; -
(Optional) If your Product Analytics environment is hosted in the EU, set the
baseURL
option tohttps://mh.ba.contentsquare.net
.CSQ.configureProductAnalytics(environmentID: "YOUR_ENVIRONMENT_ID",additionalOptions: [.enableUIKitAutocapture: true,.baseURL: "https://mh.ba.contentsquare.net"])[CSQ configureProductAnalyticsWithEnvironmentID:@"YOUR_ENVIRONMENT_ID"additionalOptions:@{CSQProductAnalyticsOptionEnableUIKitAutocapture: @(YES),CSQProductAnalyticsOptionBaseURL: @"https://mh.ba.contentsquare.net"}]; -
Add a call to
CSQ.start()
after the configuration:CSQ.configureProductAnalytics(environmentID: "YOUR_ENVIRONMENT_ID",additionalOptions: [.enableUIKitAutocapture: true])CSQ.start()[CSQ configureProductAnalyticsWithEnvironmentID:@"YOUR_ENVIRONMENT_ID"additionalOptions:@{CSQProductAnalyticsOptionUploadInterval: @(5),CSQProductAnalyticsOptionBaseUrl: @"https://example.com/",CSQProductAnalyticsOptionCaptureVendorId: @(YES),CSQProductAnalyticsOptionDisablePageviewTitleCapture: @(YES),CSQProductAnalyticsOptionEnableUIKitAutocapture: @(YES)}];[CSQ start]; -
Start your application, and check logs for this output:
CSLIB ℹ️ Info: Contentsquare SDK v1.0.0 starting in app: com.example.testapp
Get user consent
Section titled Get user consentThe 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 UIKitimport ContentsquareSDK
optinButton.addTarget(self, action: #selector(optInButtonTapped), for: .touchUpInside)
@objc func optInButtonTapped(_ sender: UIButton) { CSQ.start() CSQ.optIn() ...}
#import <UIKit/UIKit.h>#import <ContentsquareSDK/ContentsquareSDK.h>[optinButton addTarget:self action:@selector(optInButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
- (void)optInButtonTapped:(UIButton *)sender { [CSQ start]; [CSQ optIn]; // Additional initialization or navigation code...}
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.
Next steps
Section titled Next stepsOur 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.