Nathan
Nathan

Reputation: 1647

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.

Upvotes: 2

Views: 3363

Answers (3)

Aayushi
Aayushi

Reputation: 797

Swift 3

    let tracker = GAI.sharedInstance().defaultTracker
    let eventTracker: NSObject = GAIDictionaryBuilder.createEvent(
        withCategory: YOUR_CATEGORY_NAME,
        action: YOUR_ACTION_NAME",
        label: YOUR_LABEL_NAME,
        value: nil).build()
    tracker?.send(eventTracker as! [AnyHashable: Any])

Upvotes: 0

Sarat Patel
Sarat Patel

Reputation: 856

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

Upvotes: 1

Anamika
Anamika

Reputation: 163

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.

Upvotes: 9

Related Questions