2011-03-11 18 views
6

Tôi muốn sử dụng phân tích google để theo dõi số lần xem trang và số phiên của một số người dùng nhất định. Để làm điều này tôi (muốn) sử dụng một biến tùy chỉnh được hỗ trợ bởi phiên bản GANTracker mới nhất (v1.1).Biến tùy chỉnh GANTracker cho SDK SDK cung cấp lỗi 195946409

trong appHeader của tôi, tôi có mã này:

[[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); 
} 

khi tôi bắt đầu ứng dụng của tôi tôi nhận được các lỗi này:

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.)" 

trong hàm mở ra một trang Tôi muốn theo dõi tôi đặt này :

NSError * error; 
if(![[GANTracker sharedTracker] trackPageview:@"/pagename"] 
            withError:&error]){ 
     NSLog(@"%@", error); 
} 

trả về này không có lỗi

nếu tôi bỏ qua hàm setCustomVariableAtIndex, lần xem trang được ghi lại trong phân tích nhưng với các vars tùy chỉnh, tôi không nhận được gì.

Có ai có ý tưởng về cách tôi có thể giải quyết vấn đề này không?

+0

trong trường hợp một số googles này, tôi đã giải quyết nó (tôi nghĩ) bằng cách đặt chỉ mục ở 1 và 2 thay cho 0 và 1 – Weptunus

Trả lời

6

Tôi gặp vấn đề tương tự và tình cờ gặp câu trả lời trong Google's sample code.

Biến tùy chỉnh sẽ phát ra lỗi nếu bạn đặt chỉ mục bằng 0. Biến đầu tiên của bạn cần phải sử dụng chỉ mục 1. Điều này sẽ thay đổi đoạn mã trên để trông giống như thế này ...

[[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); 
} 
+0

Tôi đã đạt được kết quả tương tự (hoặc rất giống) bằng cách vô tình truyền giá trị nil. –

Các vấn đề liên quan