Digital Measurement iOS Simplified API: Difference between revisions

From Engineering Client Portal

m (formatting fix)
m (added "; limit to 25 unique values across custom segments (segA + segB + segC)" for seg descriptions)
Line 885: Line 885:
|section || Unique Value assigned to page/site section || HomePage || Yes
|section || Unique Value assigned to page/site section || HomePage || Yes
|-
|-
| segA ||name of program (25 character limit) || custom || Yes
| segA ||name of program (25 character limit); limit to 25 unique values across custom segments (segA + segB + segC) || custom || Yes
|-
|-
| segB || custom segment B || custom ||  
| segB || custom segment B; limit to 25 unique values across custom segments (segA + segB + segC) || custom ||  
|-
|-
| segC || custom segment C || custom ||  
| segC || custom segment C; limit to 25 unique values across custom segments (segA + segB + segC) || custom ||  
|-
|-
|}
|}

Revision as of 22:30, 12 December 2018

Engineering Portal / Digital / DCR & DTVR / Digital Measurement iOS Simplified API

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), Digital Audio. 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.

Prerequisites

To start using the App SDK, the following details are required:

  • App ID (appid): Unique ID assigned to the player/site and configured by product.
  • sfcode: Unique identifier for the environment that the SDK should point to.
  • Nielsen SDK: The Nielsen SDK package contains a variety of sample players for your reference.

If you do not have any of these prerequisites or if you have any questions, please contact our SDK sales support team. Refer to Digital Measurement Onboarding guide for information on how to get a Nielsen App SDK and appid.

Simplified SDK API

As part of making the SDK more user-friendly and reducing the number of app integration touch points, Nielsen has designed a simple interface to pass metadata to the SDK. The new trackevent() API has been implemented as a wrapper for the existing SDK and will be responsible for handling new API calls, performing validation, and translating new API calls to the existing Nielsen App SDK API methods. Applications which are already integrated with the existing SDK API are unaffected by this new API. SimplifiedAPI vs StandardAPI New.jpg In the Simplified API, one API call will be used to reference many methods. The key-value structure of this API call will provide information for proper crediting. The SDK will utilize the data received in this call and translate it into a sequence of calls linking to the existing API.

Co-Existance.jpg

For iOS SDK framework package will contain 2 public header files. One header file will contain old SDK interface and will be used by existing clients (NielsenAppApi.h). New API will be defined in a new public header file (NielsenEventTracker.h).

For Android, a new wrapper class for AppSdk will be introduced (AppSdkTrackEvent). This class will be responsible for handling and translating new API calls into calls of the existing Nielsen App SDK API methods. A new public API will be introduced in this class, that accepts a JSONObject parameter.

Implementation

This guide covers implementation steps for iOS using Xcode and Android using Android Studio.

Setting up your Development Environment

Configuring Xcode Development Environment

Nielsen App SDK is compatible with Apple iOS versions 8.0 and above.

The SDK uses the NSURLSession instead of the deprecated NSURLConnection.

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

Importing Frameworks The first step is to ensure that the following frameworks and libraries are imported into the Frameworks folder of the Xcode project before creating an instance of the Nielsen App SDK object.

  • UIKit.framework
  • Foundation.framework
  • AdSupport.framework
  • JavascriptCore.framework
  • WebKit.framework
  • SystemConfiguration.framework
  • Security.framework
    • Nielsen Analytics framework makes use of a number of functions in this library.
  • AVFoundation.framework
  • NielsenAppApi.framework
  • libc++.tbd (as SDK contains Objective C++ source file)
    • Alternatively, include -lstdc++ in Build Settings → Other Linker Flag of the Xcode project

Example

  • Extract “NielsenAppApi.Framework” from the Nielsen App SDK sample app and copy it to Frameworks folder of the Xcode project.
  • Add the code -#import NielsenAppApi/NielsenAppApi.h to the View Controller’s header file.

Ensure that the following are included in the Linked Frameworks and Libraries list (located in the project’s Summary settings).

  • Nielsen App SDK
  • iOS security framework


Using Swift

To import a set of Objective-C files in the same app target as your Swift code, you rely on an Objective-C bridging header to expose those files to Swift. Xcode offers to create this header file when you add a Swift file to an existing Objective-C app, or an Objective-C file to an existing Swift app.

  • Select File/New File/Objective-C File
  • Xcode will prompt you to create a bridging header.
bridgingheader 2x.png

Once this file has been created, you need to add the following:

#import <NielsenAppApi/NielsenAppApi.h>

Using Objective-C

Add the code

#import <NielsenAppApi/NielsenAppApi.h>

to the View Controller’s header file.

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. (Version 4.0 for Android)

  • A maximum of four SDK instances per appid are supported. When a fifth SDK instance is launched, the SDK will return “nil” from initWithAppInfo:delegate:

The following table contains the list of arguments that should be passed during initialization.

  • The appid is provided by the Nielsen Technical Account Manager (TAM).
Parameter / Argument Description Source Required? Example
appid Unique id for the application assigned by Nielsen.

It is GUID data type, provided by the Nielsen Technical Account Manager (TAM).

Nielsen-specified Yes PXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
appname Name of the application Client-defined No "Nielsen Sample App"
appversion Current version of the app used Client-defined No "1.0.2"
sfcode Nielsen collection facility to which the SDK should connect.

DTVR

  • "us"

Digital Audio

  • "drm"

DCR

  • "dcr"
Nielsen-specified Yes "dcr"
containerID View ID of the UI element used as player view in application for Viewability (Future Feature) Client-defined No "1234567"
nol_devDebug Enables Nielsen console logging. Only required for testing Nielsen-specified Optional "DEBUG"



Sample SDK Initialization Code

Swift

Swift 4.0 Example: NielsenInit.swift

