DCR Italy Static iOS SDK

From Engineering Client Portal

Engineering Portal breadcrumbArrow.png Digital breadcrumbArrow.png International DCR breadcrumbArrow.png DCR Italy Static iOS SDK

Overview

The Nielsen SDK is one of multiple framework SDKs that Nielsen provides to enable measuring linear (live) and on-demand TV viewing using TVs, mobile devices, etc. The App SDK is the framework for mobile application developers to integrate Nielsen Measurement into their media player applications. It supports a variety of Nielsen Measurement Products like Digital in TV Ratings, Digital Content Ratings (DCR & DTVR), Digital Ad Ratings (DAR). Nielsen SDKs are also equipped to measure static content and can track key life cycle events of an application like:

  • Application launch events and how long app was running
  • Time of viewing a sub section / page in the application.

Implementation

This guide covers implementation steps for iOS using Xcode to enable Static Measurement within you APP.

If you are building an app for the 'kids category' please review the Opt Out Requirement.

Prerequisites

This Guide is for the Implementation of Static Measurement. For implementation of Video, please refer to the iOS DCR Video Implementation Guide. To start using the App SDK, the following items are required:

Item Description Source
App ID (appid) Unique ID assigned to the player/site and configured by product. Provided by Nielsen
Nielsen SDK Includes SDK frameworks and sample implementation; See iOS SDK Release Notes Download
sfcode Unique identifier for the environment that the SDK should point to Provided by Nielsen

If need App ID(s) or our SDKs, feel free to reach out to us and we will be happy to help you get started. Refer to Digital Measurement Onboarding guide for information on how to get a Nielsen App SDK and appid.

Setting up your Development Environment

Prior to SDK Version 6.2.0.0 the IOS framework has been distributed as a static library packaged into framework bundle format. Apple recommends to use dynamic framework, it has some benefits over static libraries like less executable file size of an app, faster startup time and native support in xCode IDE. Nielsen AppSDK has been transformed into dynamic framework in this release (static framework is still available).

If migrating from the static library to this new dynamic framework, once implemented, unless your specific application requires, you can remove the following Frameworks that were once required: [AdSupport, JavascriptCore, SystemConfiguration, Security, AVFoundation, libc++]

The Dynamic framework is created as a fat framework. It means that it contains slices required for devices (armv7, arm64) as well as slices required for simulators (i386, x86_64). Simulator slices are needed to let clients build and debug their app on the simulators, but they should be removed before sending the app to the AppStore. The example of the shell script that should be added as a Run Script phase in the application can be found here.

How to obtain the NielsenAppApi.Framework

The Nielsen AppSDK can either be downloaded directly or can be integrated directly within an application through the use of CocoaPods. We recommend using the CocoaPods-based integration whenever possible to ensure you maintain the most recent changes and enhancements to the Nielsen libraries.

Configuring Xcode Development Environment

Starting with SDK version 6.0.0.0, the Nielsen App SDK is compatible with Apple iOS versions 8.0 and above. In addition, when using the dynamic framework, all the required frameworks are linked automatically as the are needed. More details can be found here: https://stackoverflow.com/questions/24902787/dont-we-need-to-link-framework-to-xcode-project-anymore

Note: All communications between the SDK and the Census (Collection Facility) use HTTPS.

Download Framework

The first step is to download and copy the NielsenAppApi.framework bundle to the app project directory. (Not required if using CocaPods)

Add Framework

In the General tab for app configuration add NielsenAppApi.framework in the list of Embedded Binaries. (Not required if using CocaPods)

Add Path

Add path to the NielsenAppApi.framework in the Framework Search Paths build setting. (Not required if using CocaPods)

Import Framework

Add NielsenAppApi.framework module in the source file of your app:

Using Swift

Add the following:

import NielsenAppApi

Using Objective-C

@import NielsenAppApi;

SDK Initialization

The latest version of the Nielsen App SDK allows instantiating multiple instances of the SDK object, which can be used simultaneously without any issue. The sharedInstance API that creates a singleton object was deprecated prior to version 5.1.1. (Click here for an example of multiple instances)

The following table contains the list of arguments that can be passed via the AppInfo JSON schema.

  • The appid is provided by the Nielsen Technical Account Manager (TAM). The appid is a GUID data type and is specific to the application.
