如何使用Google Analytics跟踪用户对MFMailComposeViewController的操作?

时间:2014-01-14 03:45:16

标签: ios objective-c google-analytics mfmailcomposeviewcontroller

如何使用Google Analytics跟踪用户对MFMailViewController的操作?我想看看人们如何使用它;即按取消,发送电子邮件,删除消息等。

1 个答案:

答案 0 :(得分:2)

在委托中实施以下方法:

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
 id tracker = [[GAI sharedInstance] defaultTracker];
 switch (result) {
     case MFMailComposeResultCancelled:
        [tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"ui_action"                                                               action:@"event_action"  // Event action (required)
            label:@"Cancelled"          // Event label
            value:nil] build]];    // Event value
          break;
     case MFMailComposeResultSaved:
        [tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"ui_action"                                                               action:@"event_action"  // Event action (required)
            label:@"Saved"          // Event label
            value:nil] build]];    // Event value
          break;
     case MFMailComposeResultSent:
        [tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"ui_action"                                                               action:@"event_action"  // Event action (required)
            label:@"Sent"          // Event label
            value:nil] build]];    // Event value
          break;
     case MFMailComposeResultFailed:
        [tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"ui_action"                                                               action:@"event_action"  // Event action (required)
            label:@"Failed"          // Event label
            value:nil] build]];    // Event value
          break;
     default:
          break;
 }
}