Rie*_* C. 6 google-analytics-api ipad ios
我想使用谷歌分析来跟踪某些用户的浏览量和会话.为此,我(想)使用最新(v1.1)GANTracker版本支持的自定义变量.
在我的appHeader中我有这个代码:
[[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);
}
Run Code Online (Sandbox Code Playgroud)
当我启动我的应用程序时,我得到这些错误:
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.)"
Run Code Online (Sandbox Code Playgroud)
在打开我要跟踪的页面的函数中我把它放入:
NSError * error;
if(![[GANTracker sharedTracker] trackPageview:@"/pagename"]
withError:&error]){
NSLog(@"%@", error);
}
Run Code Online (Sandbox Code Playgroud)
这不会返回任何错误
如果我省略了setCustomVariableAtIndex函数,则会在分析中记录页面视图,但是使用自定义变量我什么也得不到.
有没有人知道如何解决这个问题?
小智 6
我遇到了同样的问题,并在Google的示例代码中偶然发现了答案.
如果将索引设置为零,则自定义变量会引发错误.你的第一个变量需要使用索引1.这会将上面的代码片段改为这样......
[[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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3400 次 |
| 最近记录: |