Can't find error in Google Analytics API track

2019-07-27 10:11发布

问题:

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