2012-07-18 85 views
0
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{  

    [[GANTracker sharedTracker] startTrackerWithAccountID:kAnalyticsAccountId 
              dispatchPeriod:kGANDispatchPeriodSec 
               delegate:nil]; 
    NSError *error; 
    NSCalendar * calendar = [NSCalendar currentCalendar]; 
    NSDateComponents * components = [calendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSSecondCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit 
               fromDate:[NSDate date]]; 
    NSString * stringTime = [NSString stringWithFormat:@"%d:%d",components.hour, components.minute]; 

    if (![[GANTracker sharedTracker] setCustomVariableAtIndex:1 
                 name:@"TIME" 
                 value:stringTime 
                withError:&error]) { 
     NSLog(@"error in setCustomVariableAtIndex"); 
    } 

    [self.window addSubview:navigationController.view]; 
    [self.window makeKeyAndVisible]; 
    return YES; 

} 

由于这些值是URL编码的,因此GA站点中16:30成为16%3A30。我希望它能够显示,因为它是.ie,16:30。我该怎么做呢? 另外我从其他控制器设置的自定义变量没有得到更新。 例如:Google Analytics GANTracker - 如何在IOS应用程序中使用setCustomVariable?

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    UIDevice *device = [UIDevice currentDevice]; 

    NSError *errorMsg; 

    if (![[GANTracker sharedTracker] setCustomVariableAtIndex:2 
                 name:@"DEVICE" 
                 value:device.model 
                withError:&errorMsg]) { 
     NSLog(@"error in setCustomVariableAtIndex2"); 
    } 
} 

这没有更新。我知道需要一天时间才能在网站上反映数据。但只有自定义变量(键1)才有数据。其他键显示“这个视图没有数据”,尽管我使用索引2(参考上面的代码)。 有人可以帮助我吗?

回答

0

由于这些值是由URL编码的,所以在GA网站中16:30成为16%3A30。我希望它能够显示,因为它是.ie,16:30。我该怎么做呢?

NSString *testme = @"16%3A30"; 
testme = [testme stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
NSLog(@"testme = %@", testme); //16:30 
+0

感谢大卫,但就在我身边我得到的字符串作为唯一的16:30。当我使用GANTracker的setCustomVariableAtIndex方法将它传递给谷歌服务器时,它在站点上更新为16%3A30。 – MarenWolf 2012-07-18 07:52:33

相关问题