我在iOS上使用Google Analytics的自定义维度存在一些问题。 我已经在GA的Web界面中设置了自定义维度。但是,如果我在GA跟踪器初始化时在AppDelegate中发送自定义维度,它就不会像预期的那样显示出来。
id tracker = [[GAI sharedInstance] defaultTracker];
[tracker set:[GAIFields customDimensionForIndex:1] value:@"testValue"];
[tracker send:[[[GAIDictionaryBuilder createAppView] set:@"testValue" forKey:[GAIFields customDimensionForIndex:1]] build]];
有人遇到过类似的问题吗?
答案 0 :(得分:1)
> I hope it's help you.
// Call this on didFinishLaunchingWithOptions
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self startGoogleAnalyticsTracking];
[self performSelector:@selector(sendGoogleAnalyticsStartup) withObject:nil afterDelay:3];
// --------- Enter your code here
----------//
return YES;
}
- (void)startGoogleAnalyticsTracking {
@try {
// self.googleAnalyticsTracker = [[GAI sharedInstance] trackerWithTrackingId:”PASTE YOUR TRACKING ID HERE”];
// Optional: automatically send uncaught exceptions to Google Analytics.
[GAI sharedInstance].trackUncaughtExceptions = YES;
// Optional: set Google Analytics dispatch interval to e.g. 20 seconds.
[GAI sharedInstance].dispatchInterval = 10;
// Optional: set debug to YES for extra debugging information.
[GAI sharedInstance].debug = YES;
// **** REPLACE Tracking Id with your own GA Tracking Id **** //
// Create tracker instance.Tracking Id
id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"Tracking Id"];
[tracker sendView:@"Application Loaded"];
}@catch (NSException *exception) {
NSLog(@"exception:%@",exception);
}
}
- (void)sendGoogleAnalyticsStartup {
@try {
[self.googleAnalyticsTracker sendEventWithCategory:@"Application Events" withAction:nil withLabel:@"Tracking Starts" withValue:nil];
}@catch (NSException *exception) {
NSLog(@"exception=%@",exception);
}
}
- (void)stopGoogleAnalyticsTracking {
@try {
[self.googleAnalyticsTracker sendEventWithCategory:@"Application Events" withAction:nil withLabel:@"Tracking Suspended /Stopped" withValue:nil];
}@catch (NSException *exception) {
NSLog(@"exception=%@",exception);
}
}
答案 1 :(得分:0)
我发现“问题”并不是真的。我确实正确地设置了一切。但Google Analytics需要一些时间来评估数据。它需要很长时间(48小时+)才能显示在Web界面中。因此,对于遇到类似问题的每个人:请耐心等待!