Reputation: 644
I'm going to use Google Analytics in my iOS application, and the app doesn't have any login/signup mechanism, which means I don't have an "application generated userid".
So when I implement the new Google Analytics (Universal Analytics), I want to take advantage of the "User tracking" feature which allows us to track the same user across devices.
Is it possible to get the Apple Id from the SDK in iOS and set that as the User ID for Google Analytics? Or is there any other way that I can set user id in Google Analytics and still be able to track users across devices without having a log-in/signup.
Thanks in advance.
Upvotes: 0
Views: 580
Reputation: 23634
There is no direct way to track a user across multiple devices. You should be able to accomplish this using iCloud though, by creating a unique identifier and storing it across devices. Something like this should do it.
+ (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;
}
Upvotes: 1