import Foundation
import NielsenAppApi

class NielsenInit : NSObject {
    class func createEventTracker(delegate: NielsenEventTrackerDelegate) -> NielsenEventTracker?{
    
        //Initialising the NielsenEventTracker class by passing app information which returns the instance of NielsenEventTracker.
        
        var nielsenEventTracker: NielsenEventTracker?
        
        let appInformation = [
  
            "appid": "PDA7D5EE6-B1B8-4123-9277-2A788XXXXXXX",
            "appversion": "1.0",
            "appname": "Amazing app",
            "sfcode": "dcr",
            "nol_devDebug": "DEBUG",
            "containerId": String(containerId)   //Keep container id unique constant, you can use tag property of player.
        ]
        
        nielsenEventTracker = NielsenEventTracker(appInfo:appInformation1, delegate:delegate)
        return nielsenEventTracker
    }
}


Sample code: ViewController
ViewController.swift

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //Getting the instance of NielsenEventTracker
        
        self.nielsenEventTracker = NielsenInit.createEventTracker(delegate: self)

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.

Objective-C Example: NielsenInit.m

    
#import "NielsenInit.h"
#import <NielsenAppApi/NielsenEventTracker.h>

@implementation NielsenInit

+ (NielsenEventTracker *)createNielsenEventTrackerWithDelegate:(id<NielsenEventTrackerDelegate>)delegate
{
    //Initialising the NielsenEventTracker class by passing app information which returns the instance of NielsenEventTracker.
    
    NSDictionary *appInformation = @{ @"appid": @"PDA7D5EE6-B1B8-4123-9277-2A788XXXXXXX",
                            @"appversion": @"1.0",
                            @"appname": @"Objc Test app",
                            @"sfcode": @"dcr",
                            @"nol_devDebug": @"INFO",
                            @"containerId": @"1" };  //Keep container id unique constant, you can use tag property of player.
    
    return [[NielsenEventTracker alloc] initWithAppInfo:appInformation delegate:delegate];
}


The following would be the NielsenInit.h file:

#import <Foundation/Foundation.h>

@class NielsenEventTracker;
@protocol NielsenEventTrackerDelegate;

@interface NielsenInit : NSObject

+ (NielsenEventTracker *)createNielsenEventTrackerWithDelegate:(id<NielsenEventTrackerDelegate>)delegate;

@end

The ViewController.m file could then contain the following line(s):

  
    //Getting the instance of NielsenEventTracker
    nielsenEventTracker = [NielsenInit createNielsenEventTrackerWithDelegate:nil];
/////
-(void) setPlayHeadPosition {
    
    //Setting play head position
    CMTime timeInterval = CMTimeMakeWithSeconds(1, 1);
    [player addPeriodicTimeObserverForInterval:(timeInterval) queue:dispatch_get_main_queue() usingBlock:^(CMTime time){
        NSTimeInterval seconds = CMTimeGetSeconds(time);
        NSInteger intSec = seconds;
        NSString* strSec = [NSString stringWithFormat:@"%li", intSec];
        
        //updating playHead position in dictionary.
        [mutableData setValue:strSec forKey:@"playheadPosition"];
        
        //Sending data dictionary to SDK with updated playHead position.
        [nielsenEventTracker trackEvent:mutableData];
    }];
}



APP SDK Error & Event Codes

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

Simplified API Syntax

The existing API has a number of methods used for reporting player and application state changes to the SDK. The order of calls is important for the SDK in the existing API. In the new simplified API, all these calls will be replaced with one API call that will get one dictionary object with many key-value pairs, where any value could be another complex dictionary object. All the data provided in the older API in separate calls will be provided in one single call.

Main API call for the new NielsenEventTracker API:

 
- (void)trackEvent:(NSDictionary *)data;

Handling JSON Metadata

Parameter “data” is a JSON object with many key-value pairs that holds all information required by SDK.

Format of input object is the following:

{ 
 "event": <event identifier>,
 "type": <type of metadata>,
 "metadata":{ 
   "content": <content metadata object>,
   "ad": <ad metadata object>,
   "static": <static metadata object>
 },
 "playheadPosition":<playhead value | UTC>,
 "id3Data": <id3 payload>,
}


Event Types

The New API method supports the following event types:

Key Description
playhead

It is used to pass content, ad or static metadata, the current playhead value, Unix timestamp or id3 payload, OTT information to the SDK.

pause

This event should be used to in the following cases: application enters background, any application interruptions, content playback is paused. (Pause is detected by SDK automatically only if the time gap between commands exceeds 30 minutes.)

complete

It is called when session is completed or ends.

adStop

This event should be called at the end of each ad and is required when advertisements have the same assetId.


DCR and DTVR require various levels of data. Please select the TAB of the product you are interested in reviewing.

DCR

Digital Content Ratings

Parameter Description Supported values Example
event Event identifier

String: playhead,pause,complete, adStop

"event":"playhead"
type Determines the metadata object

that should be used for crediting.

String:
content, ad, static

"type":"content"
metadata Object that holds metadata values of specific types

Detailed in tables below

Object
"metadata":{ 
   "content": <content metadata object>,
   "ad": <ad metadata object>,
   "static": <static metadata object>
 },
playheadPosition Playhead value as reported by video player. Unix timestamp (seconds since Jan-01-1970 UTC) for live video. String

Position value is Unix timestamp (live): "playheadPosition":"1542797780"

Position value is playhead:

"playheadPosition":"10"

Content Metadata

Content metadata sent for every playheadposition update.

