iOS SDK Quick Start Guide

Overview

CleverTap provides an iOS SDK that enables app developers to track, segment, and engage their users. This guide shows how to install the CleverTap SDK, track your first user event, and see this information within the CleverTap dashboard in less than ten minutes.

Install SDK

To use the CleverTap iOS SDK, you have two options. You can install it with CocoaPods or manually install it by including the SDK source code in your Xcode project.

Option A: Install using CocoaPods (Recommended)

Follow the steps below to install using CocoaPods:

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

Option B: Manual Install

Follow the steps below for a manual install:

  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.

Additional SDWebImage Library Required for Manual Integration

For a manual integration, you need to integrate SDWebImage library for supporting images and GIFs in App Inbox and Native In-Apps.

Add CleverTap Credentials

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

Perform the following steps:

  1. Navigate to the Info.plist file in your project navigator.
  1. Create a key called CleverTapAccountID with type string.
  2. Create a key called CleverTapToken with type string.
  3. Insert the account ID and account token values from your CleverTap account. These values are available on the Settings page. To navigate to the Settings page, log into your CleverTap account, click on the gear icon on the bottom left navigation, and select Settings dashboard.

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.

Installation Steps for Swift

Starting with v3.1.4, the SDK includes a modulemap which provides the ability to import the SDK as a module rather than using a bridging header.

Refer to the example implementation for bridging header on the CleverTap iOS SDK github.

SDK Integration

Use one of the following sections to integrate the appropriate SDK.

Objective-C

Follow the steps below for Objective-C:

  1. Import CleverTap.h to your AppDelegate.h file.
  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.

Swift

Follow the steps below for Swift:

  1. Import CleverTapSDK to your AppDelegate.swift file.
  1. In your AppDelegate.m 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.
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    ...
    [CleverTap autoIntegrate];
    ...
}
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject:AnyObject]?) -> Bool {
    ...
    CleverTap.autoIntegrate()
    ...
}

Purpose String in Info.plist

CleverTap has a getLocation method to track the location of users. In case you are not using the getLocation method and get a warning while uploading your application to iTunes connect, please add 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.

As an alternative to using the automatic integration method, you can manually turn on different CleverTap SDK features. For more information on the manual integration steps, refer to iOS Push Notifications.

Run Your Application

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

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 example below shows how to do this in Objective-C and Swift:

NSDictionary *profile = @{
                              //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];
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 will be sent to CleverTap.

Follow the steps below to see how this information displays within the CleverTap dashboard:

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

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

Track Custom Events

Once you integrate the CleverTap SDK, we automatically start tracking events, such as App Launch and Notification Viewed. In addition to the default 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 example below shows how to do this in both Objective-C and Swift:

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

Here is how to record the custom event within the viewDidLoad method:

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

Next Steps

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

In the next iOS guide, you will learn more advanced options for tracking custom events and enriching user profiles.

Updated 26 days ago


iOS SDK Quick Start Guide


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.