Skip to content

Instantly share code, notes, and snippets.

@davehenke
Last active September 26, 2016 15:07
Show Gist options
  • Save davehenke/fc60fe5a6d1ce1e73291e5e381035101 to your computer and use it in GitHub Desktop.
Save davehenke/fc60fe5a6d1ce1e73291e5e381035101 to your computer and use it in GitHub Desktop.
Nielsen Opt-In/Out Using Anvato SDK

#Nielsen Opt-In/Out Using Anvato SDK

##Prerequisites

  • Linked Nielsen Framework NielsenAppApi.framework. This can be obtained from Anvato's reference app under ANVSDK/dependency/NielsenAppApi.framework
  • String Values for: Nielsen App ID, Nielsen App Name, Nielsen SF Code.

##Setup During configuration of anvato's SDK, include the following code. Please note that the values assigned are examples taken from the news app. You should have your own nielsen app values.

	[ANVConfig sharedInstance].nielsenTVR.appID = nielsenID;
    [ANVConfig sharedInstance].nielsenTVR.appName = [[CMGConfigStore sharedInstance] nielsenAppName];
    
    // Eg, 5.2.0. This is your CFBundleVersion
    [ANVConfig sharedInstance].nielsenTVR.appVersion = [[CMGConfigStore sharedInstance] appVersionString]; 
    
    [ANVConfig sharedInstance].nielsenTVR.sfCode = [[CMGConfigStore sharedInstance] nielsenSFCode];
    [ANVConfig sharedInstance].nielsenTVR.isActive = YES;
	[ANVConfig sharedInstance].nielsenTVR.trackPlayhead = YES;

The ANVConfig sharedInstance].nielsenTVR object contains a property nielsenOptOutUrl. Create a link in your app titled "About Nielsen Measurement and Your Choices". When tapped, that link should pop out to a modal webview using the value in nielsenOptOutUrl as the URL. Please note that this webview should not leave the app. Do not use [[UIApplication sharedApplication] openURL:]

Your modal webview should be configured to receive link callbacks. In a UIWebView, this is captured in the UIWebViewDelegate method

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;

When a user selects the opt in or opt out link in the presented website, a URL request will fire once they have tapped the OK button in the "popup" on the page. This URL request will have a prefix of the form nielsen://.

When intercepting requests, check for the prefix nielsen. If nielsen is present, then the entire request URL must be sent back to Anvato's nielsenTVR object, and the webview can be dismissed.

Here is example code from the news app. Please note that the news app uses a modal web view library, so it does not use the traditional UIWebView callback, but the principles are the same.

((CMGModalWebViewController *)viewController).shouldStartLoadRequestHandler = ^BOOL(NSURLRequest *request, UIWebViewNavigationType navigationType){
	            NSString *requestURLString = [NSString stringWithFormat:@"%@", request.URL];
    if ([requestURLString hasPrefix:CMGDebugSettingsViewControllerNielsenCommandPrefix]) {
        [[[[CMGAnvatoManager sharedInstance] anvatoSDK] nielsenTVR] setNielsenOptOut:requestURLString];
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    return YES;
};

##Known Issues

  • If the nielsen framework is not linked, the value returned by anvato for nielsenOptOutUrl will be nil and unusable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment