iOS SDK Quick Start Guide

Overview

CleverTap provides an iOS SDK that enables app developers to track, segment, and engage users. This guide shows how to install the CleverTap SDK in your application, track your first user event, and see the user profiles and user events within the CleverTap dashboard quickly.

Install SDK

To use the CleverTap iOS SDK, you have the following options:

Install using CocoaPods (Recommended)

To install SDK using CocoaPods:

  1. Add the CleverTap SDK to your Podfile as shown below.
pod "CleverTap-iOS-SDK"
  1. After you have updated your Podfile, run pod install in your terminal to download automatically.
  2. Install the SDK in your project.

Install using Swift Package Manager

  1. Open the cleverTap-ios-sdk project page on GitHub and copy the clone URL(https://github.com/CleverTap/clevertap-ios-sdk) of the project.
  2. Now integrate CleverTap SDK in your application in Xcode. Go to File > Add Packages to add a new dependency.
  3. Specify the clone URL of the cleverTap-ios-sdk library. Keep the default version settings - the library will be updated after the next major release.
25572557 22982298

Install Manually

To install the SDK manually:

  1. Download and unzip the CleverTap SDK.
  2. Drag the CleverTapSDK.xcodeproj inside your project under the main project file.
  3. Embed the framework.
  4. Select your app.xcodeproj file.
  5. Under General, add the CleverTapSDK framework as an embedded binary.
26652665

📘

Additional SDWebImage Library Required for Manual Integration

You must integrate the SDWebImage library for supporting images and GIFs in App Inbox and Native In-Apps for manual integration. Follow the steps for integrating SDWebImage:

  1. Navigate to the Vendors/SDWebImage directory found under the cloned CleverTap iOS SDK repository.
  2. Drag and drop SDWebImage.xcodeproj into the main project file.
  3. Navigate to the project application’s target settings, open General, click the + button under the Frameworks, Libraries, and Embedded Content, add SDWebImage.framework as an embedded binary.
  1. Add the CleverTapSDK package product to the app target.

Add CleverTap Credentials

To associate your iOS app with your CleverTap account, you need to add your CleverTap credentials in the Info.plist file in your application. To do so:

  1. Navigate to the Info.plist file from your project navigator.
574574
  1. Create a key called CleverTapAccountID with a type string.
  2. Create a key called CleverTapToken with a type string.
  3. Insert the Project ID and account Project Token values from your CleverTap account. These values are available under the Settings page.

🚧

Credentials and Access

The CleverTapAccountId and CleverTapToken are available as Project ID and Project Token respectively on the CleverTap dashboard.
Member and Creator roles in the project don’t have access to view the Passcode and Project Token of the account on the dashboard.

27082708

📘

Disable IDFV Usage

Optionally, starting from CleverTap iOS SDK 3.9.4, you can disable the generation of CleverTap ID basis IDFV value. Add CleverTapDisableIDFV with type Boolean and set its value as 1 in your Info.plist file.
This is recommended for apps that send data from different iOS apps to a common CleverTap account.

Add Region Code

Refer to the following table to identify the region for your account:

To enable the CleverTap Region, complete the following step. In your applications’ Info.plist file, add a new key under the Information Property List with the type string. The name for key is CleverTapRegion and the value is in1 for India, sg1 for Singapore, us1 for U.S and eu1 is for EU region.

18141814

Integrate CleverTap SDK in iOS Applications

For integrating CleverTap SDK in Objective-C Application refer here.
For integrating CleverTap SDK in Swift Application refer here.

Objective-C installation steps:

To integrate the CleverTap SDK for Objective-C:

  1. Import CleverTap.h to your AppDelegate.h file.
988988
  1. Import CleverTap.h into every class where you plan to record user events.
    For example, in the application below, we record user events in the ViewController class by importing CleverTap.h in the ViewController.h file.
822822

Autointegrate CleverTap in your Obj-C Application

This creates an instance of the CleverTap class used to track app launches, receive in-app notifications, and enable deep-link tracking.
In your AppDelegate.m file, add [CleverTap autoIntegrate] within the application:didFinishLaunchingWithOptions: method.

- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    ...
    [CleverTap autoIntegrate];
    ...
}
14881488

Debug CleverTap SDK in Obj-C application

In your AppDelegate.m file, add [CleverTap setDebugLevel:CleverTapLogDebug]; within the application:didFinishLaunchingWithOptions: method. This is an optional step.
By default, CleverTap logs are set to CleverTapLogLevel.info. During development, we recommend that you set the SDK to DEBUG mode, in order to log warnings or other important messages to the iOS logging system. This can be done by setting the debug level to CleverTapLogLevel.debug. If you want to disable CleverTap logs for production environment, you can set the debug level to CleverTapLogLevel.off.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [CleverTap autoIntegrate];
    [CleverTap setDebugLevel:CleverTapLogDebug];
}

Swift installation steps:

To integrate CleverTap SDK for Swift:

  1. Import CleverTapSDK to your AppDelegate.swift file as given in the application below. Similarly import CleverTapSDK in every class file where you plan to record user events.

❗️

Bridging Headers for CleverTap v3.1.4 and below for Swift installation:

For bridging header on the CleverTap iOS SDK github, refer to the example implementation.
Starting with v3.1.4, the SDK now includes a module map, which allows importing the SDK as a module rather than using a bridging header.

Autointegrate CleverTap in your Swift Application

In your AppDelegate.swift file, add CleverTap.autoIntegrate() within the
application:didFinishLaunchingWithOptions: method.
This creates an instance of the CleverTap class used to track app launches, receive in-app notifications, and enable deep-link tracking.

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject:AnyObject]?) -> Bool {
    ...
    CleverTap.autoIntegrate()
    ...
}
22142214

