找不到在谷歌Analytics(分析)API跟踪代码错误(Can't find error

2019-10-18 11:57发布

我添加了所有的框架和已实施其他GA API代码和返回的分析。 不知道是什么错误? 我得到“的选择sendEventWithCategory没有已知的实例:

(IBAction)didTouchOnInviteButton
{
    ContactListViewController *contactsViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewControllerId"];
    contactsViewController.mode = modeInviteToEvent;
    contactsViewController.event = self.event;
    [self.navigationController pushViewController:contactsViewController animated:YES];

    id <GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
    [tracker sendEventWithCategory:@"Contacts" withAction:@"Invite Button Pressed" withValue:1];
}

Answer 1:

尝试这个:

[[GAI sharedInstance].defaultTracker sendEventWithCategory:@"Contacts" withAction:@"Invite Button Pressed" withLabel:nil withValue:@1];


Answer 2:

你可以试试这个,它为我工作

id <GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"Contacts"
                                                      action:@"Invite Button Pressed"
                                                       label:@"Your label goes here..."
                                                       value:[NSNumber numberWithInt:1]] build]];


Answer 3:

你是因为你缺少收到这个错误Label领域。 此外,该Value应该是一个NSNumber ,和你有一个int

见谷歌的事件跟踪- iOS的SDK DOCO,它规定:

事件包含四个字段,你可以用它来描述与应用内容的用户交互的:

  • NSString的类别
  • NSString的行动
  • NSString的标签
  • 的NSNumber(可选)值,解释为64位整数

您的代码应该是这个样子:

id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker sendEventWithCategory:@"Contacts"
                    withAction:@"Invite Button Pressed"
                     withLabel:@"Your label goes here..."
                     withValue:[NSNumber numberWithInt:1]];


Answer 4:

该解决方案的工作。

[[GAI sharedInstance].defaultTracker sendEventWithCategory:@"Contacts" withAction:@"Invite Button Pressed" withLabel:nil withValue:@1];


文章来源: Can't find error in Google Analytics API tracker code