George Asda
George Asda

Reputation: 2129

Google analytics opt out "how to"

I'm looking to implement google analytics in my app and would like to notify the users of that. I've been going through all the questions here but can't still find the proper way to do it.

I m using the SDK 3 from google developer website.

There it states:

 // Get the app-level opt out preference.
if ([GAI sharedInstance].optOut) {
  ... // Alert the user they have opted out.
}
To set the app-level opt out, use:

// Set the app-level opt out preference.
[[GAI sharedInstance] setOptOut:YES];

but nothing more on how to do this...

Any ideas please?

Upvotes: 2

Views: 2930

Answers (1)

thorb65
thorb65

Reputation: 2716

Use an UIAlertView and UIAlertViewDelegate to decide, which buttons the user tapped (opt-in or out). store that in NSUserDefaults.

when checking the result of alertview do:

NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSString *allowGoogle;
if (//User tapped opt in) {
    allowGoogle = @"yes";
} else {
    allowGoogle = @"no";
}
[userDefaults setValue:allowGoogle forKey:@"AllowGoogleAnalytics"];
[userDefaults synchronize];

place the next code around the UIAlertView open:

NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSString *allowGoogle = [userDefaults valueForKey:@"AllowGoogleAnalytics"];
if (!allowGoogle) {
    // HERE OPEN ALERTVIEW because you have no value for that key in your
    // userdefaults
} else {
    if ([allowGoogle isEqualToString:@"yes"] {
        // Enable GoogleAnalytics
    } else {
        // Disable GoogleAnalytics
    }
}

Upvotes: 3

Related Questions