Debug CleverTap SDK in your Swift Application

In your AppDelegate.swift file, add CleverTap.setDebugLevel(CleverTapLogLevel.debug.rawValue) within the
application:didFinishLaunchingWithOptions: method. This is an optional step. By default, CleverTap logs are set to CleverTapLogLevel.info. During development, we recommend that you set the SDK to DEBUG mode, in order to log warnings or other important messages to the iOS logging system. This can be done by setting the debug level to CleverTapLogLevel.debug. If you want to disable CleverTap logs for production environment, you can set the debug level to CleverTapLogLevel.off.rawValue.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        // Configure and init the default shared CleverTap instance (add CleverTap Account ID and Account Token in your .plist file)
        CleverTap.autoIntegrate()
        CleverTap.setDebugLevel(CleverTapLogLevel.debug.rawValue)
}
15441544

Get Location Information in Application

CleverTap has a getLocationWithSuccess method to track the location of users. We have to add CLEVERTAP_LOCATION = 1 macro.

  1. Go to Clevertap-iOS-SDK-iOS target and select build settings > find Apple Clang - Preprocessing column > click on Preprocessor Macros.
  2. Add CLEVERTAP_LOCATION=1 with the + button below.
  3. Run the application, and now location information will be logged to the CleverTap dashboard.
25802580

🚧

Purpose String in info.plist

If you are not using the getLocationWithSuccess method and see a warning while uploading your application to iTunes connect, add the key NSLocationWhenInUseUsageDescription in the info.plist with a string value.

🚧

Manual Integration

In a single line of code, the autoIntegrate method lets you automatically track app launches, receive in-app notifications, and enable deep-link tracking.

You can manually turn on different CleverTap SDK features as an alternative to the automatic integration method. For more information on the manual integration steps for setting up push notifications, refer to iOS Push Notifications.

Run Your Application

To run your application, navigate to your CleverTap dashboard. If you integrate the CleverTap SDK successfully, you see a new active user on the dashboard.

14051405

Identify Users

A user profile is automatically created in CleverTap for each user launching your application.

Initially, the user profile starts out as anonymous which means the profile does not contain any identifiable information about the user. You can enrich the profile with pre-defined attributes from the CleverTap data model, such as name and email. You can also add custom attributes that you define to extend the CleverTap data model.

Sending user profile information to CleverTap using our iOS SDK requires two steps:

  1. Build a NSDictionary object with the profile properties.
  2. Call the SDK's Onuserlogin method and pass the NSDictionary object you created as a parameter.

The following example shows how to do this in Objective-C and Swift:

NSDictionary *profile = @{
                              //Update pre-defined profile properties
                              @"Name": @"Jack Montana" as AnyObject,
                              @"Email": @"[email protected]" as AnyObject,
                              //Update custom profile properties
                              @"Plan Type": @"Silver" as AnyObject,
                              @"Favorite Food": @"Pizza" as AnyObject
                              };
    
[[CleverTap sharedInstance] onUserLogin:profile];
let profile: Dictionary<String, AnyObject> = [
    //Update pre-defined profile properties
    "Name": "Jack Montana",
    "Email": "[email protected]",
    //Update custom profile properties
    "Plan type": "Silver",
    "Favorite Food": "Pizza"
]

CleverTap.sharedInstance()?.onUserLogin(profile)

When the Onuserlogin method is called, the user profile information is sent to CleverTap.

To see how this information displays within the CleverTap dashboard:

  1. Log in to the CleverTap dashboard.
  2. Click Find People under the Segment tab. In the By Identity box, enter the email you set on the user profile record and click Find.
14071407

If CleverTap finds a user profile with this email, the user record is displayed. On that page, you will see name and email as pre-defined fields and any other custom fields.

29122912

Update the User Profile

The Onuserlogin method identifies the individual users on the device. However, you may need to add additional user properties to the user profile such as gender, date of birth, and so on. You can update these properties with the profilePush() method. For more information, refer to our User Documentation.

Track Custom Events

After you integrate the CleverTap SDK, we automatically start tracking events, such as App Launch and Notification Viewed. In addition to the default (system) events tracked by CleverTap, you can also track custom events.

To send custom events to CleverTap using our iOS SDK, you will have to call the recordEvent method with the name of the custom event you want to track.

The following example shows how to do this in both Objective-C and Swift:

[[CleverTap sharedInstance] recordEvent:@"Product Viewed"];
CleverTap.sharedInstance()?.recordEvent("Product viewed")

Now, looking at the same user profile in CleverTap from the previous step, click Activity within the user profile record, which shows a list of activities associated with the user profile. If the custom event is successfully sent from your application to CleverTap, you can see it in this list.

27222722

GDPR Compliance

From CleverTap iOS SDK 3.1.7 onwards, CleverTap provides APIs to support GDPR compliance. For more information, refer to iOS GDPR Compliance.

Sample Projects demonstrating direct implementation of CleverTap features:

  1. For an example project of integrating CleverTap SDK and using all its features in your Swift application, refer to the Github Swift Starter Project.

  2. For an example project of integrating CleverTap SDK and using all its features in your ObjC application, refer to the Github Objective-C Starter Project. Follow the same steps.

  3. For an example project of implementing CleverTap advanced push notifications and various push templates refer to CleverTap Notification Content. We have Swift starter and Obj-C starter applications in the repository for reference.

Next Steps

By completing this guide, you are now automatically tracking user events such as app launches and associating that information with profiles for each of your users. You have also learned how to debug, how to add information to a user profile and how to track custom events.

In the next iOS User Profiles, you will learn more advanced options for enriching user profiles.