2

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.

3 Answers 3

9

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.

3
  • +1 for the reminder to choose the correct date! I always seem to forget this…
    – enjayem
    Commented Mar 12, 2013 at 19:56
  • 1
    How long does it take for the event to show up on the web site? Commented Mar 23, 2013 at 1:40
  • @ FreeAsInBeer it ll take few hours or a day
    – Anamika
    Commented Mar 25, 2013 at 8:42
1

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

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.