Parameter / Argument Description Source Required? Example
appid Unique Nielsen ID for the application. The ID is a GUID data type. If you did not receive your App ID, let us know and we will provide you. Nielsen-specified Yes PXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
appname Name of the application Client-defined Yes "Nielsen Sample App"
appversion Current version of the app used Client-defined Yes "1.0.2"
sfcode Nielsen collection facility to which the SDK should connect.

Italian Clients:

  • "it"
Nielsen-specified Yes "it"
nol_devDebug Enables Nielsen console logging. Only required for testing Nielsen-specified Yes for Debugging / Testing App "DEBUG"

Debug flag for development environment

Player application developers / integrators can use Debug flag to check whether an App SDK API call made is successful. To activate the Debug flag, Pass the argument @"nol_devDebug":@"DEBUG", in the JSON string . The permitted values are:

  • INFO: Displays the API calls and the input data from the application (validate player name, app ID, etc.). It can be used as certification Aid.
  • WARN: Indicates potential integration / configuration errors or SDK issues.
  • ERROR: Indicates important integration errors or non-recoverable SDK issues.
  • DEBUG: Debug logs, used by the developers to debug more complex issues.

Once the flag is active, it logs each API call made and the data passed. The log created by this flag is minimal.

Note: Activate the Debug flag in a Test environment.

Sample SDK Initialization Code

App tracking transparency framework

To display the App Tracking Transparency authorization request for accessing the IDFA, update your info.plist to add the NSUserTrackingUsageDescription key with a custom message describing your usage. Below is an example description text: <key>NSUserTrackingUsageDescription</key> <string>This identifier will be used to deliver personalized ads to you.</string>

The system automatically generates the prompt’s title, which includes the name of your app, then the usage description appears as part of the App Tracking

To present the authorization request, call requestTrackingAuthorizationWithCompletionHandler.

Please NOTE: It is important to initialize the NielsenSDK after the ATTrackingManager has Authorized usage. When the SDK initializes, it checks the status of the ATTrackingManager.

You can find an example in the file Global iOS SDK Download from the SDK Downloads section, folder name NielsenSampleVideoPlayer.

Swift 4.0 Example:

NielsenInit.swift

import Foundation
import NielsenAppApi

class NielsenInit : NSObject {
    class func createNielsenApi(delegate: NielsenAppApiDelegate) -> NielsenAppApi?{
        
        let appInformation:[String: String] = [
            "appid": "PDA7D5EE6-B1B8-4123-9277-2A788XXXXXXX",
            "appversion": "1.0.2",
            "appname": "Nielsen Sample App",
            "sfcode": "it",
            "nol_devDebug": "DEBUG"
        ]       
        return NielsenAppApi(appInfo:appInformation, delegate:delegate)
    }
}

Sample code using AVPlayer

LandingVC.swift

import UIKit
import NielsenAppApi


class LandingVC: UIViewController, NielsenAppApiDelegate {
    
    var nielsenMain : NielsenAppApi!
    var sdkMethods : SDKMethods!
    var data : [String : Any]!

class ViewController: UIViewController, NielsenAppApiDelegate, AVPlayerViewControllerDelegate  {

// your code//    

  override func viewDidLoad() {
        super.viewDidLoad()
        //Getting the instance of NielsenApi
        self.nielsenApi = NielsenInit.createNielsenApi(delegate: self)
            }
  }
    override func viewDidAppear(_ animated: Bool) {      
        self.data = sdkMethods.loadStaticMaster()     // This is just an example of populating the metadata
        self.nielsenMain.loadMetadata(self.data)
    }

Objective C =

Initialize the Nielsen App object within the viewDidLoad view controller delegate method using initWithAppInfo:delegate:

If App SDK is initialized using init or new methods, it will ignore the API calls resulting in no measurement. The SDK will not return any errors.

    
#import "NlsAppApiFactory.h"
#import <NielsenAppApi/NielsenAppApi.h>

@implementation NlsAppApiFactory

+ (NielsenAppApi *)createNielsenAppApiWithDelegate:(id<NielsenAppApiDelegate>)delegate;
{
    
    
    NSDictionary *appInformation = @{ 
                                     @"appid": "PDA7D5EE6-B1B8-4123-9277-2A788XXXXXXX",
                                     @"appversion": "1.0.2",
                                     @"appname": "Nielsen Sample App",
                                     @"sfcode": "it",
                                     @"nol_devDebug": @"DEBUG"
                                    };
    
    return [[NielsenAppApi alloc] initWithAppInfo:appInformation delegate:delegate];
}

@end


The following would be the NlsAppApiFactory.h file:

#import <Foundation/Foundation.h>

@class NielsenAppApi;
@protocol NielsenAppApiDelegate;

@interface NlsAppApiFactory : NSObject 

+ (NielsenAppAPI *) createNielsenAppApiWithDelegate:(id<NielsenAppApiDelegate>)delegate;

@end

Sample Code:

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
        
