AMX SDK is a SDK provided to track user activities and user life cycle.
- Note : You need to share your firebase server key with us
- Note : Firebase is included in this project
To run the example project, clone the repo, and run pod install
from the Example directory first.
AMXSDK is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'AMXSDK'
Get an api key from us using the link
Import the following in AppDelegate
import AMXSDK
import Firebase
import UserNotifications
For didFinishLaunchingWithOptions
method for AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
AMX(appDelegate: application).setKey(apiKey: "YOUR_API_KEY_HERE")
Messaging.messaging().delegate = self
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self
} else {
// Fallback on earlier versions
}
let token = Messaging.messaging().fcmToken
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
AMX.setTracking()
}
For Firebase methods add these extensions to existing Firebase code if present
// [START ios_10_message_handling]
@available(iOS 10, *)
extension AppDelegate : UNUserNotificationCenterDelegate {
// Receive displayed notifications for iOS 10 devices.
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
AMX.setNotifier(userInfo: userInfo)
print(userInfo)
// Change this to your preferred presentation option
completionHandler([[.alert, .sound]])
}
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
AMX.setNotifier(userInfo: userInfo)
print(userInfo)
completionHandler()
}
}
// [END ios_10_message_handling]
extension AppDelegate : MessagingDelegate {
// [START refresh_token]
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
print("Firebase registration token: \(String(describing: fcmToken))")
let dataDict:[String: String] = ["token": fcmToken ?? ""]
NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
}
// [END refresh_token]
}
For Event Tracking :
let payload = ["ANY KEY" : anyValue]
let event = Event.init(eventName: "EVENT_NAME", payload: payload)
AMX.setEvent(event: event)
Pranjal, [email protected]
AMXSDK is available under the MIT license. See the LICENSE file for more info.