Keys Description Example Required
assetName name of program (100 character limit) "MyTest789" Yes
assetid unique ID assigned to asset custom Yes
length length of content in seconds seconds (0 for live stream or unknown) Yes
program name of program (100 character limit) custom Yes
segB custom segment B ¹ custom
segC custom segment C ¹ custom
title name of program (100 character limit) custom Yes
type 'content', 'ad', 'static' 'content' Yes
section Unique Value assigned to page/site section HomePage Yes
airdate the airdate in the linear TV ² YYYYMMDD HH24:MI:SS Yes
isfullepisode full episode flag "y"- full episode, "n"- non full episode Yes
crossId1 standard episode ID custom
crossId2 content originator (only required for distributors) Nielsen provided
adloadtype linear vs dynamic ad model 1=Linear

2=Dynamic Ads

custom

¹ Custom segments (segB and segC) can be used to aggregate video and/or static content within a single Brand to receive more granular reports within a brand.
² Acceptable Air Date Formats:

YYYYMMDD HH24:MI:SS
YYYYMMDDHH24MISS
YYYY-MM-DDTHH:MI:SS
YYYY-MM-DDHH:MI:SS 
YYYYMMDDHH:MI:SS
MM-DD-YYYY
YYYYMMDD HH:MI:SS


For USA all times should be EST, for all other countries Local Time. Below is a sample event for DCR. If no ad or static values, these can be left as blank/null.

{ 
"event": "playhead",
"type": "content",
"metadata": { 
  "content":{
    "assetName":"Big Buck Bunny",
    "assetid":"B66473",
    "length":"3600",
    "program":"MyProgram",
    "segB":"CustomSegmentValueB",
    "segC":"segmentC",
    "title":"S2,E3",
    "type":"content",
    "section":"cloudApi_app",
    "airdate":"20180120 10:00:00",
    "isfullepisode":"y",
    "crossId1":"Standard Episode ID",
    "crossId2" :"Content Originator",
    "adloadtype":"2"},
"ad": {},
"static": {}
},
"playheadPosition": "",
}

DTVR

Digital TV Ratings info

Parameter Description Supported values Example
event Event identifier

String: playhead,pause,complete, adStop

"event":"playhead"
type Determines the metadata object that should be used for crediting.

String:
content, ad, static

"type":"content"
adModel linear vs dynamic ad model 1=Linear

2=Dynamic Ads

custom
channelName Any string representing the.channel/stream Object custom
playheadPosition Playhead value or Unix timestamp (seconds since Jan-01-1970 UTC) String

Position value is Unix timestamp: "playheadPosition":"1542797780"

Position value is playhead:

"playheadPosition":"10"

id3Data Nielsen ID3 payload Object

"id3Data": "www.nielsen.com/065H2g6E7ZyQ5UdmMAbbpg ==/_EMc37zfVgq_8KB7baUYfg==/ADQCAmgV1Xyvnynyg60 kZO_Ejkcn2KLSrTzyJpZZ-QeRn8GpMGTWI7-HrEKzghxyzC yBEoIDv2kA2g1QJmeYOl5GnwfrLDVK2bNLTbQxr1z9VBfxa hBcQP5tqbjhyMzdVqrMKuvvJO1jhtSXa9AroChb11ZUnG1W VJx2O4M=/33648/22847/00"

Below is a sample event for DTVR. If no ad or static values, these can be left as blank/null.

{ 
"event": "playhead",
"type": "content",
"metadata": { 
  "content":{
    "adModel":"1",
    "channelname":"channel1"
  },
"ad": {},
"static": {}
},
"playheadPosition": "",
"id3Data": "www.nielsen.com/065H2g6E7ZyQ5UdmMAbbpg==/_
EMc37zfVgq_8KB7baUYfg==/ADQCAmgV1Xyvnynyg60kZO_Ejkcn
2KLSrTzyJpZZ-QeRn8GpMGTWI7-HrEKzghxyzCyBEoIDv2kA2g1Q
JmeYOl5GnwfrLDVK2bNLTbQxr1z9VBfxahBcQP5tqbjhyMzdVqrMK
uvvJO1jhtSXa9AroChb11ZUnG1WVJx2O4M=/33648/22847/00"
}

DCR & DTVR

Applies to DCR and DTVR

Parameter Description Supported values Example
event Event identifier

String: playhead, pause, complete, adStop

"event":"playhead"
type Determines the metadata object that should be used for crediting.

String:
content, ad, static

"type":"content"
metadata Object that holds metadata values of specific types

Detailed in tables below

Object
"metadata":{ 
   "content": <content metadata object>,
   "ad": <ad metadata object>,
   "static": <static metadata object>
 },
playheadPosition Playhead value or Unix timestamp (seconds since Jan-01-1970 UTC) String

Position value is Unix timestamp: "playheadPosition":"1501225191747"

Position value is playhead:

"playheadPosition":"10"

id3Data Nielsen ID3 payload Object

"id3Data": "www.nielsen.com/065H2g6E7ZyQ5UdmMAbbpg ==/_EMc37zfVgq_8KB7baUYfg==/ADQCAmgV1Xyvnynyg60 kZO_Ejkcn2KLSrTzyJpZZ-QeRn8GpMGTWI7-HrEKzghxyzC yBEoIDv2kA2g1QJmeYOl5GnwfrLDVK2bNLTbQxr1z9VBfxa hBcQP5tqbjhyMzdVqrMKuvvJO1jhtSXa9AroChb11ZUnG1W VJx2O4M=/33648/22847/00"

ottData Object that holds OTT information Object
"ottData": {
   "ottStatus": 1,
   "ottType": casting,
   "ottDevice": chromecast,
   "ottDeviceID": 1234
}

Content Metadata

Content metadata sent for every playheadposition update.

Keys Description Example Required
length length of content in seconds seconds (86400 for live stream) Yes
type "content", "ad", "static" "content" Yes
adModel linear vs dynamic ad model 1=Linear

2=Dynamic Ads

