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.
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-prereleases.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 -
Add a call to
CSQ.start()
after the configuration:AppDelegate.swift import UIKitimport ContentsquareSDK@UIApplicationMainclass AppDelegate: UIResponder, UIApplicationDelegate {var window: UIWindow?func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {// Configure and start the SDKCSQ.start()return true}}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 {// Configure and start the SDK[CSQ start];return YES;}@end -
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...}
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, 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.
Sending screenview events
Section titled Sending screenview eventsScreen 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] = [])
@import ContentsquareSQK;
[CSQ trackScreenview:(NSString * _Nonnull)];// or[CSQ trackScreenview:(NSString * _Nonnull) cvars:(NSArray<CustomVar *> * _Nonnull)]; // To add custom variables to screen tracking
For more information see Implementation recommendations
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.