Clevertap Push Notifications
CleverTap Push Notifications Integration
This document outlines the integration of CleverTap notifications into the iOS application, focusing on handling and tracking notifications for enhanced user engagement and analytics.
Follow the given steps in AppDelegate.swift
Step 1: Setting Up CleverTap
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
...
PartnerAnalyticsTracker.configureClevertapAnalytics(
cleverTapEventTrackPermission: true,
cleverTapEventListenerEnabled: true,
listeners: [self] as [ParterClevertapNotifier]
)
...
return true
}
Explanation:
-
Configures CleverTap analytics when the app launches.
-
Enables event tracking (
cleverTapEventTrackPermission: true
) and event listening (cleverTapEventListenerEnabled: true
). -
Registers
self
as a listener conforming to theParterClevertapNotifier
protocol for handling CleverTap events.
Step 2: Handling Foreground Notifications
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
...
CleverTap.sharedInstance()?.handleNotification(
withData: notification.request.content.userInfo,
openDeepLinksInForeground: true
)
...
completionHandler([.alert, .badge, .sound])
}
Explanation:
-
Handles notifications presented while the app is in the foreground.
-
Passes notification data to CleverTap for processing.
-
Uses
openDeepLinksInForeground: true
to handle deep links directly in the app's foreground.
Step 3: Tracking CleverTap Events
extension AppDelegate: ParterClevertapNotifier {
func trackClevertapEvents(eventName: String, props: [AnyHashable: Any]) {
print("CleverTap props")
print(props)
}
}
Explanation:
- Implements the
trackClevertapEvents
method from theParterClevertapNotifier
protocol. - Logs event names and associated properties (
props
) tracked through CleverTap for debugging and analytics purposes.