Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

stera8

macrumors member
Original poster
Aug 21, 2014
59
2
Hello. I have google analytics where an alert shows every time the user opens the app. I would like it to be where the user only sees this alert the first time they open it if they decide to opt in.

If they decide not to opt in, I would like the alert to show every 7 days and allow them to change this in the settings app if they decide to opt in.

Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary     *)launchOptions
{
 ...



UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Google Analytics" message:@"With your permission usage information will be collected to improve the application." delegate:self cancelButtonTitle:@"Opt Out" otherButtonTitles:@"Opt In", nil];
[av show];

return YES;
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
switch (buttonIndex) {
    case 0:
        [[GAI sharedInstance] setOptOut:YES];
        break;
    case 1:
        [[GAI sharedInstance] setOptOut:NO];
        break;

    default:
        break;
}
}
 
I'm sure your users will hate this.

Can you not do it another way?

----------

...but to answer your question. I would store the day the user last said no, probably as a NSDate in an NSUserDefault.

Then on launch calculate the number of days since that date or maybe just if ([lastDate timeIntervalSinceNow] < -6*60*60). If sufficient time has passed show the alert view again.
 
Yes I agree. So until another update I ask the person on first launch and not again. I have to think about it.

What does everyone else do to show users about collecting analytics?
 
Maybe try with scheduledLocalNotifications. It will fire alert on date (or dates) that you specify.

To store option that user selected i would also use NSUserDefault. Store it as key-value pair and check it every time app is loaded.

Code:
BOOL userOption; // user selected opt to alerts.

NSUserDefault *showAVAlert = [NSUserDefault standardUserDefaults];
[showAVAlert setBool:userOption forKey:@"showAlert];
 
Last edited:
Thanks Boris.

All my analytics are anonymous as most apps and I just do not mention it, very few apps do.
 
Then on launch calculate the number of days since that date or maybe just if ([lastDate timeIntervalSinceNow] < -6*60*60). If sufficient time has passed show the alert view again.

This method will not scale across calendars, timezones, or daylight savings. I suggest you use NSCalendar and NSDateComponents.

There's a lot of examples online (on my phone for the moment, so can't type or find one), but I HIGHLY suggest that route.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.