Search code examples
objective-ciosxcodegoogle-analyticsios6

what is the proper way to track an event in Google Analytics 2 for iOS


I am using Google Analytics Beta 2.0 to track events in an iOS application.

Screen tracking seems to be not an issue, but when I attempt to track an event the website states it says "122 of your visits sent events", but there are no events tracked.

Here is the code for the event tracking:

[self.tracker trackEventWithCategory:@"Question Results"
                              withAction:@"Finished questions"
                               withLabel:@"Testing"
                               withValue:[NSNumber numberWithInt:1]];

Which is straight from the google analytics website.

Thanks for the assistance.


Solution

  • Try this code. It works for me.

    [[GAI sharedInstance].defaultTracker trackEventWithCategory:@"UIAction"
                                                     withAction:@"buttonPress"
                                                      withLabel:@"Next button to second page"
                                                      withValue:[NSNumber numberWithInt:1]];
    

    Add the above code into -(IBAction)buttonClicked:(id)sender;

    In your Google Analytics page go to app home -> my dashboard -> in that choose add widget -> choose table in that add a Dimension as Event Label, add a metric as Event Value and add a metrics to total events and save.

    Don't forget to choose the date which is in the right-top corner.

    Once the event is fired it ll added in google analytics. but it ll take time to show events in Google Analytics.