2014-07-15 45 views
0

我将在我的iOS应用程序中使用Google Analytics,并且该应用程序没有任何登录/注册机制,这意味着我没有“应用程序生成的用户ID”。为Google Analytics实施用户ID iOS

因此,当我实施新的Google Analytics(通用分析)时,我想利用“用户跟踪”功能,该功能允许我们跨设备跟踪同一用户。

是否可以从iOS中的SDK获取Apple ID并将其设置为Google Analytics的用户ID?或者还有其他方式可以在Google Analytics中设置用户ID,并且仍然可以在不登录/注册的情况下跨设备跟踪用户。

在此先感谢。

+0

苹果不允许您直接抢苹果ID,但是这可能会有所帮助:http://stackoverflow.com/questions/14023954/in-app-purchase-ios-access-appleid – brandonscript

回答

1

没有直接的方法来跨多个设备跟踪用户。不过,您应该能够使用iCloud完成此操作,方法是创建一个唯一标识并将其存储在各个设备上。像这样的东西应该这样做。

+ (NSString *) getOrCreateIdentifier 
{ 
    static NSString *userIdentifier; 
    static NSString * const kUserIdentifierKey = @"kUserIdentifierKey"; 
    if(! userIdentifier.length) 
    { 
     NSUbiquitousKeyValueStore *cloudStore = [NSUbiquitousKeyValueStore defaultStore]; 
     userIdentifier = [cloudStore stringForKey:kUserIdentifierKey]; 
     if(! userIdentifier.length) 
     { 
      userIdentifier = [[NSUUID UUID] UUIDString]; 
      [cloudStore setString:userIdentifier forKey:kUserIdentifierKey]; 
     } 
    } 
    return userIdentifier; 
} 
+0

谢谢。我认为这可以工作。 –

相关问题