custom
adloadtype DCR Ad Model 1=Linear

2=Dynamic Ads

custom

+ Custom segments (segB and segC) can be used to aggregate video and/or static content within a single Brand to receive more granular reports within a brand.
++ Acceptable Air Date Formats:

YYYYMMDD HH24:MI:SS
YYYYMMDDHH24MISS
YYYY-MM-DDTHH:MI:SS
YYYY-MM-DDHH:MI:SS 
YYYYMMDDHH:MI:SS
MM-DD-YYYY
YYYYMMDD HH:MI:SS


Below is a sample event for DCR/DTVR joint integration. If no ad or static values, these can be left as blank/null.

{ 
"event": "playhead",
"type": "content",
"metadata": { 
  "content":{
    "type":"content",
    "length":"86400",
    "adModel":"1",
    "adloadtype":"1"},
  "ad": {},
  "static": {}
},
"playheadPosition": "",
"id3Data": "www.nielsen.com/065H2g6E7ZyQ5UdmMAbbpg==/_
EMc37zfVgq_8KB7baUYfg==/ADQCAmgV1Xyvnynyg60kZO_Ejkcn
2KLSrTzyJpZZ-QeRn8GpMGTWI7-HrEKzghxyzCyBEoIDv2kA2g1Q
JmeYOl5GnwfrLDVK2bNLTbQxr1z9VBfxahBcQP5tqbjhyMzdVqrMK
uvvJO1jhtSXa9AroChb11ZUnG1WVJx2O4M=/33648/22847/00"
}

Ad Metadata

The ad metadata (if applicable) should be passed for each individual ad, if ads are available during or before the stream begins.

Keys Description Values Example
assetid unique ID assigned to ad custom
(no Special Characters)
'AD1234'
title unique name assigned to ad custom 'ADtitle'
adldx Ad Index (*See Note below*) custom "66478364"
type type of ad 'preroll', 'midroll', or 'postroll' 'preroll'
length length of ad In Seconds '20'

Ad Metadata Sample

{
  "ad": {
    "assetid":"AD12345",
    "title":"ADTestTitle",
    "adldx":"1",
    "type":"preroll",
    "length":"20"
  },
}

Managing Ads

If there is an Ad block within the playing content (such as a midroll) you need to:

  • Reset the playhead position to 0 for each ad.
  • Call the adStop event at the end of each ad or increment the adldx

The Simplified SDK can automatically detect the change from ad to content as well as ad to ad if the assetID changes; however, there could be situations where the same ad is played back to back.

Sometimes it is not possible for integrators to provide different assetId value for individual ads in a sequence of ads. Taking this into account, the Simplified API will support a new parameter for ad metadata: adIdx. This parameter is an index of an individual ad in a sequence of ads. Once the next ad is started the adIdx parameter should be changed and provided as part of ad metadata. You can either increment/change the adldx value, and/or call adStop at the end of each Ad.

            // Example of passing both values
            self.data.updateValue("adStop", forKey: "event")
            self.data.updateValue("223", forKey: "adldx")
            self.nielsenEventTracker.trackEvent(data)

Static Metadata

Keys Description Values Required
type type identifier "static"
assetid unique ID assigned for each article/section custom
section Unique Value assigned to page/site section HomePage Yes
segA name of program (25 character limit); limit to 25 unique values across custom segments (segA + segB + segC) custom Yes
segB custom segment B; limit to 25 unique values across custom segments (segA + segB + segC) custom
segC custom segment C; limit to 25 unique values across custom segments (segA + segB + segC) custom
{
    "static":
            {
                "type": "static",
                "section": "homeSection",
                "assetid": "AID885-9984",
                "segA": "CustomSegmentValueA",
                "segB": "CustomSegmentValueB",
                "segC": "CustomSegmentValueC",
            }
        },

Putting it all together

Swift

      func loadPreRollAd() -> [String : Any] {
        
        //Loading Ad data
        
        url = NSURL(string: "http://www.nielseninternet.com/NWCC-3002/prog_index.m3u8")
        
        let content = [
            "assetName":"Big Buck Bunny",
            "assetid":"B66473",
            "length":"3600",
            "program":"MyProgram",
            "segB":"CustomSegmentValueB",
            "segC":"segmentC",
            "title":"S2,E3",
            "type":"content",
            "section":"app_Mainpage",
            "airdate":"20180120 10:00:00",
            "isfullepisode":"y",
            "crossId1":"Standard Episode ID",
            "crossId2" :"Content Originator",
            "adloadtype":"2"
        ]
           
        let staticObj = [
            "type":"static",
            "section":"homeSection",
            "segA":"CustomSegmentValueA",
            "segB":"CustomSegmentValueB",
            "segC":"CustomSegmentValueC"
            ]

        let ad = [
            "assetid":"AD12345",
            "title":"ADTestTitle",
            "adldx":"1",
            "type":"preroll",
            "length":"20"
        ]
        
        let metadata = [
            "content" : content,
            "ad" : ad,
            "static" : staticObj
            ] as [String : Any]
        
        
        let data = [
            "metadata" : metadata,
            "event": "playhead",
            "playheadPosition": "0",
            "type": "ad",
            ] as [String : Any]
        
        return data    
    }

Objective C

 
#import <Foundation/Foundation.h>
#import "SDKMethods.h"

