DIAnalytics 0.1.5

DIAnalytics 0.1.5

Mathieu JuneauMathieu Juneau 维护。



 
依赖关系
Firebase/Core~> 6.0
Firebase/Messaging~> 6.0
Firebase/Analytics~> 6.0
 

  • Dialog Insight

DIAnalytics

Version License Platform

需求

  • Firebase 项目
  • Firebase Console 中配置了 Firebase Cloud Messaging。有关更多信息,请参阅 Firebase Cloud Messaging 文档
  • Firebase 项目的 "GoogleService-Info.plist" 文件。
  • 由 Dialog Insight 提供的应用 ID

安装

DIAnalytics 通过 CocoaPods 提供访问。要安装,只需将以下行添加到您的 Podfile

pod "DIAnalytics"

使用方法

  1. 将Firebase提供的 "GoogleService-Info.plist" 添加到项目的根目录。确保文件位于您的目标项目的 "复制 bundle 资源" 之中。

  2. 将以下代码添加到您的 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];
}
  1. 设置您的偏好。
[DIAnalytics setLogEnabled:YES];
[DIAnalytics setBaseUrl:@"https://ofsys.com"];
  1. 在使用 Dialog Insight 提供的应用 ID 中实现 "didFinishLaunchingWithOptions" 方法时启动库。
[DIAnalytics startWithApplicationId:@"MY_APPLICATION_ID_PROVIDED_BY_DIALOG_INSIGHT" withLaunchOptions:launchOptions];
  1. 发送用户信息。

    为了将应用程序中的用户识别为您的DI项目的联系人,您必须提供对应于唯一键字段的相应信息。

    注意:DI字段始终以“f_”开头。在DI项目字段页面上,查看标记为“主字段”的字段并记录它们的代码。在以下步骤中,只需将“f_”前缀与任何字段代码组合即可。例如,代码为“idCustomer”的DI字段将变为“f_idCustomer”。

    这分两个简单步骤完成。首先,将主键字段信息收集到一个字典中。

    例如,唯一键仅由电子邮件字段组成的项目中,执行以下操作:

    NSMutableDictionary *customFieldsDictionary = [[NSMutableDictionary alloc] init];
    [customFieldsDictionary setObject:self.emailTextField.text forKey:@"f_EMail"];

    对于唯一键由FirstName和LastName字段组成的项目,执行以下操作:

    NSMutableDictionary *customFieldsDictionary = [[NSMutableDictionary alloc] init];
    [customFieldsDictionary setObject:self.firstNameTextField.text forKey:@"f_FirstName"];
    [customFieldsDictionary setObject:self.nameTextField.text forKey:@"f_LastName"];

    对于唯一键仅由“idCustomer”字段组成的项目,执行以下操作:

    NSMutableDictionary *customFieldsDictionary = [[NSMutableDictionary alloc] init];
    [customFieldsDictionary setObject:self.idCustomerTextField.text forKey:@"f_idCustomer"];

    然后,再创建一个包含“contact”条目的另一个字典并发送。

    NSDictionary *contactDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:customFieldsDictionary, @"contact", nil];
    
    [DIAnalytics identify:contactDictionary];
  2. 注册推送通知。这会提示用户使用UIAlertView请求授权通知。

[DIAnalytics registeForRemoteNotification];

作者

Dialog Insight,[email protected]

许可证