Template

iOS Privacy and Opt-Out: Difference between revisions

From Engineering Client Portal

(https://www.nielsen.com/digitalprivacy)
Line 3: Line 3:
# '''[[#OS-level_Opt-out|OS-level Opt-out]]''' - managed by ''Limit Ad Tracking'' setting on device ('''preferred approach''').
# '''[[#OS-level_Opt-out|OS-level Opt-out]]''' - managed by ''Limit Ad Tracking'' setting on device ('''preferred approach''').
# '''[[#Legacy_Opt-out|Legacy Opt-out]]''' - Direct call to SDK; used only for older versions of Nielsen iOS SDK (< 5.1.1.18)
# '''[[#Legacy_Opt-out|Legacy Opt-out]]''' - Direct call to SDK; used only for older versions of Nielsen iOS SDK (< 5.1.1.18)
# '''[[#App_Level_Opt_Out|App Level Opt-Out]]''' - Where [https://developer.apple.com/documentation/adsupport Ad Framework] cannot be leveraged


=== OS-level Opt-out ===
=== OS-level Opt-out ===
Line 71: Line 70:
<blockquote>
<blockquote>
'''"Please note: This app features Nielsen’s proprietary measurement software which contributes to market research, like Nielsen’s TV Ratings. Please see https://www.nielsen.com/digitalprivacy for more information"'''</blockquote>
'''"Please note: This app features Nielsen’s proprietary measurement software which contributes to market research, like Nielsen’s TV Ratings. Please see https://www.nielsen.com/digitalprivacy for more information"'''</blockquote>
==== Webview Example  ====
The below code is an example of displaying the Nielsen Privacy page to the user.
{{ExampleCode|
|Objective C = <syntaxhighlight lang="objective-c">
- (void)viewDidLoad {
    [super viewDidLoad];
   
    //Setting background image
    UIImage *backgroundImage = [UIImage imageNamed:@"new_ios_bg.png"];
    UIImageView *backgroundImageView=[[UIImageView alloc]initWithFrame:self.view.frame];
    backgroundImageView.image=backgroundImage;
    [self.view insertSubview:backgroundImageView atIndex:0];
    self.nielsenApi = [NielsenInit createNielsenAppApiWithDelegate:nil];
    //Initialising the webview
    WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
    _wkwebView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:theConfiguration];
    _wkwebView.navigationDelegate = self;
    //Getting the optPut URL from SDK
    NSURL *nsurl=[NSURL URLWithString:[self.nielsenApi optOutURL]];
    //Setting url request in webview
    NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
    //Setting url request in webview
    [_wkwebView loadRequest:nsrequest];
      //Adding webview to the controller view
    [self.view addSubview:_wkwebView]; 
}
</syntaxhighlight>
|Swift = <syntaxhighlight lang="swift">
import UIKit
import WebKit
import NielsenAppApi
class OptOutVC: UIViewController, NielsenAppApiDelegate, WKNavigationDelegate {
   
    var webView: WKWebView!
    var nielsenApi: NielsenAppApi!
   
    override func loadView() {
        webView = WKWebView()
        webView.navigationDelegate = self
        view = webView
    }
   
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor(patternImage: UIImage(named: "new_ios_bg.png")!)
        self.nielsenApi = NielsenInit.createNielsenApi(delegate: self)
       
        if let appApi = self.nielsenApi {
            //Getting the optPut URL from SDK
            if let url = URL(string: appApi.optOutURL) {
                webView.load(URLRequest(url: url))
                webView.allowsBackForwardNavigationGestures = true
            }
        }
    }
   
}
</syntaxhighlight>
}}
<br>
=== App Level Opt Out ===
This is only used if the Ad Framework is not available.  The Opt-Out occurs by opening a Nielsen-defined web page and passing the user choice from the 'WebView'. In order to do this, the application needs to:
* Implement the UIWebView delegate method to open the Nielsen Privacy web page
* Capture user's selection
* Pass the selection back to the SDK via the <code>userOptOut</code>.
==== Capture and forward user selection ====
{{ExampleCode|
|Objective C = <syntaxhighlight lang="objective-c">
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSString *command = [NSString stringWithFormat:@"%@",request.URL];
    if ([command isEqualToString:kNielsenWebClose]) {
        // Close the WebView
        [self performSelector:@selector(closeOptOutView) withObject:nil afterDelay:0];
        return NO;
    }
    // Retrieve next URL if it’s not opt-in/out selection
    return (![nAppApiObject userOptOut:command]);
}</syntaxhighlight>
*The app gets the user selection string via webviews shouldStartLoadWithRequest and invokes <code>userOptOut</code> with user selection. The delegate method handles the 'WebView' URL requests, interprets the commands, and calls the SDK accordingly.
**<code>[nAppApiObject userOptOut:command]</code> passes the user's selection on Nielsen Privacy page to the SDK to allow the SDK to perform the required functions.
<blockquote>'''Note:''' When 'WebView' is closed, pass the status returned from 'WebView' to the SDK within the app. The App SDK manages the user's choice (Opt-Out / Opt-In), the app does not need to manage this status.</blockquote>
|Swift = <syntaxhighlight lang="swift">
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
        let command = request.url?.absoluteString
        if  command ==  "kNielsenWebClose"{
            self.perform(#selector(closeOptOutView), with: nil, afterDelay: 0)
            return false
        }   
        return NielsenAppApi.optOutURL
    }
</syntaxhighlight>
*The app gets the user selection string via webviews shouldStartLoadWithRequest and invokes <code>userOptOut</code> with user selection. The delegate method handles the 'WebView' URL requests, interprets the commands, and calls the SDK accordingly.
**<code>[nAppApiObject userOptOut:command]</code> passes the user's selection on Nielsen Privacy page to the SDK to allow the SDK to perform the required functions.
<blockquote>'''Note:''' When 'WebView' is closed, pass the status returned from 'WebView' to the SDK within the app. The App SDK manages the user's choice (Opt-Out / Opt-In), the app does not need to manage this status.</blockquote>
}}