    //Getting the instance of Nielsen SDK
    nielsenApi = [NlsAppApiFactory createNielsenAppApiWithDelegate:nil];
}}

APP SDK Error & Event Codes

To view the Error and Event codes for iOS, please review the App SDK Event Code Reference page.

Populate and Pass Metadata Object

The Nielsen SDK is able to monitor Application launch events and how long your app has been running. Once the Nielsen SDK has been Initialized, pass "type":'static' as a JSON object via loadMetadata.

Swift

        let staticMetadata = [
            "type": "static",
            "assetid": "vid345-67483",
            "section": "Home_EntityName_iOS"
        ];
         self.nielsenAppApi?.loadMetadata(staticMetadata)

Objective C

 
   NSDictionary *staticMetadata = @
    {
        "type": "static",
        "assetid": "vid345-67483",
        "section": "Home_EntityName_iOS"
    }

[nielsenApi loadMetadata:(staticMetadata)];


The above code would be inserted only for the "home section" within your app.

Nielsen SDK Metadata

The following table defines the staticMetadata reserved keys:

Key Description Data Type Value Required?
type asset type fixed 'static' Yes
assetid Unique ID for each article dynamic custom (no Special Characters) Yes
section section of the App to be measured
EntityName = brand name or sub-brand name
dynamic Home_EntityName_iOS for iOS App Yes

Handling Foreground and Background states

For iOS, background/foreground detection is handled by the app lifecylce APIs which are provided by Apple:

Foreground/Background state measurement is a requirement of Nielsen AppSDK implementation which is especially crucial for static measurement.

Privacy and Opt-Out

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

  • OS-level Opt-out - managed by AppTracking or Limit Ad Tracking setting on device (preferred approach).
  • User Choice - Direct call to SDK. Can be used without the Ad Framework

Special Note Regarding Apps in the Kids Category

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

Ensure that you are using the NoID version: of the Nielsen SDK Framework. Also, you can use the Artifactory method. Immediately following the initialization of the Nielsen SDK ensure you call the userOptOut API with Opt out selection:

NielsenAppApi?.userOptOut("nielsenappsdk://1"); // User opt-outv

OS-level 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.

Get the latest Nielsen opt-out URL

  • Get the current Nielsen opt-out URL via optOutURL
  • Display a WebView element whose loadUrl is set to the value obtained from optOutURL

Webview Example

The below code is an example of displaying the Nielsen Privacy page to the user.

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)  //create an instance 
        
        if let appApi = self.nielsenApi {
            //Getting the optPut URL from SDK
            if let url = URL(string: appApi.optOutURL) { //query the nielsensdk for the current privacy page
                webView.load(URLRequest(url: url))
                webView.allowsBackForwardNavigationGestures = true
            }}}}

User Choice

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.

The User Choice opt-out method works 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

Opt-out example code

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

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

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.

"Si prega di notare che questa app include il software di misurazione proprietario di Nielsen che contribuisce alla ricerca di mercato. Per ulteriori informazioni, si prega di consultare il seguente link https://www.nielsen.com/it/it/legal/privacy-statement/digital-measurement/"

Going Live

Following Nielsen testing, users need to make one update to the initialization call to ensure that the site is being measured properly.

  1. Debug Logging: Disable logging by deleting {nol_sdkDebug: 'DEBUG'} from initialization call.
    • Example Production Initialization Call - Refer to the production initialization call below:

iOS Example:

class NielsenInit: NSObject {
    class func createNielsenAppApi(delegate: NielsenAppApiDelegate) -> NielsenAppApi?{
    let appInformation:[String: String] = [
            "appid": "PDA7D5EE6-B1B8-4123-9277-2A788XXXXXXX",
            "appversion": "1.0.2",
            "appname": "Nielsen Sample App",
            "sfcode": "it"
            // Remove Flag:   "nol_devDebug": "DEBUG"
        ]
        return NielsenAppApi(appInfo:appInformation, delegate:delegate)
    }
}

Sample Applications

You can find some examples in the file Global iOS SDK Download from the SDK Downloads section