@implementation SDKMethods
//Loading content Data
- (NSDictionary *)loadContentData
{
- (NSDictionary *)loadPreRollAd
{
    self.url = [NSURL URLWithString:@"http://www.nielseninternet.com/NWCC-3002/prog_index.m3u8"];
    
    //We should pass content dictionary also in Ad video.
    NSDictionary *content = @{  @"assetName":@"ChromeCast1",
                                @"assetid":@"C77664",
                                @"length":@"3600",
                                @"program":@"MyProgram",
                                @"segB":@"CustomSegmentValueB",
                                @"segC":@"segmentC",
                                @"title":@"S2,E3",
                                @"type":@"content",
                                @"section":@"app_Mainpage",
                                @"airdate":@"20180120 10:00:00",
                                @"isfullepisode":@"y",
                                @"adloadtype":@"2",
                                @"channelName":@"My Channel 1",
                                @"pipMode":@"false" };
    
    NSDictionary *ad = @{ @"assetid":@"AD12345",
                          @"title":@"ADTestTitle",
                          @"type":@"preroll",
                          @"length":@"20" };

   NSDictionary *staticObj = @{ @"type":@"static",
                               @"section":@"homeSection",
                               @"segA":@"CustomSegmentValueA",
                               @"segB":@"CustomSegmentValueB",
                               @"segC":@"CustomSegmentValueC" };
    
    //static data should be empty in Ad video
    NSDictionary *metadata = @{  @"content" : content,
                                 @"ad" : ad,
                                 @"static" :  @staticObj };
    
    NSDictionary *data = @{  @"metadata" : metadata,
                             @"event": @"playhead",
                             @"type": @"ad",
                             @"playheadPosition": @"0" };
    
    return data;
}


JSON examples

Additional JSON examples such as:

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 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)
  3. App Level Opt-Out - Where Ad Framework cannot be leveraged

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" ("Limit Ad Tracking" for Android) 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

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 viaOS-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 http://priv-policy.imrworldwide.com/priv/mobile/us/en/optout.html for more information"

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


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 userOptOut.

Capture and forward user selection

-(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]);
}
  • The app gets the user selection string via webviews shouldStartLoadWithRequest and invokes userOptOut with user selection. The delegate method handles the 'WebView' URL requests, interprets the commands, and calls the SDK accordingly.
    • [nAppApiObject userOptOut:command] passes the user's selection on Nielsen Privacy page to the SDK to allow the SDK to perform the required functions.

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.

Example Code

Putting it all together

The below code was built to show the functionality of the Nielsen Simplified API using a standard no-frills player. An Advanced Player is available with the SDK Bundle.

Swift

iphonescreenshot.png

Swift Version 4 Code Example

Select the below link to download the sample files
Download Project Files

NielsenInit.swift

// This is sample code of a very basic implementation of the Nielsen 'Simplified API'
// This code is for educational purposes only
//
import Foundation
import NielsenAppApi

class NielsenInit : NSObject {
    class func createEventTracker(delegate: NielsenEventTrackerDelegate) -> NielsenEventTracker?{
    
        //Initialising the NielsenEventTracker class by passing app information which returns the instance of NielsenEventTracker.
        
        var nielsenEventTracker: NielsenEventTracker?
        
        let appInformation = [
  
            "appid": "PDA7D5EE6-B1B8-4123-9277-2A788XXXXXXX",
            "appversion": "1.0",
            "appname": "Amazing app",
            "sfcode": "dcr",
            "nol_devDebug": "DEBUG",
            "containerId": String(containerId)
        ]
        
        nielsenEventTracker = NielsenEventTracker(appInfo:appInformation, delegate:delegate)
        return nielsenEventTracker
    }
}

SDKMethods.swift

import Foundation

class SDKMethods : NSObject {
    
    var nielsenApi : NielsenAppApi!
    var url = NSURL(string: "")
    var content : NSDictionary!
    
    //Loading Static Data
    func loadStatic() -> [String : Any] {
        
        let staticObj = [
            "type":"static",
            "section":"homeSection",
            "segA":"CustomSegmentValueA",
            "segB":"CustomSegmentValueB",
            "segC":"CustomSegmentValueC"]

        
        let metadata = [
            "content" : [String:String](),
            "ad" : [String:String](),
            "static" :  staticObj ] as [String : Any]
        
        let data = [
            "metadata" : metadata,
            "event": "playhead",
            "type": "static",
            "playheadPosition": "0" ] as [String : Any]
        
        return data
    }

//Loading content Data
func loadContent() -> [String : Any] {
    
    url = NSURL(string: "http://www.nielseninternet.com/NielsenConsumer/prog_index.m3u8")
    
    let content = [
        "assetName":"ChromeCast1",
        "assetid":"C77664",
        "length":"3600",
        "program":"MyProgram",
        "segB":"CustomSegmentValueB",
        "segC":"segmentC",
        "title":"S2,E3",
        "type":"content",
        "section":"myApi_app",
        "airdate":"20180120 10:00:00",
        "isfullepisode":"y",
        "adloadtype":"2",
        "channelName":"My Channel 1",
        "pipMode":"false" ]
    
    //Ad data,static data should be empty in content video dictionary
    let metadata = [
        "content" : content,
        "ad" : [String:String](),
        "static" :  [String:String]() ] as [String : Any]
    
    let data = [
        "metadata" : metadata,
        "event": "playhead",
        "type":"content",
        "playheadPosition": "0" ] as [String : Any]
    
    return data

  }
}

ViewController.swift

import UIKit
import AVKit
import CoreLocation
import AdSupport
import AVFoundation
import NielsenAppApi

class ViewController: UIViewController, NielsenEventTrackerDelegate, AVPlayerViewControllerDelegate {
    
    var videoType : Int!
    var player : AVPlayer!
    var playerController : AVPlayerViewController!
    var sdkMethods : SDKMethods!
    var nielsenEventTracker : NielsenEventTracker!
    
    var data : [String : Any]!
    var timeObserver: Any!
    var totalVideosPlayed = 0
    var totalVideos : Int!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //Mark: In NielsenInit class we are initialising the NielsenEventTracker.
        
