Introduction
The Clevertap iOS SDK allows you to easily integrate Clevertap’s powerful mobile marketing automation and analytics capabilities into your iOS app. With Clevertap, you can gain valuable insights about your users, track their behavior, and engage them with personalized messaging and campaigns.
Prerequisites
- Before getting started, make sure you have an account with Clevertap.
- You should also have the latest version of Xcode installed on your development machine.
Installation
To install the Clevertap iOS SDK, you have two options:
Option 1: Using Cocoapods
If you are using Cocoapods, you can simply add the following line to your Podfile:
pod 'CleverTap-iOS-SDK'
Then, run pod install
in your project directory to install the Clevertap iOS SDK.
Option 2: Manual installation
If you prefer not to use Cocoapods, you can manually install the Clevertap iOS SDK by following these steps:
- Download the latest version of the Clevertap iOS SDK from the Clevertap website.
- Unzip the downloaded file and locate the Clevertap.framework folder.
- Drag and drop the Clevertap.framework folder into your Xcode project’s frameworks folder.
- Make sure that the “Copy items if needed” option is selected.
- In your Xcode project’s target settings, go to the General tab.
- Scroll down to “Frameworks, Libraries, and Embedded Content” and click the “+” button.
- Select Clevertap.framework from the list and click Add.
Getting Started
Before you can start using the Clevertap iOS SDK, you need to initialize it with your Clevertap account credentials. Typically, you would do this in your app delegate’s didFinishLaunchingWithOptions
method.
import CleverTapSDK
// ...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
CleverTap.autoIntegrate()
// Add any additional configuration code here
return true
}
Make sure to replace autoIntegrate()
with autoIntegrate(withCleverTapID: "YOUR_CLEVERTAP_ACCOUNT_ID", andCleverTapToken: "YOUR_CLEVERTAP_ACCOUNT_TOKEN")
if you want to specify your Clevertap account credentials explicitly.
Tracking Events
Once you have integrated the Clevertap iOS SDK into your app, you can start tracking events to gain insights about your users’ behavior. You can track custom events, as well as predefined events provided by Clevertap.
Tracking Custom Events
To track a custom event, use the following code:
CleverTap.sharedInstance()?.recordEvent("Event Name")
You can also include properties with your custom event:
let eventProperties = ["Property 1": "Value 1", "Property 2": "Value 2"]
CleverTap.sharedInstance()?.recordEvent("Event Name", withProps: eventProperties)
Tracking Predefined Events
Clevertap provides a set of predefined events that you can track. These events include App Launched, App Installed, and many more. To track a predefined event, use the event name as shown above.
User Profiles
The Clevertap iOS SDK allows you to manage user profiles and store additional information about your users. You can set user properties, track user actions, and segment your users based on their behavior.
Setting User Properties
You can set user properties such as name, email, and more using the following code:
let profileProperties = ["Name": "John Doe", "Email": "john.doe@example.com"]
CleverTap.sharedInstance()?.profilePush(profileProperties)
You can also update individual user properties:
CleverTap.sharedInstance()?.profileSet("Name", value: "New Name")
Tracking User Actions
In addition to events, you can also track user actions using the following code:
CleverTap.sharedInstance()?.recordChargedEvent(withDetails: chargeDetails, andItems: transactionItems)
Segmenting Users
To segment your users based on their behavior, you can use Clevertap’s audience segmentation feature. For example, you can segment users who have made a purchase in the last 30 days by using the following code:
let event: [AnyHashable: Any] = ["propertyName": "purchased", "count": 1, "days": 30, "event": "App Launched"]
CleverTap.sharedInstance()?.record(event)
Push Notifications
With the Clevertap iOS SDK, you can easily send push notifications to your users. To enable push notifications, you need to perform the following steps:
Configure Push Notifications
- Enable push notifications for your app in your Apple Developer account and obtain the necessary certificates and keys.
- In your Xcode project, go to the Capabilities tab and enable the Push Notifications capability.
- Upload the relevant certificates and keys to your app’s push notifications settings in the Clevertap dashboard.
Register for Push Notifications
Register for push notifications in your app delegate’s didFinishLaunchingWithOptions
method:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
CleverTap.autoIntegrate()
CleverTap.sharedInstance()?.registerForPushNotifications()
// ...
return true
}
Conclusion
Congratulations! You have successfully integrated the Clevertap iOS SDK into your iOS app. You can now take advantage of Clevertap’s powerful mobile marketing automation and analytics capabilities to engage your users and drive growth.