Can't find error in Google Analytics API tracker code

非 Y 不嫁゛ 提交于 2019-12-24 07:37:05

问题


I have added all frameworks & have other GA API code implemented and returning analytics. Not sure what the error is? I'm getting "no known instance for selector 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];
}

回答1:


Try this:

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



回答2:


You can try this, it works for me

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]];



回答3:


You're getting that error because you're missing the Label field. Also, the Value should be an NSNumber, and you've got an int.

See Google's Event Tracking - iOS SDK doco, where it states:

An event consists of four fields that you can use to describe a user's interaction with your app content:

  • NSString Category
  • NSString Action
  • NSString Label
  • NSNumber (Optional) Value, interpreted as 64-bit integer

Your code should look something like this:

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



回答4:


This solution worked.

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


来源:https://stackoverflow.com/questions/18280439/cant-find-error-in-google-analytics-api-tracker-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!