        //Getting the instance of NielsenEventTracker
        self.nielsenEventTracker = NielsenInit.createEventTracker(delegate: self)
        
        //Mark: In SDKMethods class we wrote methods which creates content,Ad objects
        sdkMethods = SDKMethods()
        
        if(videoType == Constants.onlyContent){
            //loading video content data
            self.data = sdkMethods.loadContent()
        }else{
            //loading Ad data
            self.data = sdkMethods.loadPreRollAd()
        }
        
        setPlayer()
        setPlayHeadPosition()
        
        //Setting observer to know the completion of video
        setVideoFinishObserver()
    }
    
    override func viewDidAppear(_ animated: Bool) {
        //loading static data
        let staticData = sdkMethods.loadStatic()
        
        //sending static data to SDK.
        self.nielsenEventTracker.trackEvent(staticData)
    }
    
    func setPlayer() {
        
        //creating player
        player  = AVPlayer.init(url: sdkMethods.url! as URL)
        playerController = AVPlayerViewController()
        playerController.view.frame = CGRect(x:0 , y:100, width: self.view.frame.width, height: 300)
        playerController.player = player;
        playerController.showsPlaybackControls = true;
        playerController.delegate = self;
        
        //Adding observer to player to track play,pause and reverse
        player.addObserver(self, forKeyPath: "rate", options: NSKeyValueObservingOptions.new, context: nil)
        player.play()
        
        self.addChildViewController(playerController)
        self.view.addSubview(playerController.view)
    }
    
    func setPlayHeadPosition() {
        
        //Setting play head position
        let timeInterval : CMTime = CMTimeMakeWithSeconds(1.0, 10)
        playerController.player?.addPeriodicTimeObserver(forInterval: timeInterval, queue: DispatchQueue.main) {(elapsedTime: CMTime) -> Void in
            
            let time : Float64 = self.playerController.player!.currentTime().seconds;
            let pos = Int64(time);
            let playHeadPos = String(pos)
            
            //updating playHead position in dictionary.
            self.data.updateValue(playHeadPos, forKey: "playheadPosition")
            
            //Sending data dictionary to SDK with updated playHead position.
            self.nielsenEventTracker.trackEvent(self.data)
        }
    }
    
    func setVideoFinishObserver() {
        
        //observer fires on completion of Video
        NotificationCenter.default.addObserver(self, selector: #selector(playerDidFinishPlaying), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: playerController.player?.currentItem)
    }
    
    //rate 0.0 = Video Pause or stopped
    //rate 1.0 = Video played or resumed
    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
        if keyPath == "rate" {
            if let rate = change?[NSKeyValueChangeKey.newKey] as? Float {
                
                if rate == 0.0 {
                    print("Playback stopped")
                    
                    //on video pause, updating event as pause in dictionary
                    self.data.updateValue("pause", forKey: "event")
                    
                    //sending the dictionary to SDK with "pause" event.
                    self.nielsenEventTracker.trackEvent(self.data)
                }
                if rate == 1.0 {
                    print("normal playback")
                    
                    //On Play resume setting event as Playhead
                    self.data.updateValue("playhead", forKey: "event")
                }
            }
        }
    }
    
    override func viewDidDisappear(_ animated: Bool) {
        
        //on moving to other screen, updating event as pause in dictionary
        self.data.updateValue("pause", forKey: "event")
        
        player.rate = 0
        player.pause()
    }
    
    @objc func playerDidFinishPlaying(note: NSNotification) {
        
        self.player?.removeObserver(self, forKeyPath: "rate")
        
        //As 1 video completed playing, incrementing the variable value.
        totalVideosPlayed += 1
        
        if(videoType == Constants.onlyContent || totalVideosPlayed == totalVideos){
            //When content video completes or total videos finishs, let's send complete event to SDK
            sendCompleteEventToSDK()
        }else{
            //On completion of Ad updating "adStop" event to SDK.
            self.data.updateValue("adStop", forKey: "event")
            
            //sending "adStop" event to SDK.
            self.nielsenEventTracker.trackEvent(data)
        }
        
        //Checking if total videos played or not.
        if(totalVideosPlayed != totalVideos){
            
            //Checking if videoType is contentWithOneAd, then after completion of Ad, will play the content video.
            if(videoType == Constants.contentWithOneAd){
                
                //loading video content data
                self.data = sdkMethods.loadContent()
            }else if(videoType == Constants.contentWithTwoAds){
                if(totalVideosPlayed == 1){
                    
                //loading 2nd Ad data
                self.data = sdkMethods.loadMidRollAd()
                }else{

                    //loading video content data
                    self.data = sdkMethods.loadContent()
                }
            }
            setPlayer()
            
            //Adding observer to player to check is buffering finished
            self.timeObserver = player.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: 3), queue: DispatchQueue.main) { [weak self] time in
                
                //checking the video player status
                self?.handlePlayerStatus(time: time)
                self?.setPlayHeadPosition()
                
                //Setting observer to know the completion of video
                self?.setVideoFinishObserver()
                
            }
        }
    }
    
    func handlePlayerStatus(time: CMTime) {
        if player.status == .readyToPlay {
            
            // buffering is finished, setting event as Playhead
            self.data.updateValue("playhead", forKey: "event")
            player.removeTimeObserver(self.timeObserver)
        }
        if player.status == .unknown{
            print("Buffering")
        }
    }
    
    func sendCompleteEventToSDK(){
        
        //onCompletion of video, updating event as complete in dictionary
        self.data.updateValue("complete", forKey: "event")
        
        //sending the dictionary to SDK with "complete" event.
        self.nielsenEventTracker.trackEvent(self.data)
    }
    
    deinit {
        
        print("Remove NotificationCenter Deinit")
        NotificationCenter.default.removeObserver(self)
    }
}

Objective C

iphonescreenshot.png

