DIAnalytics
Requirements
- Firebase Project
- Firebase Cloud Messaging configured in Firebase console. For more information, refer to Firebase Cloud Messaging docs
- Firebase project's "GoogleService-Info.plist".
- Application ID provided by Dialog Insight
Installation
DIAnalytics is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "DIAnalytics"
Usage
-
Add your "GoogleService-Info.plist" provided by Firebase to the root of your project. Ensure that the file is in the "Copy Bundle Resources" of your target project.
-
Add the following code to your AppDelegate:
#pragma mark - Notification delegate
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[DIAnalytics handleDidReceiveRemoteNotification:userInfo];
if (application.applicationState == UIApplicationStateActive ) {
NSLog(@"Application is in foreground when it received the notification, application should handle display of notification.");
}
}
//For iOS under 10, you must implement these two methods to register for a token
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"Unable to register for remote notifications: %@", error);
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[DIAnalytics handleDidRegisterForRemoteNotificationWithDeviceToken:deviceToken];
}
- Setup your preference.
[DIAnalytics setLogEnabled:YES];
[DIAnalytics setBaseUrl:@"https://ofsys.com"];
- Start the library with your ApplicationID provided by Dialog Insight in your "didFinishLaunchingWithOptions" implementation.
[DIAnalytics startWithApplicationId:@"MY_APPLICATION_ID_PROVIDED_BY_DIALOG_INSIGHT" withLaunchOptions:launchOptions];
-
Send information about the user.
In order to identify a user of the application as a contact of your DI project, you must provide the information corresponding to the fields of the unique key.
Note: the DI fields always start with a "f_". In the DI project fields page, look at the fields tagged as “primary field” and note their code. In the following steps, just prepend “f_” with any field code. For instance, a DI field with the code “idCustomer” will become “f_idCustomer”.
This is made in two simples step. First, gather the primary key fields informations in a dictionary.
For example, a project where the unique key is composed only of the EMail field, do:
NSMutableDictionary *customFieldsDictionary = [[NSMutableDictionary alloc] init]; [customFieldsDictionary setObject:self.emailTextField.text forKey:@"f_EMail"];
For a project where the unique key is composed of the fields FirstName and LastName, do:
NSMutableDictionary *customFieldsDictionary = [[NSMutableDictionary alloc] init]; [customFieldsDictionary setObject:self.firstNameTextField.text forKey:@"f_FirstName"]; [customFieldsDictionary setObject:self.nameTextField.text forKey:@"f_LastName"];
For a project where the unique key is composed only of a field named “idCustomer”, do:
NSMutableDictionary *customFieldsDictionary = [[NSMutableDictionary alloc] init]; [customFieldsDictionary setObject:self.idCustomerTextField.text forKey:@"f_idCustomer"];
Then, make another dictionary with a “contact” entry and send it.
NSDictionary *contactDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:customFieldsDictionary, @"contact", nil]; [DIAnalytics identify:contactDictionary];
-
Register for push notification. This will prompt to user an UIAlertView asking to authorize notifications.
[DIAnalytics registeForRemoteNotification];
Authors
Dialog Insight, [email protected]