9

I added Google Analytics SDK to my project, following the provided instructions on the guide by Google. However, when I try to track some events, this is the debug output:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    […]

    // Google Analytics
    [GAI sharedInstance].trackUncaughtExceptions = YES;
    [GAI sharedInstance].dispatchInterval = 20;
    [[[GAI sharedInstance] logger] setLogLevel:(PADEV ? kGAILogLevelVerbose : kGAILogLevelError)];
    [[GAI sharedInstance] trackerWithTrackingId:@"UA-XXXXXXXX-Y"]; // This is obviously replaced with my tracking ID

    return YES;
}

and

id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"article"
                                                      action:@"read"
                                                       label:@""
                                                       value:self.post[@"id"]] build]];

Log:

2014-11-12 01:02:25.144 PonzApp[5236:112706] INFO: GoogleAnalytics 3.10 -[GAIBatchingDispatcher didSendHits:response:data:error:] (GAIBatchingDispatcher.m:208): Hit(s) dispatched: HTTP status -1
2014-11-12 01:02:25.146 PonzApp[5236:112781] INFO: GoogleAnalytics 3.10 -[GAIBatchingDispatcher deleteHits:] (GAIBatchingDispatcher.m:509): hit(s) Successfully deleted
2014-11-12 01:02:25.147 PonzApp[5236:112781] INFO: GoogleAnalytics 3.10 -[GAIBatchingDispatcher didSendHits:] (GAIBatchingDispatcher.m:219): 1 hit(s) sent

It says that the hits are sent but the HTTP status is weirdly -1 and if I check on the dashboard, section “real-time”, nothing appears.

What could be wrong?

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
entropid
  • 6,130
  • 5
  • 32
  • 45

3 Answers3

9

From Google Analytics tracking setup

Once you've correctly installed the tracking code snippet, you should allow up to 24 hours for data to appear in your account. If it has been more than 24 hours and you're still not seeing any data, take a look at the list of possible reasons below:

Once the system has detected your tracker you will start seeing data in the real-time reports. Some of the data may also appear in the standard reports but it is not reliable as it takes 24 hours for data to finish processing.

All and all your code looks fine you just need to wait. The above is the same even though it is a application tracking. I suspect it takes time for Google to set up the new account on there side.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • 2
    The example that they provide together with the SDK works instantly! I never understood this `24h` for some things; it should (and it does for their example) work instantly. – Iulian Onofrei Jan 20 '15 at 14:48
  • It can take time for them to setup a new account. This isn't always the case I have seen it take from a few hours to a day. – Linda Lawton - DaImTo Jan 20 '15 at 14:53
5

For me the problem was that I was testing it in simulator... :|

Inam Abbas
  • 1,480
  • 14
  • 28
  • 1
    Same here ;-) Simulator doesn't do things. But even in real device, you would see "hit(s) Successfully deleted" log in console. I think this is about "deleting in app memory". – MyounghoonKim Jun 08 '15 at 08:42
0

If you are using simulator to test it, make sure to press command + shift + H on the simulator to back to home since the data will be sent when it's on background.

Kevin Lee
  • 195
  • 2
  • 9