I would like to use google analytics to track pageviews and sessions by certain users. To do this I (would like to) use a custom variables which are supported by the newest (v1.1) GANTracker version.
in my appHeader I have this code:
[[GANTracker sharedTracker] startTrackerWithAccountID:@"UA-xxxxxxxx-x"
dispatchPeriod:10
delegate:nil];
NSError *error1;
if(![[GANTracker sharedTracker] setCustomVariableAtIndex:0
name:@"userSession"
value:@"username"
scope:kGANSessionScope
withError:&error1]){
NSLog(@"error1 %@", error1);
}
NSError *error2;
if(![[GANTracker sharedTracker] setCustomVariableAtIndex:1
name:@"userSession"
value:@"username"
scope:kGANPageScope
withError:&error2]){
NSLog(@"error2 %@", error2);
}
when I start my app I get these errors:
error1: Error Domain=com.google.googleanalytics.GANTrackerError Code=195946409 "The operation couldn’t be completed. (com.google.googleanalytics.GANTrackerError error 195946409.)"
error2: Error Domain=com.google.googleanalytics.GANTrackerError Code=195946409 "The operation couldn’t be completed. (com.google.googleanalytics.GANTrackerError error 195946409.)"
in the function that opens a page I want to track I put this:
NSError * error;
if(![[GANTracker sharedTracker] trackPageview:@"/pagename"]
withError:&error]){
NSLog(@"%@", error);
}
this returns no errors
if I leave out the setCustomVariableAtIndex function the pageview is logged in analytics but with the custom vars I get nothing.
Does anyone have an idea on how I can solve this problem?
I hit the same problem and stumbled upon the answer in Google's sample code.
The custom variables throw an error if you set the index to zero. Your first variable needs to use index 1. This would change the above code snippet to look like this...
[[GANTracker sharedTracker] startTrackerWithAccountID:@"UA-xxxxxxxx-x"
dispatchPeriod:10
delegate:nil];
NSError *error1;
if(![[GANTracker sharedTracker] setCustomVariableAtIndex:1
name:@"userSession"
value:@"username"
scope:kGANSessionScope
withError:&error1]){
NSLog(@"error1 %@", error1);
}
NSError *error2;
if(![[GANTracker sharedTracker] setCustomVariableAtIndex:2
name:@"userSession"
value:@"username"
scope:kGANPageScope
withError:&error2]){
NSLog(@"error2 %@", error2);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With