Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 841
Nathan Avatar asked Nov 16 '25 14:11

Nathan


2 Answers

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.

like image 78
Anamika Avatar answered Nov 19 '25 05:11

Anamika


You have to build the tracker send event with googleAnalytics. see follow

-(IBAction)buttonClicked:(id)sender{
 //Track your event with Google Analytics
 id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
 [tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"Category Name"
                                                      action:@"Event Action"
                                                       label:@"Action Label(Button)"
                                                       value:@"value (int)"] build]];
}
like image 43
Sarat Patel Avatar answered Nov 19 '25 05:11

Sarat Patel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!