Reputation: 261
I started using Goole Analytics v2.0beta3 for iOS native app. I start a session with the following code:
[GAI sharedInstance].trackUncaughtExceptions = YES;
[GAI sharedInstance].dispatchInterval = 20;
[GAI sharedInstance].debug = YES;
id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-XXXX-X"];
[GAI sharedInstance].defaultTracker = tracker;
[tracker setAnonymize:YES];
BOOL res = [tracker trackEventWithCategory:@"cat" withAction:@"act" withLabel:@"label" withValue:[NSNumber numberWithInt:1]];
[[GAI sharedInstance] dispatch];
However, I don't know how to end the session and the session duration I get is always 0.0
Has anyone encountered this issue ?
Thanks
Upvotes: 1
Views: 621
Reputation: 23976
As per Google Analytics v3 the session behaviour changed. If you're experiencing these problems with the latest version, check out my fix here:
https://stackoverflow.com/a/26882024/1485701
Upvotes: 0
Reputation: 1423
I would check and see if your trackers are set properly. My setup code is as follows
[GAI sharedInstance].debug = YES;
[GAI sharedInstance].dispatchInterval = 20;
[GAI sharedInstance].trackUncaughtExceptions = YES;
self.tracker = [[GAI sharedInstance] trackerWithTrackingId:kTrackingId];
NSLog(@"what is tracker %@ / default tracker %@?", self.tracker, [GAI sharedInstance].defaultTracker);
Where self.tracker is @property (strong, nonatomic) id <GAITracker> tracker;
I am getting correct session tracking information. Maybe try pulling out code until you find what is causing the issue?
Additionally a workaround could be something like this.
- (void)applicationDidBecomeActive:(UIApplication *)application
{
appBecameActive = [NSDate date];
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
NSDate *appClosing = [NSDate date];
NSTimeInterval sessionLength = [appClosing timeIntervalSinceDate:appBecameActive];
[[GAI sharedInstance].defaultTracker trackTimingWithCategory:@"sessionLength"
withValue:sessionLength
withName:@"appWentToBackground"
withLabel:nil];
}
Upvotes: 2