Objective-C Code Example

Select the below link to download the sample files
Download Project Files

NielsenInit.m

//  NielsenInit.m
//  VideoPlayerAppObjC
// This is sample code of a very basic implementation of the Nielsen 'Simplified API'
// This code is for educational purposes only


#import "NielsenInit.h"
#import <NielsenAppApi/NielsenEventTracker.h>

@implementation NielsenInit

+ (NielsenEventTracker *)createNielsenEventTrackerWithDelegate:(id<NielsenEventTrackerDelegate>)delegate
{
    //Initialising the NielsenEventTracker class by passing app information which returns the instance of NielsenEventTracker.
    
    NSDictionary *appInformation = @{ @"appid": @"PDA7D5EE6-B1B8-4123-9277-2A788BC653CA",
                            @"appversion": @"1.0",
                            @"appname": @"Abdul's Objc Test app",
                            @"sfcode": @"dcr",
                            @"ccode": @"123",
                            @"dma":@"456",
                            @"uoo":@"0",
                            @"nol_devDebug": @"INFO",
                            @"containerId": @"1" };
    
    return [[NielsenEventTracker alloc] initWithAppInfo:appInformation delegate:delegate];
}


@end

NielsenInit.h

#import <Foundation/Foundation.h>

@class NielsenEventTracker;
@protocol NielsenEventTrackerDelegate;

@interface NielsenInit : NSObject

+ (NielsenEventTracker *)createNielsenEventTrackerWithDelegate:(id<NielsenEventTrackerDelegate>)delegate;

@end

SDKMethods.m

#import <Foundation/Foundation.h>
#import "SDKMethods.h"


@implementation SDKMethods

//Loading content Data
- (NSDictionary *)loadContentData
{
    
    self.url = [NSURL URLWithString:@"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerEscapes.mp4"];
    
    NSDictionary *content = @{  @"assetName":@"ChromeCast1",
                                @"assetid":@"C77664",
                                @"length":@"3600",
                                @"program":@"MyProgram",
                                @"segB":@"CustomSegmentValueB",
                                @"segC":@"segmentC",
                                @"title":@"S2,E3",
                                @"type":@"content",
                                @"section":@"cloudApi_app",
                                @"airdate":@"20180120 10:00:00",
                                @"isfullepisode":@"y",
                                @"adloadtype":@"2",
                                @"channelName":@"My Channel 1",
                                @"pipMode":@"false" };
    
    //Ad data,static data should be empty in content video dictionary
    NSDictionary *metadata = @{  @"content" : content,
                               @"ad" : @{},
                               @"static" :  @{} };
    
    NSDictionary *data = @{  @"metadata" : metadata,
                           @"event": @"playhead",
                           @"type": @"content",
                           @"playheadPosition": @"0" };
    
    
    
    return data;
}

//Loading Ad data
- (NSDictionary *)loadPreRollAd
{
    self.url = [NSURL URLWithString:@"http://www.nielseninternet.com/NWCC-3002/prog_index.m3u8"];
    
    //We should pass content dictionary also in Ad video.
    NSDictionary *content = @{  @"assetName":@"ChromeCast1",
                                @"assetid":@"C77664",
                                @"length":@"3600",
                                @"program":@"MyProgram",
                                @"segB":@"CustomSegmentValueB",
                                @"segC":@"segmentC",
                                @"title":@"S2,E3",
                                @"type":@"content",
                                @"section":@"cloudApi_app",
                                @"airdate":@"20180120 10:00:00",
                                @"isfullepisode":@"y",
                                @"adloadtype":@"2",
                                @"channelName":@"My Channel 1",
                                @"pipMode":@"false" };
    
    NSDictionary *ad = @{ @"assetid":@"AD12345",
                          @"title":@"ADTestTitle",
                          @"type":@"preroll",
                          @"length":@"20" };
    
    //static data should be empty in Ad video
    NSDictionary *metadata = @{  @"content" : content,
                                 @"ad" : ad,
                                 @"static" :  @{} };
    
    NSDictionary *data = @{  @"metadata" : metadata,
                             @"event": @"playhead",
                             @"type": @"ad",
                             @"playheadPosition": @"0" };
    
    return data;
}

@end

SDKMethods.h

#import <Foundation/Foundation.h>

@interface SDKMethods : NSObject

@property(nonatomic, strong) NSURL *url;

- (NSDictionary *)loadContentData;
- (NSDictionary *)loadPreRollAd;

@end

ViewController.m

#import "ViewController.h"
#import "NielsenInit.h"
#import "SDKMethods.h"
#import <MediaPlayer/MediaPlayer.h>
#import <AVKit/AVKit.h>
#import "Constants.h"

#import <NielsenAppApi/NielsenEventTracker.h>

NSMutableDictionary *mutableData;
NSDictionary *data;
SDKMethods *sdkMethods;
AVPlayer  *player;
AVPlayerViewController *playerController;
NielsenEventTracker *nielsenEventTracker;

int totalVideosPlayed = 0;
id timeObserver;

@interface ViewController()<AVPlayerViewControllerDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //Mark: In NielsenInit class we are initialising the NielsenEventTracker.
    
    //Getting the instance of NielsenEventTracker
    nielsenEventTracker = [NielsenInit createNielsenEventTrackerWithDelegate:nil];
    
    //Mark: In SDKMethods class we wrote methods which creates content,Ad objects
    sdkMethods = [[SDKMethods alloc] init];
    
    if(self.videoType == onlyContent){
        //loading video content data
       data = [sdkMethods loadContentData];
    }else{
        //loading Ad data
        data = [sdkMethods loadPreRollAd];
    }
    
    //Converting "data" to mutable dictionary as we have to update playhead, event values.
    mutableData =[data mutableCopy];
    
    [self setPlayer];
    [self setPlayHeadPosition];
    
    //Setting observer to know the completion of video
    [self setVideoFinishObserver];
}