Revision as of 20:45, 4 December 2019

Privacy and Opt-Out

There are three primary methods for implementing user Opt-out preferences:

  1. OS-level Opt-out - managed by Limit Ad Tracking setting on device (preferred approach).
  2. Legacy Opt-out - Direct call to SDK; used only for older versions of Nielsen iOS SDK (< 5.1.1.18)

OS-level Opt-out

OS-level Opt-out method available on Nielsen iOS SDK Versions 5.1.1.18 and above.

The Nielsen SDK automatically leverages the iOS's Limit Ad Tracking setting. The user is opted out of demographic measurement if the OS-level "Limit Ad Tracking" setting is enabled. As a publisher, you cannot override this setting.

Legacy Opt-out

The Legacy opt-out method is only necessary for Nielsen iOS SDK versions less than 5.1.1.18.

Nielsen iOS SDK 5.1.1.17 and above will check for OS-level opt-out first, if available. The user will be opted out if indicated at the OS-level OR the App-level.

The legacy opt-out method works as follows:

  • Get the legacy Nielsen opt-out URL via optOutURL
  • Display a WebView element whose loadUrl is set to the value obtained from optOutURL
  • Detect if the WebView URL changes to a special URL that indicates Opt-in, or Opt-out and close the WebView
    • Opt-out if the WebView URL = nielsenappsdk://1
    • Opt-in if the WebView URL = nielsenappsdk://0
  • Pass the detected URL to the userOptOut function
    • Example:
      NielsenAppApi?.userOptOut("nielsenappsdk://1"); // User opt-out
      

Legacy Opt-out example code

Swift

var webView: WKWebView!
var NIELSEN_URL_OPT_OUT : String = "nielsenappsdk://1"
var NIELSEN_URL_OPT_IN : String = "nielsenappsdk://0"

func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {

       let urlStr = navigationAction.request.url?.absoluteString

        if(urlStr == NIELSEN_URL_OPT_OUT || urlStr == NIELSEN_URL_OPT_IN){
            let appApi = self.nielsenApi
            appApi?.userOptOut(urlStr)
            decisionHandler(.allow)

        }else{
           decisionHandler(.cancel)
        }
    }

Objective C

- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {

    NSURLRequest *request = [navigationAction request];
    NSString *url = [[request URL]absoluteString];
    
    if([url isEqualToString:self.NIELSEN_URL_OPT_OUT] || [url isEqualToString:self.NIELSEN_URL_OPT_IN]){
        [self.nielsenApi userOptOut:url];
        decisionHandler(WKNavigationActionPolicyAllow);
    }else{
        decisionHandler(WKNavigationActionPolicyCancel);
    }        
}


Retrieve current Opt-Out preference

Whether the user is opted out via OS-level Opt-out or via App-level Opt-out, the current Opt-Out status as detected by the SDK is available via the optOutStatus property in the Nielsen SDK API

Required Privacy Links

Users must either have access to the "About Nielsen Measurement" page, or have similar text available within the native app. Include "About Nielsen Measurement" and "Your Choices" link in the Privacy Policy / EULA or as a button near the link to the app's Privacy Policy.

In addition, the following text must be included in your app store description.

"Please note: This app features Nielsen’s proprietary measurement software which contributes to market research, like Nielsen’s TV Ratings. Please see https://www.nielsen.com/digitalprivacy for more information"