Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GANTracker for iPhone SDK custom variables gives error 195946409

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?

like image 730
Rien Avatar asked Mar 11 '11 16:03

Rien


1 Answers

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);
}
like image 174
akshaun Avatar answered Nov 30 '22 12:11

akshaun