Template

Difference between revisions of "iOS Privacy and Opt-Out"

From Engineering Client Portal

(Legacy Opt-out example code)
(Webview Element)
(14 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
== Privacy and Opt-Out ==
 
== Privacy and Opt-Out ==
There are two primary methods for implementing user Opt-out preferences:
 
# '''[[#OS-level_Opt-out|OS-level Opt-out]]''' - managed by ''AppTracking'' or ''Limit Ad Tracking'' setting on device ('''preferred approach''').
 
# '''[[#User Choice|User Choice]]''' - Direct call to SDK. Can be used without the Ad Framework
 
  
=== Special Note Regarding Apps in the '''Kids Category''' ===
+
There are currently 3 flavors of the Nielsen SDK. Please check the "Implementation" section for a comparison of the three flavors. Implementing opt-out for the three flavors are different:
If you are building an app that will be listed in the Kids Category:
+
# '''[[#Global_iOS_SDK_Opt-out|Global iOS SDK Opt-out]]''' - managed by ''AppTracking'' or ''Limit Ad Tracking'' setting on device.
# Ensure that you are using the [https://nielsendownloads-green.digitalengsdk.com/digital/Nielsen-iOS-App-SDK-GlobalNoId_latest.zip NoID version] of the Nielsen SDK Framework.
+
# '''[[#Global_iOS_SDK_No_Ad_Framework_Opt-out|Global iOS SDK No Ad Framework Opt-out]]''' - Direct call to SDK. Can be used without the Ad Framework.
# Immediately following the initialization of the Nielsen SDK ensure you call the userOptOut API with Opt out selection:
+
# '''[[#Global_iOS_SDK_No_ID_Opt-out|Global iOS SDK No ID Opt-out]]''' - Direct call to SDK. Should be used for Kids Category.
<syntaxhighlight lang=swift>NielsenAppApi?.userOptOut("nielsenappsdk://1"); // User opt-out</syntaxhighlight>
+
__NOTOC__
 
+
=== Global iOS SDK Opt-out ===
=== OS-level Opt-out ===
 
 
''OS-level Opt-out'' method available on Nielsen iOS  
 
''OS-level Opt-out'' method available on Nielsen iOS  
  
Line 16: Line 12:
 
*  If the User's device is running < iOS 13.x, the Nielsen SDK will check the status of '''Limit Ad Tracking'''.
 
*  If the User's device is running < iOS 13.x, the Nielsen SDK will check the status of '''Limit Ad Tracking'''.
 
*  iOS14 modifies the way Apple manages the collection of a User's Opt-In status through '''AppTracking'''. Starting with Version 8.x+, the Nielsen App SDK will check the iOS version during initialization. If the device is running iOS12 or iOS13, the Limit Ad Tracking setting is requested. If iOS14.x +, then AppTracking is utilized.
 
*  iOS14 modifies the way Apple manages the collection of a User's Opt-In status through '''AppTracking'''. Starting with Version 8.x+, the Nielsen App SDK will check the iOS version during initialization. If the device is running iOS12 or iOS13, the Limit Ad Tracking setting is requested. If iOS14.x +, then AppTracking is utilized.
 +
==== Webview Element ====
 +
It is a requirement to display a WebView element whose loadUrl is set to the value obtained from optOutURL.
 +
If using the Global iOS SDK, this optOutURL informs the user how to deactivate/activate “App Tracking/Limit Ad Tracking”.
  
==== Webview Example  ====
+
In addition, the following text must be included in your app store description.
The below code is an example of displaying the Nielsen Privacy page to the user.
+
<blockquote>"Please note: This app features Nielsen’s proprietary measurement software which contributes to market research, like Nielsen’s TV Ratings. Please see https://nielsen.com/legal/privacy-principles/digital-measurement-privacy-statement/?lang=en-no for more information"</blockquote>
 +
 
 +
If you are implementing on AppleTV here are your Opt Out verbiage options : https://engineeringportal.nielsen.com/docs/DCR_Video_%26_Static_CTV_Device_SDK_Privacy
 +
 
 +
==== Sample Code for Global Build ====
 +
===== Swift =====
 
<syntaxhighlight lang="swift">
 
<syntaxhighlight lang="swift">
 
import UIKit
 
import UIKit
Line 25: Line 29:
  
 
class OptOutVC: UIViewController, NielsenAppApiDelegate, WKNavigationDelegate {
 
class OptOutVC: UIViewController, NielsenAppApiDelegate, WKNavigationDelegate {
 +
    var nielsenApi : NielsenAppApi!
 
     var webView: WKWebView!
 
     var webView: WKWebView!
    var nielsenApi: NielsenAppApi!
+
 
   
 
 
     override func loadView() {
 
     override func loadView() {
 
         webView = WKWebView()
 
         webView = WKWebView()
 
         webView.navigationDelegate = self
 
         webView.navigationDelegate = self
         view = webView }
+
         view = webView
   
+
    }
 +
 
 
     override func viewDidLoad() {
 
     override func viewDidLoad() {
 
         super.viewDidLoad()
 
         super.viewDidLoad()
        self.view.backgroundColor = UIColor(patternImage: UIImage(named: "new_ios_bg.png")!)
+
 
        self.nielsenApi = NielsenInit.createNielsenApi(delegate: self)  //create an instance
+
    if let appApi = self.nielsenApi {
       
 
        if let appApi = self.nielsenApi {
 
 
             //Getting the optPut URL from SDK
 
             //Getting the optPut URL from SDK
             if let url = URL(string: appApi.optOutURL) { //query the nielsensdk for the current privacy page
+
             if let url = URL(string: appApi.optOutURL) {
 
                 webView.load(URLRequest(url: url))
 
                 webView.load(URLRequest(url: url))
 
                 webView.allowsBackForwardNavigationGestures = true
 
                 webView.allowsBackForwardNavigationGestures = true
             }}}}
+
             }}}
 +
 
 +
        func closeOptOutView() {
 +
            self.dismiss(animated: true, completion: nil)
 +
        }}
 +
</syntaxhighlight>
 +
 
 +
===== Objective-C =====
 +
<syntaxhighlight lang="objective-c">
 +
 
 +
#import "OptOutVC.h"
 +
#import "NielsenInit.h"
 +
#import <NielsenAppApi/NielsenAppApi.h>
 +
 
 +
@interface OptOutVC ()
 +
 
 +
@property (weak, nonatomic) IBOutlet UIWebView *webView;
 +
@end
 +
 
 +
@implementation OptOutVC
 +
 
 +
- (void)viewDidLoad {
 +
    [super viewDidLoad];
 +
 
 +
- (void)viewDidLoad {
 +
    [super viewDidLoad];
 +
    //Getting the optPut URL from eventTracker
 +
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL
 +
URLWithString:self.nielsenApi.optOutURL]]];
 +
}}
 +
 
  
 
</syntaxhighlight>
 
</syntaxhighlight>
<br>
 
  
=== User Choice ===
+
=== Global iOS SDK No Ad Framework Opt-out ===
The ''User Choice'' method can be used without the Ad Framework, or in situations where the publisher does not wish to use the [https://developer.apple.com/documentation/apptrackingtransparency App Tracking Transparency Framework].
+
The ''User Choice'' method can be used without the Ad Framework, or in situations where the publisher does not wish to use the [https://developer.apple.com/documentation/apptrackingtransparency App Tracking Transparency Framework]. As this flavor of the Nielsen SDK does not use the Ad Framework, so it is necessary to display an Optout Page to the user and capture their selection.
 +
 
 +
Similar to the Global iOS SDK Flavor, it is a requirement to display a WebView element whose loadUrl is set to the
 +
value obtained from optOutURL. This is a special URL that indicates Opt-in, or Opt-out and close the WebView.  '''The steps are as follows:'''
  
==== The User Choice opt-out method works as follows: ====
 
 
* Get the Nielsen opt-out URL via [[optOutURL]]
 
* Get the Nielsen opt-out URL via [[optOutURL]]
 
* Display a WebView element whose loadUrl is set to the value obtained from [[optOutURL]]
 
* Display a WebView element whose loadUrl is set to the value obtained from [[optOutURL]]
Line 60: Line 94:
 
** Example: <syntaxhighlight lang=swift>NielsenAppApi?.userOptOut("nielsenappsdk://1"); // User opt-out</syntaxhighlight>
 
** Example: <syntaxhighlight lang=swift>NielsenAppApi?.userOptOut("nielsenappsdk://1"); // User opt-out</syntaxhighlight>
  
==== Opt-out example code ====
+
==== Sample code for No Ad Framework Build ====
 +
===== Swift =====
 +
<syntaxhighlight lang="swift">
 +
import UIKit
 +
import WebKit
 +
import NielsenAppApi
 +
 
 +
class OptOutVC: UIViewController, NielsenAppApiDelegate, WKNavigationDelegate {
 +
    var nielsenApi : NielsenAppApi!
 +
    var webView: WKWebView!
 +
 
 +
    override func loadView() {
 +
        webView = WKWebView()
 +
        webView.navigationDelegate = self
 +
        view = webView
 +
    }
 +
 
 +
    override func viewDidLoad() {
 +
        super.viewDidLoad()
 +
 
 +
        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
 +
            }}}
 +
 
 +
        func closeOptOutView() {
 +
            self.dismiss(animated: true, completion: nil)
 +
        }
 +
 
 +
        func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler:
 +
@escaping (WKNavigationActionPolicy) -> Void) {
 +
            print(navigationAction.request.url?.absoluteString as Any) //For debugging to check what is being passed from webpage.
 +
            if navigationAction.request.url?.absoluteString == "nielsen://close" {
 +
                closeOptOutView()
 +
                decisionHandler(.cancel)
 +
            } else {
 +
                if let url = navigationAction.request.url?.absoluteString, url.hasPrefix("nielsen") {
 +
                    nielsenApi?.userOptOut(url). //either nielsenappsdk://1 or nielsenappsdk://0
 +
                    decisionHandler(.cancel)
 +
                } else {
 +
                    if navigationAction.navigationType == .linkActivated {
 +
                        if let url = navigationAction.request.url?.absoluteString, url.hasSuffix("#") {
 +
                            decisionHandler(.allow)
 +
                        } else {
 +
                            decisionHandler(.cancel)
 +
                            webView.load(navigationAction.request)
 +
                        }
 +
                    } else {
 +
                        decisionHandler(.allow)
 +
                    }}}}
 +
 
 +
}
 +
 
 +
</syntaxhighlight>
 +
 
 
===== Objective-C =====
 
===== Objective-C =====
 
  <syntaxhighlight lang="objective-c">
 
  <syntaxhighlight lang="objective-c">
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)
 
navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
 
  
    NSURLRequest *request = [navigationAction request];
+
#import "OptOutVC.h"
    NSString *url = [[request URL]absoluteString];
+
#import "NielsenInit.h"
   
+
#import <NielsenAppApi/NielsenAppApi.h>
    if([url isEqualToString:self.NIELSEN_URL_OPT_OUT] || [url isEqualToString:self.NIELSEN_URL_OPT_IN]){
 
        [self.nielsenApi userOptOut:url];
 
        decisionHandler(WKNavigationActionPolicyAllow);
 
    }else{
 
        decisionHandler(WKNavigationActionPolicyCancel);
 
    }       
 
}
 
</syntaxhighlight>
 
===== Swift =====
 
<syntaxhighlight lang="swift">
 
  
var webView: WKWebView!
+
@interface OptOutVC ()
var NIELSEN_URL_OPT_OUT : String = "nielsenappsdk://1"
 
var NIELSEN_URL_OPT_IN : String = "nielsenappsdk://0"
 
  
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction,
+
@property (weak, nonatomic) IBOutlet UIWebView *webView;
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
+
@end
  
      let urlStr = navigationAction.request.url?.absoluteString
+
@implementation OptOutVC
  
         if(urlStr == NIELSEN_URL_OPT_OUT || urlStr == NIELSEN_URL_OPT_IN){
+
- (void)viewDidLoad {
             let appApi = self.nielsenApi
+
    [super viewDidLoad];
             appApi?.userOptOut(urlStr)
+
 
            decisionHandler(.allow)
+
- (void)viewDidLoad {
 +
    [super viewDidLoad];
 +
    //Getting the optPut URL from eventTracker
 +
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL
 +
URLWithString:self.nielsenApi.optOutURL]]];
 +
}
 +
   
 +
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction
 +
decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
 +
{
 +
    if ([navigationAction.request.URL.absoluteString isEqualToString:kNielsenWebClose])
 +
    {  [self performSelector:@selector(closeOptOutView) withObject:nil afterDelay:0];
 +
        decisionHandler(WKNavigationActionPolicyCancel);
 +
    } else {
 +
         if ([navigationAction.request.URL.absoluteString hasPrefix:@"nielsen"])
 +
        {[self.nielsenAppApi userOptOut:navigationAction.request.URL.absoluteString];
 +
            decisionHandler(WKNavigationActionPolicyCancel);
 +
        } else {
 +
             if (navigationAction.navigationType == WKNavigationTypeLinkActivated)
 +
             { if ([navigationAction.request.URL.absoluteString hasSuffix:@"#"])
 +
                      {decisionHandler(WKNavigationActionPolicyAllow);
 +
                } else {
 +
                    decisionHandler(WKNavigationActionPolicyCancel);
 +
                    [webView loadRequest:[NSURLRequest requestWithURL:navigationAction.request.URL]];
 +
                }} else {
 +
                decisionHandler(WKNavigationActionPolicyAllow);
 +
            }}}
 +
}
  
        }else{
 
          decisionHandler(.cancel)
 
        }
 
    }
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== Retrieve current Opt-Out preference ===
 
Whether the user is opted out via OS-level Opt-out or via User Choice 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 ===
+
=== Global iOS SDK No ID Opt-out ===
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.
+
If you are building an app that will be listed in the Kids Category:
 +
#  Ensure that you are using the [https://nielsendownloads-green.digitalengsdk.com/digital/Nielsen-iOS-App-SDK-GlobalNoId_latest.zip NoID version] of the Nielsen SDK Framework.
 +
#  Immediately following the initialization of the Nielsen SDK ensure you call the userOptOut API with Opt out selection:
 +
<syntaxhighlight lang=swift>NielsenAppApi?.userOptOut("nielsenappsdk://1"); // User opt-out</syntaxhighlight>
  
In addition, the following text must be included in your app store description.
+
== Retrieve current Opt-Out preference ==
<blockquote>
+
Whether the user is opted out via OS-level Opt-out or via User Choice Opt-out, the current Opt-Out status as detected by the SDK is available via the [[optOutStatus]] property in the Nielsen SDK API
'''"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/us/en/legal/privacy-statement/digital-measurement/ for more information"'''</blockquote>
+
<syntaxhighlight lang="objective-c">
 +
@property (readonly) BOOL optOutStatus
 +
</syntaxhighlight>

Revision as of 09:08, 4 August 2022

Privacy and Opt-Out

There are currently 3 flavors of the Nielsen SDK. Please check the "Implementation" section for a comparison of the three flavors. Implementing opt-out for the three flavors are different:

  1. Global iOS SDK Opt-out - managed by AppTracking or Limit Ad Tracking setting on device.
  2. Global iOS SDK No Ad Framework Opt-out - Direct call to SDK. Can be used without the Ad Framework.
  3. Global iOS SDK No ID Opt-out - Direct call to SDK. Should be used for Kids Category.

Global iOS SDK Opt-out

OS-level Opt-out method available on Nielsen iOS

The Nielsen SDK automatically leverages the iOS's Limit Ad Tracking or AppTracking setting.

  • If the User's device is running < iOS 13.x, the Nielsen SDK will check the status of Limit Ad Tracking.
  • iOS14 modifies the way Apple manages the collection of a User's Opt-In status through AppTracking. Starting with Version 8.x+, the Nielsen App SDK will check the iOS version during initialization. If the device is running iOS12 or iOS13, the Limit Ad Tracking setting is requested. If iOS14.x +, then AppTracking is utilized.

Webview Element

It is a requirement to display a WebView element whose loadUrl is set to the value obtained from optOutURL. If using the Global iOS SDK, this optOutURL informs the user how to deactivate/activate “App Tracking/Limit Ad Tracking”.

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://nielsen.com/legal/privacy-principles/digital-measurement-privacy-statement/?lang=en-no for more information"

If you are implementing on AppleTV here are your Opt Out verbiage options : https://engineeringportal.nielsen.com/docs/DCR_Video_%26_Static_CTV_Device_SDK_Privacy

Sample Code for Global Build

Swift
import UIKit
import WebKit
import NielsenAppApi

class OptOutVC: UIViewController, NielsenAppApiDelegate, WKNavigationDelegate {
    var nielsenApi : NielsenAppApi!
    var webView: WKWebView!
   
    override func loadView() {
        webView = WKWebView()
        webView.navigationDelegate = self
        view = webView
    }

    override func viewDidLoad() {
        super.viewDidLoad()

    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
            }}}

        func closeOptOutView() {
            self.dismiss(animated: true, completion: nil)
        }}
Objective-C
#import "OptOutVC.h"
#import "NielsenInit.h"
#import <NielsenAppApi/NielsenAppApi.h>

@interface OptOutVC ()

@property (weak, nonatomic) IBOutlet UIWebView *webView;
@end

@implementation OptOutVC

- (void)viewDidLoad {
    [super viewDidLoad];

- (void)viewDidLoad {
    [super viewDidLoad];
    //Getting the optPut URL from eventTracker
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL
 URLWithString:self.nielsenApi.optOutURL]]];
}}

Global iOS SDK No Ad Framework Opt-out

The User Choice method can be used without the Ad Framework, or in situations where the publisher does not wish to use the App Tracking Transparency Framework. As this flavor of the Nielsen SDK does not use the Ad Framework, so it is necessary to display an Optout Page to the user and capture their selection.

Similar to the Global iOS SDK Flavor, it is a requirement to display a WebView element whose loadUrl is set to the value obtained from optOutURL. This is a special URL that indicates Opt-in, or Opt-out and close the WebView. The steps are as follows:

  • Get the 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
      

Sample code for No Ad Framework Build

Swift
import UIKit
import WebKit
import NielsenAppApi

class OptOutVC: UIViewController, NielsenAppApiDelegate, WKNavigationDelegate {
    var nielsenApi : NielsenAppApi!
    var webView: WKWebView!
   
    override func loadView() {
        webView = WKWebView()
        webView.navigationDelegate = self
        view = webView
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        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
            }}}

        func closeOptOutView() {
            self.dismiss(animated: true, completion: nil)
        }

        func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: 
@escaping (WKNavigationActionPolicy) -> Void) {
            print(navigationAction.request.url?.absoluteString as Any) //For debugging to check what is being passed from webpage.
            if navigationAction.request.url?.absoluteString == "nielsen://close" {
                closeOptOutView()
                decisionHandler(.cancel)
            } else {
                if let url = navigationAction.request.url?.absoluteString, url.hasPrefix("nielsen") {
                    nielsenApi?.userOptOut(url). //either nielsenappsdk://1 or nielsenappsdk://0
                    decisionHandler(.cancel)
                } else {
                    if navigationAction.navigationType == .linkActivated {
                        if let url = navigationAction.request.url?.absoluteString, url.hasSuffix("#") {
                            decisionHandler(.allow)
                        } else {
                            decisionHandler(.cancel)
                            webView.load(navigationAction.request)
                        }
                    } else {
                        decisionHandler(.allow)
                    }}}}

}
Objective-C
#import "OptOutVC.h"
#import "NielsenInit.h"
#import <NielsenAppApi/NielsenAppApi.h>

@interface OptOutVC ()

@property (weak, nonatomic) IBOutlet UIWebView *webView;
@end

@implementation OptOutVC

- (void)viewDidLoad {
    [super viewDidLoad];

- (void)viewDidLoad {
    [super viewDidLoad];
    //Getting the optPut URL from eventTracker
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL
 URLWithString:self.nielsenApi.optOutURL]]];
}
     
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction
 decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
{
    if ([navigationAction.request.URL.absoluteString isEqualToString:kNielsenWebClose])
    {   [self performSelector:@selector(closeOptOutView) withObject:nil afterDelay:0];
        decisionHandler(WKNavigationActionPolicyCancel); 
     } else {
        if ([navigationAction.request.URL.absoluteString hasPrefix:@"nielsen"])
        {[self.nielsenAppApi userOptOut:navigationAction.request.URL.absoluteString];
            decisionHandler(WKNavigationActionPolicyCancel); 
        } else {
            if (navigationAction.navigationType == WKNavigationTypeLinkActivated) 
            { if ([navigationAction.request.URL.absoluteString hasSuffix:@"#"]) 
                      {decisionHandler(WKNavigationActionPolicyAllow);
                } else {
                    decisionHandler(WKNavigationActionPolicyCancel);
                    [webView loadRequest:[NSURLRequest requestWithURL:navigationAction.request.URL]];
                }} else {
                 decisionHandler(WKNavigationActionPolicyAllow);
            }}}
}


Global iOS SDK No ID Opt-out

If you are building an app that will be listed in the Kids Category:

  1. Ensure that you are using the NoID version of the Nielsen SDK Framework.
  2. Immediately following the initialization of the Nielsen SDK ensure you call the userOptOut API with Opt out selection:
NielsenAppApi?.userOptOut("nielsenappsdk://1"); // User opt-out

Retrieve current Opt-Out preference

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

@property (readonly) BOOL optOutStatus