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, 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 the following two options:
- Install it with CocoaPods
- Install it manually by including the SDK source code in your Xcode project
Install using CocoaPods (Recommended)
To install SDK using CocoaPods:
- Add the CleverTap SDK to your Podfile as shown below.
pod "CleverTap-iOS-SDK"
- After you have updated your Podfile, run pod install in your terminal to download automatically.
- Install the SDK in your project.
Install Manually
To install the SDK manually:
- Download and unzip the CleverTap SDK.
- Drag the
CleverTapSDK.xcodeproj
inside your project under the main project file. - Embed the framework.
- Select your
app.xcodeproj
file. - Under General, add the CleverTapSDK framework as an embedded binary.


Additional
SDWebImage
Library Required for Manual IntegrationYou need to integrate the
SDWebImage
library for supporting images and GIFs in App Inbox and Native In-Apps for manual integration.
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:
- Navigate to the
Info.plist file
from your project navigator.


- Create a key called
CleverTapAccountID
with a type string. - Create a key called
CleverTapToken
with a type string. - Insert the account ID and account Token values from your CleverTap account. These values are available under the Settings page.


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 yourInfo.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 module map, which allows importing the SDK as a module rather than using a bridging header.
For bridging header on the CleverTap iOS SDK github, refer to the example implementation.
Integrate CleverTap SDK
Use one of the following options to integrate the appropriate SDK.
Objective-C
To integrate the CleverTap SDK for Objective-C:
- Import
CleverTap.h
to yourAppDelegate.h
file.


- Import
CleverTap.h
into every class where you plan to record user events.
For example, in the application below, we record user events in theViewController
class by importingCleverTap.h
in theViewController.h
file.


Swift
To integrate CleverTap SDK for Swift:
- Import CleverTapSDK to your
AppDelegate.swift
file.


- In your
AppDelegate.m
file, add [CleverTap autoIntegrate] within theapplication: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 thegetLocation
method and get a warning while uploading your application to iTunes connect, add the keyNSLocationWhenInUseUsageDescription
in theinfo.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, 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.


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:
- Build a
NSDictionary
object with the profile properties. - Call the SDK's
Onuserlogin
method and pass theNSDictionary
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",
@"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 is sent to CleverTap.
To see how this information displays within the CleverTap dashboard, proceed as follows:
- Log in to the dashboard.
- 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.


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
After 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 following example 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 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.


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 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 5 days ago