-(void) setPlayer {
    
    //creating player
    player = [AVPlayer playerWithURL:[sdkMethods url]];
    playerController = [[AVPlayerViewController alloc] init];
    playerController.view.frame = CGRectMake(0,100,self.view.frame.size.width,300);
    playerController.player = player;
    playerController.showsPlaybackControls = YES;
    playerController.delegate = self;
    
    //Adding observer to player to track play,pause and reverse
    [player addObserver:self
              forKeyPath:@"rate"
                 options:(NSKeyValueObservingOptionNew)
                 context:nil];
    
    [player play];
    
    [self addChildViewController:playerController];
    [self.view addSubview:playerController.view];
}

-(void) setPlayHeadPosition {
    
    //Setting play head position
    CMTime timeInterval = CMTimeMakeWithSeconds(1, 1);
    [player addPeriodicTimeObserverForInterval:(timeInterval) queue:dispatch_get_main_queue() usingBlock:^(CMTime time){
        NSTimeInterval seconds = CMTimeGetSeconds(time);
        NSInteger intSec = seconds;
        NSString* strSec = [NSString stringWithFormat:@"%li", intSec];
        
        //updating playHead position in dictionary.
        [mutableData setValue:strSec forKey:@"playheadPosition"];
        
        //Sending data dictionary to SDK with updated playHead position.
        [nielsenEventTracker trackEvent:mutableData];
    }];
}

- (void) setVideoFinishObserver {
    
    //observer fires on completion of Ad
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying:) name:AVPlayerItemDidPlayToEndTimeNotification object:playerController.player.currentItem];
}

//rate 0.0 = Video Pause or stopped
//rate 1.0 = Video played or resumed
//rate -1.0 = Play reversed/rewind.
- (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context
{
    if (object == player && [keyPath isEqualToString:@"rate"]) {
        NSNumber * newValue = [change objectForKey:NSKeyValueChangeNewKey];
        int intValue = newValue.intValue;
        if(intValue == 0){
            NSLog(@"playback paused");
            
            //on video pause, updating event as pause in dictionary
            [mutableData setValue:@"pause" forKey:@"event"];
            
            //sending the dictionary to SDK with "pause" event.
            [nielsenEventTracker trackEvent:mutableData];
            
        }else if(intValue == 1){
            NSLog(@"Normal playback");
            
            //On Play resume setting event as Playhead
            [mutableData setValue:@"playhead" forKey:@"event"];
            
        }
    }
}

- (void)viewDidDisappear:(BOOL)animated
{
    //on moving to other screen, updating event as pause in dictionary
    [mutableData setValue:@"pause" forKey:@"event"];
    
    //As it is a pause event setting the playheadPosition to empty.
    [mutableData setValue:@"" forKey:@"playheadPosition"];
    
    player.rate = 0;
    [player pause];
    
    [super viewDidDisappear:animated];
}


-(void)itemDidFinishPlaying:(NSNotification *) notification {
    
    [player removeObserver:self forKeyPath:@"rate"];
    
    [self sendCompleteEventToSDK];
    
    //As 1 video completed playing, incrementing the variable value.
    totalVideosPlayed += 1;
    
    //Checking if total videos played or not.
    if(totalVideosPlayed != self.totalVideos){
        
        //Checking if videoType is contentWithAd, then after completion of Ad, will play the content video.
        if(self.videoType == contentWithAd){
            
            //loading video content data
            data = [sdkMethods loadContentData];
            
            mutableData =[data mutableCopy];
            
            [self setPlayer];
            
            //Adding observer to player to check is buffering finished
            CMTime timeInterval = CMTimeMakeWithSeconds(1, 3);
            timeObserver =  [player addPeriodicTimeObserverForInterval:(timeInterval) queue:dispatch_get_main_queue() usingBlock:^(CMTime time){
                
                //checking the video player status
                [self handlePlayerStatus:time];
                [self setPlayHeadPosition];
                //Setting observer to know the completion of video
                [self setVideoFinishObserver];
                
            }];
            
        }
    }
}

- (void) handlePlayerStatus : (CMTime) time {
    
    if(player.status == AVPlayerItemStatusReadyToPlay){
        
        // buffering is finished, setting event as Playhead
        [mutableData setValue:@"playhead" forKey:@"event"];
        [player removeTimeObserver:timeObserver];
    }
}

- (void) sendCompleteEventToSDK {
    
    //onCompletion of video, updating event as complete in dictionary
    [mutableData setValue:@"complete" forKey:@"event"];
    
    //As it is a complete event setting the playheadPosition to empty.
    [mutableData setValue:@"" forKey:@"playheadPosition"];
    
    //sending the dictionary to SDK with "complete" event.
    [nielsenEventTracker trackEvent:mutableData];
}

- (void)dealloc {
    NSLog(@"Remove NotificationCenter dealloc");
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end

ViewController.h

#import <UIKit/UIKit.h>

@class NielsenEventTracker;
@protocol NielsenEventTrackerDelegate;


@interface ViewController : UIViewController

@property (nonatomic) int videoType;
@property (nonatomic) int totalVideos;

@end

OptOutVC.m

#import "OptOutVC.h"
#import "NielsenInit.h"


#import <NielsenAppApi/NielsenEventTracker.h>

@interface OptOutVC ()

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

@end

@implementation OptOutVC

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

@end

OptOutVC.h

#import <UIKit/UIKit.h>

@class NielsenEventTracker;
@protocol NielsenEventTrackerDelegate;

@interface OptOutVC : UIViewController

@property (nonatomic, weak) NielsenEventTracker *nielsenEventTracker;

@end