DCR Poland Video iOS SDK: Difference between revisions
From Engineering Client Portal
| Line 536: | Line 536: | ||
After the application is ready to be sent for Nielsen Certification, please go through the [[Digital Pre-Certification Checklist App SDK]] and ensure the app behaves as expected, before submitting to Nielsen. | After the application is ready to be sent for Nielsen Certification, please go through the [[Digital Pre-Certification Checklist App SDK]] and ensure the app behaves as expected, before submitting to Nielsen. | ||
== Privacy | == Step 7 : Disclose Nielsen Privacy Statement == | ||
The App SDK uses Mobile Ad IDs (Android ID or IDFA) which are fully hashed on the device before being sent to Nielsen (Nielsen never receives un-hashed values). | |||
Users retain the possibility to oppose the use of Mobile Ad IDs, or to reset them, by using the functionality provided by the mobile operating system (iOS or Android). | |||
In order to disclose Nielsen measurement privacy statement, please include the following items in your privacy policy: | |||
* A notice that the player includes third party measurement software that allows users to contribute to market research. | |||
* A link to the Nielsen Digital Measurement Privacy Policy located at https://www.nielsen.com/legal/privacy-principles/digital-measurement-privacy-statement/ . | |||
=== Initialization of the SDK based on User Consent in your App === | |||
In collaboration with Mediametrie, the following user consent use cases need to be implemented in your App. | |||
==== The user explicitly accepts measurement ==== | |||
The SDK is initialized and all IDs are captured. The SDK Opt-in Flags have to be set accordingly, see: | |||
* [[#User opted in|User opted in]] | |||
* | * [[#First Party ID turned on|First Party ID turned on]] | ||
* | |||
==== | ==== The user explicitly refuses measurement ==== | ||
The SDK is NOT initialized and No Nielsen SDK measurement will occur. | |||
==== The user did not explicitly give consent for the measurement(consent neither given nor refused) ==== | |||
The SDK is initialized and no IDs are captured. The SDK Opt-out Flags have to be set accordingly, see: | |||
* [[#User opted out|User opted out]] | |||
* [[#First Party ID turned off|First Party ID turned off]] | |||
=== Turning off the First Party ID for Opt-out Users during the SDK Initializazion === | |||
The First Party ID(FPID) is enabled by default in the Browser SDK. For Opt-out users, the First Party ID can be turned off during the initialization of the SDK Instance, i.e. the parameter enableFpid can be set to "false" (FPID disabled) or "true" (FPID enabled). | |||
==== Example of SDK Initialization with enableFpid ==== | |||
===== First Party ID turned on ===== | |||
====== Using Objective-C ====== | |||
<syntaxhighlight lang="objective-c"> | |||
#import "NlsAppApiFactory.h" | |||
#import <NielsenAppApi/NielsenAppApi.h> | |||
@implementation NlsAppApiFactory | |||
+ (NielsenAppApi *)createNielsenAppApiWithDelegate:(id<NielsenAppApiDelegate>)delegate; | |||
{ | |||
NSDictionary *appInformation = @{ | |||
@"appid": @"PXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", | |||
@"enableFpid": @"true" | |||
}; | |||
return [[NielsenAppApi alloc] initWithAppInfo:appInformation delegate:delegate]; | |||
} | } | ||
@end | |||
</syntaxhighlight> | </syntaxhighlight> | ||
The following would be the <code>NlsAppApiFactory.h</code> file: | |||
<syntaxhighlight lang="objective-c"> | |||
#import <Foundation/Foundation.h> | |||
@class NielsenAppApi; | |||
@protocol NielsenAppApiDeligate; | |||
@interface NlsAppApiFactory : NSObject | |||
+ (NielsenAppAPI *) createNielsenAppApiWithDelegate:(id<NielsenAppApiDelegate>)delegate; | |||
@end | |||
</syntaxhighlight> | |||
====== Using Swift ====== | |||
<code>NielsenInit.swift</code> | |||
<syntaxhighlight lang="swift"> | |||
class NielsenInit: NSObject { | |||
class func createNielsenAppApi(delegate: NielsenAppApiDelegate) -> NielsenAppApi?{ | |||
let appInformation:[String: String] = [ | |||
"appid": "PXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", | |||
"enableFpid": "true" | |||
] | |||
return NielsenAppApi(appInfo:appInformation, delegate:delegate) | |||
} | } | ||
} | |||
</syntaxhighlight>> | |||
===== First Party ID turned off ===== | |||
====== Using Objective-C ====== | |||
<syntaxhighlight lang="objective-c"> | |||
#import "NlsAppApiFactory.h" | |||
#import <NielsenAppApi/NielsenAppApi.h> | |||
@implementation NlsAppApiFactory | |||
+ (NielsenAppApi *)createNielsenAppApiWithDelegate:(id<NielsenAppApiDelegate>)delegate; | |||
{ | |||
NSDictionary *appInformation = @{ | |||
@"appid": @"PXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", | |||
@"enableFpid": @"false" | |||
}; | |||
return [[NielsenAppApi alloc] initWithAppInfo:appInformation delegate:delegate]; | |||
} | |||
@end | |||
</syntaxhighlight> | </syntaxhighlight> | ||
The following would be the <code>NlsAppApiFactory.h</code> file: | |||
<syntaxhighlight lang="objective-c"> | |||
#import <Foundation/Foundation.h> | |||
@class NielsenAppApi; | |||
@protocol NielsenAppApiDeligate; | |||
@interface NlsAppApiFactory : NSObject | |||
+ (NielsenAppAPI *) createNielsenAppApiWithDelegate:(id<NielsenAppApiDelegate>)delegate; | |||
@end | |||
</syntaxhighlight> | |||
====== Using Swift ====== | |||
<code>NielsenInit.swift</code> | |||
<syntaxhighlight lang="swift"> | <syntaxhighlight lang="swift"> | ||
class NielsenInit : NSObject { | class NielsenInit: NSObject { | ||
class func | class func createNielsenAppApi(delegate: NielsenAppApiDelegate) -> NielsenAppApi?{ | ||
let appInformation:[String: String] = [ | |||
"appid": "PXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", | |||
"enableFpid": "false" | |||
] | |||
] | |||
return NielsenAppApi(appInfo:appInformation, delegate:delegate) | return NielsenAppApi(appInfo:appInformation, delegate:delegate) | ||
} | } | ||
| Line 626: | Line 665: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== | === Setting the SDK global optout Flag for Opt-out Users === | ||
The Optout Flag is set by default to "false" in the AppSDK. | |||
For Opt-out users, the Optout Flag can be set accordingly while Initializing the SDK Instance. | |||
* <blockquote>'''Ad flavour of AppSDK''': <pre style="color: red">The Ad flavour of AppSDK should be downloaded for the french market! The AppSDK Version 10.1.0.0 or higher must be downloaded</pre> | |||
==== Example the Ouptout Flag ==== | |||
==== | ===== User opted out ===== | ||
====== Using Objective-C ====== | |||
<syntaxhighlight lang="objective-c"> | |||
#import "NlsAppApiFactory.h" | |||
#import <NielsenAppApi/NielsenAppApi.h> | |||
@implementation NlsAppApiFactory | |||
+ (NielsenAppApi *)createNielsenAppApiWithDelegate:(id<NielsenAppApiDelegate>)delegate; | |||
{ | |||
NSDictionary *appInformation = @{ | |||
@"appid": @"PXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", | |||
@"optout": @"true" | |||
}; | |||
return [[NielsenAppApi alloc] initWithAppInfo:appInformation delegate:delegate]; | |||
} | |||
@end | |||
</syntaxhighlight> | |||
The following would be the <code>NlsAppApiFactory.h</code> file: | |||
<syntaxhighlight lang="objective-c"> | |||
#import <Foundation/Foundation.h> | |||
@class NielsenAppApi; | |||
@protocol NielsenAppApiDeligate; | |||
@interface NlsAppApiFactory : NSObject | |||
+ (NielsenAppAPI *) createNielsenAppApiWithDelegate:(id<NielsenAppApiDelegate>)delegate; | |||
@end | |||
</syntaxhighlight> | </syntaxhighlight> | ||
====== Using Swift ====== | |||
<code>NielsenInit.swift</code> | |||
<syntaxhighlight lang="swift"> | |||
class NielsenInit: NSObject { | |||
class func createNielsenAppApi(delegate: NielsenAppApiDelegate) -> NielsenAppApi?{ | |||
let appInformation:[String: String] = [ | |||
"appid": "PXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", | |||
"optout": "true" | |||
] | |||
return NielsenAppApi(appInfo:appInformation, delegate:delegate) | |||
} | } | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== | ===== User opted in ===== | ||
====== Using Objective-C ====== | |||
<syntaxhighlight lang="objective-c"> | |||
#import "NlsAppApiFactory.h" | |||
#import <NielsenAppApi/NielsenAppApi.h> | |||
@implementation NlsAppApiFactory | |||
+ (NielsenAppApi *)createNielsenAppApiWithDelegate:(id<NielsenAppApiDelegate>)delegate; | |||
{ | { | ||
NSDictionary *appInformation = @{ | |||
@"appid": @"PXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", | |||
@"optout": @"false" | |||
}; | |||
return [[NielsenAppApi alloc] initWithAppInfo:appInformation delegate:delegate]; | |||
} | |||
@end | |||
return | </syntaxhighlight> | ||
}</syntaxhighlight> | |||
The following would be the <code>NlsAppApiFactory.h</code> file: | |||
<syntaxhighlight lang="objective-c"> | |||
#import <Foundation/Foundation.h> | |||
@class NielsenAppApi; | |||
@protocol NielsenAppApiDeligate; | |||
@interface NlsAppApiFactory : NSObject | |||
+ (NielsenAppAPI *) createNielsenAppApiWithDelegate:(id<NielsenAppApiDelegate>)delegate; | |||
@end | |||
</syntaxhighlight> | |||
return NielsenAppApi | |||
====== Using Swift ====== | |||
<code>NielsenInit.swift</code> | |||
<syntaxhighlight lang="swift"> | |||
class NielsenInit: NSObject { | |||
class func createNielsenAppApi(delegate: NielsenAppApiDelegate) -> NielsenAppApi?{ | |||
let appInformation:[String: String] = [ | |||
"appid": "PXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", | |||
"optout": "false" | |||
] | |||
return NielsenAppApi(appInfo:appInformation, delegate:delegate) | |||
} | } | ||
} | |||
</syntaxhighlight> | </syntaxhighlight> | ||
== AirPlay == | == AirPlay == | ||
Revision as of 15:35, 16 February 2026
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), and 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
Prerequisites
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. | Contact Nielsen |
| ☑ | Nielsen SDK | Includes SDK frameworks and sample implementation; See iOS SDK Release Notes | Download |
If you do not have any of these pre-requisites 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.
Implementation
This guide covers implementation steps for iOS using Xcode utilizing the Standard Nielsen SDK for DCR.
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.
- Select to obtain CocoaPods implementation guide
- Select to Download Directly
- Using the XCFramework bundle
Special Notes regarding iOS14
Permission to Track
Apple recently released a new policy on consent requirements, that require the user's permission, to track them using their device's advertising identifier (IDFA). To request the user's permission, use the AppTrackingTransparency framework.
For more information, see:
More detailed information on how the Nielsen SDK versions work with the AppTrackingTransparency framework is located on our DCR Video iOS14 Migration page.
Special Notes regarding iOS17
Beginning with iOS/tvOS 17, Apple is adding several requirements for App developers around tracking, use of Identifier For Advertisers (IDFA), and certain system APIs as detailed below:
Do not declare the Nielsen imrworldwide.com domain in the privacy manifest.
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 below.
XCFramework is solution for the problems described above Apple recommends to use XCFrameworks. In XCFramework, we no longer build a single framework with multiple architectures. Instead, we build one small framework for each combination of architecture and target and store it in its own folder. The top-level XCFramework folder have folders like ios-arm64, ios-arm64-simulator, etc. Each of these folders is its own framework, complete with headers, modules, and binary.
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.
Special Note for Static Framework
Starting from 8.2.0.0 release framework is build from the mixed (swift + objc) source code. If static (xc)framework is integrated additional settings should be applied to fix build or runtime issues.
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;
xCode 12 building errors
Developers who uses "fat" framework in their apps started reporting the following error that they get building the app in xCode 12.3+:
Building for iOS Simulator, but the linked and embedded framework 'MyFramework.framework' was built for iOS + iOS Simulator.
The binary framework contains different code for the same architecture in multiple places, and Xcode doesn’t know how to handle it. There is workaround that people recommend to use in such cases:
- https://stackoverflow.com/questions/63267897/building-for-ios-simulator-but-the-linked-framework-framework-was-built
- https://stackoverflow.com/questions/63932158/xcode12-issus-ld-building-for-ios-simulator-but-linking-in-object-file-built
IPA processing failure
Assertion failed: Expected 4 archs in otool output:
The error above is due to the "fat" (simulator+device) framework which will not appear if you have not enabled Bitcode. To build your app with full Bitcode support, it is recommended that you use a XCFramework to avoid the 4 archs in otool output message.
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 id for the application assigned by Nielsen. It is GUID data type. | Nielsen-specified | Yes | PXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX |
| nol_devDebug | Enables Nielsen console logging. Only required for testing | Nielsen-specified | Optional | "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":@"INFO", 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: DO NOT activate the Debug flag in a production environment.
Sample SDK Initialization Code
Swift
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",
"nol_devDebug": "DEBUG"
]
return NielsenAppApi(appInfo:appInformation, delegate:delegate)
}
}
Sample code using AVPlayer.
ViewController.swift
class ViewController: UIViewController, NielsenAppApiDelegate, AVPlayerViewControllerDelegate {
// your code//
override func viewDidLoad() {
super.viewDidLoad()
//Getting the instance of NielsenApi
self.nielsenApi = NielsenInit.createNielsenApi(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.
#import "NielsenInit.h"
#import <NielsenAppApi/NielsenAppApi.h>
@implementation NielsenInit
+ (NielsenAppApi *)createNielsenAppApiWithDelegate:(id<NielsenAppApiDelegate>)delegate
{
NSDictionary *appInformation = @{ @"appid": @"PDA7D5EE6-B1B8-4123-9277-2A788XXXXXXX",
@"nol_devDebug": @"DEBUG", };
return [[NielsenAppApi alloc] initWithAppInfo:appInformation delegate:delegate];
}
@end
The following would be the NielsenInit.h file:
#import <Foundation/Foundation.h>
@class NielsenAppApi;
@protocol NielsenAppApiDelegate;
@interface NielsenInit : NSObject
+ (NielsenAppApi *)createNielsenAppApiWithDelegate:(id<NielsenAppApiDelegate>)delegate;
@end
Sample Code:
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//Getting the instance of Nielsen SDK
nielsenApi = [NielsenInit createNielsenAppApiWithDelegate:nil];
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.
Configure Payload
Handling JSON Metadata
All the SDK methods handles only two types of objects: NSString, NSDictionary. The parameters passed must be either a JSON formatted string or a NSDictionary object. The JSON passed in the SDK must be well-formed.
- NSDictionary object
- If an object of unexpected type is passed to the method, the error message will be logged.
- If string has invalid JSON format, the error message will be logged.
- JSON value must be string value.
- This includes boolean and numeric values. For example, a value of true should be represented with "true", number value 123 should be "123".
- All the Variable Names like appid, appname, dataSrc, title, type etc. are case-sensitive. Use the correct variable name as specified in the documentation.
- JSON string can be prepared using either raw NSString or serialized NSDictionary.
Swift
let channelInfo = [
"channelName": "My Channel Name 1",
];
let contentMetadata = [
"type": "content",
"assetid": "C77664",
"title": "Program S2, E3",
"isfullepisode": "Yes",
"program": "Program Name",
"length": "3600",
"airdate": "20171020 10:05:00",
"adloadtype": "2"
];
Objective C
NSDictionary * channelInfo = @ {
@ "channelName": @ "My Channel Name 1",
}
NSDictionary * contentMetadata = @ {
@ "type": @ "content",
@ "assetid": @ "C77664",
@ "title": @ "S2,E3",
@ "isfullepisode": @ "y",
@ "program": @ "Program Name",
@ "length": @ "3600",
@ "airdate": @ "20180120 10:00:00",
@ "adloadtype": @ "2"
}
ChannelName metadata
channelName should remain constant throughout the completion of an episode or live stream.
| Key | Description | Values | Required |
|---|---|---|---|
| channelName | ChannelInfo refers to the Channel name. This can be a free-form value
value such as a friendly name for the content being played. the SDK |
custom | No |
Content Metadata
Content metadata should remain constant throughout the entirety of an episode / clip including when ads play.
| Key | Description | Values | Required |
|---|---|---|---|
| type | type of asset | "content" | ✓ |
| assetid | unique ID assigned to asset (max 64 characters; only characters 0-9, a-z, A-Z underscore and minus are allowed - no special characters or vowel mutations) | custom (no Special Characters) | ✓ |
| program | (string) name of program (max 254 characters) | custom | ✓ |
| title | (string) episode title (max 254 characters) | custom - no backslash allowed in string (because of 3rd party data processing) | ✓ |
| length | (int) length of content in seconds | 86400 seconds for live stream. For Event-Livestreams planned length. For VoD video length | ✓ |
| airdate | The airdate in the linear TV. Original (local) air date and time (hh:mm:ss as 24h time stamp); if not known set it to eg. "19700101 00:00:00" | YYYYMMDD HH:MI:SS |
✓ |
| isfullepisode | full episode flag | "y"- full episode, "n"- non full episode | ✓ |
| adloadtype | type of ad load:
|
"2" - DCR measures content with dynamic ads |
✓ |
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 | Required |
|---|---|---|---|
| type | type of ad | 'preroll', 'midroll', 'postroll' |
✓ |
| assetid | unique ID assigned to ad | custom (no Special Characters) |
✓ |
Example Ad Object
Swift
let adMetadata = [
"type": "preroll",
"assetid": "123456"
];
Objective C
NSDictionary * adMetadata = @ {
@ "type": @ "preroll",
@ "assetid": @ "AD-ID123"
}
Nielsen API Documentation
play
Use play to pass the channel descriptor information through channelName parameter when the user taps the Play button on the player. Pass in channelName metadata as described above.
Swift
nielsenApi?.play(channelInfo);
Objective C
[nielsenApi play:([NSDictionary *channel loadChannelInfo)];
loadMetadata
Call to inform SDK about asset being played. Pass in metadata as described here #Configure Payload, #Content Metadata
Swift
nielsenApi?.loadMetadata(contentMetadata)
Objective C
[nielsenApi loadMetadata:(contentMetadata)];
playheadPosition
Call to inform Nielsen SDK about position in video asset (for VOD pass second within video, for livestreams UTC timestamp in seconds).
Swift
nielsenApi?.playheadPosition(secondsAsInt)
Objective C
[nielsenApi playheadPosition:secondsAsInt];
stop
Call to indicate interruption during playback, e.g. pause. (more on interruption scenarios here: #Interruptions during playback )
Swift
nielsenApi?.stop()
Objective C
[nielsenApi stop];
end
Call when content finished playback and content cannot be resumed from the same position (it can only be restarted from the beginning of stream).
Swift
nielsenApi?.end()
Objective C
[nielsenApi end];
Call Nielsen APIs
Sample API Sequence
A Sample API sequence could follow this flow:
| Type | Sample code | Description |
|---|---|---|
| On App Start | nielsenApi = NielsenInit.createNielsenApi(delegate: self);
data = loadStaticMetadata();
nielsenApi.loadMetadata(self.data);
|
// Pass Static Metadata here if applicable |
| Start of stream | nielsenApi.play(channelName) |
// channelName now automatically generated by Nielsen SDK |
nielsenApi.loadMetadata(contentMetadata) |
// MetadataObject contains the JSON metadata for the content being played | |
| Content | nielsenApi.playheadPosition(pos); |
// playheadPosition is position of the playhead while the content is being played |
| End of Stream | nielsenApi.end() |
// Content playback is completed. |
Life cycle of SDK instance
Life cycle of SDK instance includes four general states:
- Initial state – The SDK is not initialized and hence, not ready to process playing information. Once the SDK is moved out of this state, it needs instantiation of the new SDK instance in order to get the instance in the Idle state.
- Idle state – The SDK is initialized and is ready to process playing information. Once Initialized, the SDK instance is not processing any data, but is listening for an event to occur.
- Processing state – The SDK instance is processing playing information. The
playandloadMetadatacalls move the SDK instance into this state. In this state, the SDK instance will be able to process the following calls.playheadPosition– Call this API every one second when playhead position is active. If a LIVE event, use the current UNIX timestamp (seconds since Jan-1-1970 UTC).stop– Call this API when the playback is paused, switches between content and ad (within the same content playback) or encounters interruptions.end– SDK instance exits from Processing state when this API is called.
- Disabled state – The SDK instance is disabled and is not processing playing information.
appDisableApiis set totrue
Note: For API Version 5.1 and above, App SDK will fire data pings and continue measurement even after the user has opted out from Nielsen measurement on a device. The data ping will be marked as opted-out ping.
Note: In case of any interruptions during playback due to alarm, calendar, call, flight mode, Wi-Fi toggle, channel change, etc., call stop to stop the measurement.
- As soon as the playback resumes, call
play,loadMetadataandplayheadPosition
API Call Sequence
Use Case 1: Content has no Advertisements
Call play() with channelName JSON as below.
{
"channelName": "TheMovieTitle"
}
Call loadMetadata() with JSON metadata for content as below.
{
"type": "content",
"assetid": "vid345-67483",
"program": "ProgramName",
"title": "Program S3, EP1",
"length": "3600",
...
}
Call playheadPosition() every one second until a pause / stop. Use the sample API sequence below as a reference to identify the specific events that need to be called during content playback without ads.
| Type | Sample code | Description |
|---|---|---|
| Start of stream | nielsenApi.play(channelName); |
// channelName now automatically generated by Nielsen SDK |
nielsenApi.loadMetadata(contentMetaDataObject); |
// contentMetadataObject contains the JSON metadata for the content being played | |
| Content | nielsenApi.playheadPosition(playheadPosition); |
// position is position of the playhead while the content is being played |
| End of Stream | nielsenApi.end(); |
// Content playback is completed. |
Use Case 2: Content has Advertisements
Call play() with channelName JSON as below.
{
"channelName": "TheMovieTitle"
}
Call loadMetadata() with JSON metadata for ad as below.
{
"type": "preroll",
"assetid": "ad=123"
}
Note: In case the individual ad details are not available, send ad pod (presence) details through the loadMetadata and playhead position through playheadPosition.
Call playheadPosition() every one second until a pause / stop / another loadMetadata() is called. Playhead should be passed for the entire duration of ad pod, if the ad pod details are passed as part of loadMetadata().
The sample API sequence can be used as a reference to identify the specific events that need to be called during content and ad playback.
| Type | Sample code | Description |
|---|---|---|
| Start of stream | nielsenApi.play(channelName); |
// channelName now automatically generated by Nielsen SDK |
nielsenApi.loadMetadata(contentMetaDataObject); |
// contentMetadataObject contains the JSON metadata for the content being played | |
| Preroll | nielsenApi.loadMetadata(prerollMetadataObject); |
// prerollMetadataObject contains the JSON metadata for the preroll ad |
nielsenApi.playheadPosition(playheadPosition); |
// position is position of the playhead while the preroll ad is being played | |
nielsenApi.stop(); |
// Call stop after preroll occurs | |
| Content | nielsenApi.loadMetadata(contentMetaDataObject); |
// contentMetadataObject contains the JSON metadata for the content being played |
nielsenApi.playheadPosition(playheadPosition); |
// position is position of the playhead while the content is being played | |
nielsenApi.stop(); |
// Call stop after the content is paused (ad starts) | |
| Midroll | nielsenApi.loadMetadata(midrollMetaDataObject); |
// midrollMetadataObject contains the JSON metadata for the midroll ad |
nielsenApi.playheadPosition(playheadPosition); |
// position is position of the playhead while the midroll ad is being played | |
nielsenApi.stop(); |
// App moves to background(midroll pauses) | |
nielsenApi.loadMetadata(midrollMetaDataObject); |
// App moves to foreground (midroll resumes) | |
nielsenApi.playheadPosition(playheadPosition); |
// playheadPosition is position of the playhead while the midroll ad is being played | |
nielsenApi.stop(); |
// Call stop after midroll occurs | |
| Content (End of stream) | nielsenApi.loadMetadata(contentMetaDataObject); |
// contentMetadataObject contains the JSON metadata for the content being played |
nielsenApi.playheadPosition(playheadPosition); |
// position is position of the playhead while the content is being played | |
nielsenApi.stop(); |
// Always call stop irrespective of postroll is followed or not | |
| End of Stream | nielsenApi.end(); |
// Call end() at the end of content |
| Postroll | nielsenApi.loadMetadata(postrollMetaDataObject); |
// postrollMetadataObject contains the JSON metadata for the postroll ad |
nielsenApi.playheadPosition(playheadPosition); |
// position is position of the playhead while the postroll ad is being played | |
nielsenApi.stop(); |
// Call stop after postroll occurs |
Note: Each Ad playhead should begin from 0 at ad start. When content has resumed following an ad break, playhead position must continue from where previous content segment was left off.
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.
Interruptions during playback
As part of integrating Nielsen App SDK with the player application, the Audio / Video app developer needs to handle the following possible interruption scenarios:
- Pause / Play
- Network Loss (Wi-Fi / Airplane / Cellular)
- Call Interrupt (SIM or Third party Skype / Hangout call)
- Alarm Interrupt
- Content Buffering
- Device Lock / Unlock (Video players only, not for Audio players)
- App going in the Background/Foreground (Video players only, not for Audio players)
- Channel / Station Change Scenario
- Unplugging of headphone
In case of encountering one of the above interruptions, the player application needs to
- Call stop immediately and withhold sending playhead position.
- Start sending API calls –
'loadMetadata'and'playheadPosition'for the current viewing session, once the playback resumes.
Please see the Interruption Scenarios Page for more details
Pre-Certification Checklists
After the application is ready to be sent for Nielsen Certification, please go through the Digital Pre-Certification Checklist App SDK and ensure the app behaves as expected, before submitting to Nielsen.
Step 7 : Disclose Nielsen Privacy Statement
The App SDK uses Mobile Ad IDs (Android ID or IDFA) which are fully hashed on the device before being sent to Nielsen (Nielsen never receives un-hashed values). Users retain the possibility to oppose the use of Mobile Ad IDs, or to reset them, by using the functionality provided by the mobile operating system (iOS or Android).
In order to disclose Nielsen measurement privacy statement, please include the following items in your privacy policy:
- A notice that the player includes third party measurement software that allows users to contribute to market research.
- A link to the Nielsen Digital Measurement Privacy Policy located at https://www.nielsen.com/legal/privacy-principles/digital-measurement-privacy-statement/ .
Initialization of the SDK based on User Consent in your App
In collaboration with Mediametrie, the following user consent use cases need to be implemented in your App.
The user explicitly accepts measurement
The SDK is initialized and all IDs are captured. The SDK Opt-in Flags have to be set accordingly, see:
The user explicitly refuses measurement
The SDK is NOT initialized and No Nielsen SDK measurement will occur.
The user did not explicitly give consent for the measurement(consent neither given nor refused)
The SDK is initialized and no IDs are captured. The SDK Opt-out Flags have to be set accordingly, see:
Turning off the First Party ID for Opt-out Users during the SDK Initializazion
The First Party ID(FPID) is enabled by default in the Browser SDK. For Opt-out users, the First Party ID can be turned off during the initialization of the SDK Instance, i.e. the parameter enableFpid can be set to "false" (FPID disabled) or "true" (FPID enabled).
Example of SDK Initialization with enableFpid
First Party ID turned on
Using Objective-C
#import "NlsAppApiFactory.h"
#import <NielsenAppApi/NielsenAppApi.h>
@implementation NlsAppApiFactory
+ (NielsenAppApi *)createNielsenAppApiWithDelegate:(id<NielsenAppApiDelegate>)delegate;
{
NSDictionary *appInformation = @{
@"appid": @"PXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
@"enableFpid": @"true"
};
return [[NielsenAppApi alloc] initWithAppInfo:appInformation delegate:delegate];
}
@end
The following would be the NlsAppApiFactory.h file:
#import <Foundation/Foundation.h>
@class NielsenAppApi;
@protocol NielsenAppApiDeligate;
@interface NlsAppApiFactory : NSObject
+ (NielsenAppAPI *) createNielsenAppApiWithDelegate:(id<NielsenAppApiDelegate>)delegate;
@end
Using Swift
NielsenInit.swift
class NielsenInit: NSObject {
class func createNielsenAppApi(delegate: NielsenAppApiDelegate) -> NielsenAppApi?{
let appInformation:[String: String] = [
"appid": "PXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"enableFpid": "true"
]
return NielsenAppApi(appInfo:appInformation, delegate:delegate)
}
}
>
First Party ID turned off
Using Objective-C
#import "NlsAppApiFactory.h"
#import <NielsenAppApi/NielsenAppApi.h>
@implementation NlsAppApiFactory
+ (NielsenAppApi *)createNielsenAppApiWithDelegate:(id<NielsenAppApiDelegate>)delegate;
{
NSDictionary *appInformation = @{
@"appid": @"PXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
@"enableFpid": @"false"
};
return [[NielsenAppApi alloc] initWithAppInfo:appInformation delegate:delegate];
}
@end
The following would be the NlsAppApiFactory.h file:
#import <Foundation/Foundation.h>
@class NielsenAppApi;
@protocol NielsenAppApiDeligate;
@interface NlsAppApiFactory : NSObject
+ (NielsenAppAPI *) createNielsenAppApiWithDelegate:(id<NielsenAppApiDelegate>)delegate;
@end
Using Swift
NielsenInit.swift
class NielsenInit: NSObject {
class func createNielsenAppApi(delegate: NielsenAppApiDelegate) -> NielsenAppApi?{
let appInformation:[String: String] = [
"appid": "PXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"enableFpid": "false"
]
return NielsenAppApi(appInfo:appInformation, delegate:delegate)
}
}
Setting the SDK global optout Flag for Opt-out Users
The Optout Flag is set by default to "false" in the AppSDK.
For Opt-out users, the Optout Flag can be set accordingly while Initializing the SDK Instance.
Ad flavour of AppSDK:
The Ad flavour of AppSDK should be downloaded for the french market! The AppSDK Version 10.1.0.0 or higher must be downloaded
Example the Ouptout Flag
User opted out
Using Objective-C
#import "NlsAppApiFactory.h"
#import <NielsenAppApi/NielsenAppApi.h>
@implementation NlsAppApiFactory
+ (NielsenAppApi *)createNielsenAppApiWithDelegate:(id<NielsenAppApiDelegate>)delegate;
{
NSDictionary *appInformation = @{
@"appid": @"PXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
@"optout": @"true"
};
return [[NielsenAppApi alloc] initWithAppInfo:appInformation delegate:delegate];
}
@end
The following would be the NlsAppApiFactory.h file:
#import <Foundation/Foundation.h>
@class NielsenAppApi;
@protocol NielsenAppApiDeligate;
@interface NlsAppApiFactory : NSObject
+ (NielsenAppAPI *) createNielsenAppApiWithDelegate:(id<NielsenAppApiDelegate>)delegate;
@end
Using Swift
NielsenInit.swift
class NielsenInit: NSObject {
class func createNielsenAppApi(delegate: NielsenAppApiDelegate) -> NielsenAppApi?{
let appInformation:[String: String] = [
"appid": "PXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"optout": "true"
]
return NielsenAppApi(appInfo:appInformation, delegate:delegate)
}
}
User opted in
Using Objective-C
#import "NlsAppApiFactory.h"
#import <NielsenAppApi/NielsenAppApi.h>
@implementation NlsAppApiFactory
+ (NielsenAppApi *)createNielsenAppApiWithDelegate:(id<NielsenAppApiDelegate>)delegate;
{
NSDictionary *appInformation = @{
@"appid": @"PXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
@"optout": @"false"
};
return [[NielsenAppApi alloc] initWithAppInfo:appInformation delegate:delegate];
}
@end
The following would be the NlsAppApiFactory.h file:
#import <Foundation/Foundation.h>
@class NielsenAppApi;
@protocol NielsenAppApiDeligate;
@interface NlsAppApiFactory : NSObject
+ (NielsenAppAPI *) createNielsenAppApiWithDelegate:(id<NielsenAppApiDelegate>)delegate;
@end
Using Swift
NielsenInit.swift
class NielsenInit: NSObject {
class func createNielsenAppApi(delegate: NielsenAppApiDelegate) -> NielsenAppApi?{
let appInformation:[String: String] = [
"appid": "PXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"optout": "false"
]
return NielsenAppApi(appInfo:appInformation, delegate:delegate)
}
}
AirPlay
To implement OTT measurement, report OTT changes to the SDK using public API interface: updateOTT
In order to detect AirPlay and mirroring changes we use AVAudioSessionPortDescription properties that are different on different iOS versions. We found that on iOS versions 8 - 10 AVAudioSessionPortDescription has the following values:
AirPlay: type = AirPlay; name = Apple TV 4K; UID = DC:56:E7:53:72:85-airplay
Mirroring: type = AirPlay; name = Apple TV 4K; UID = DC:56:E7:53:72:85-screen
For iOS 11+ some parameters like name and UID have different values:
AirPlay: type = AirPlay; name = AirPlay; UID = 0eb63aae-5915-45f1-b0f7-0102a0e50d53
Mirroring: type = AirPlay; name = Apple TV 4K; UID = 4335E8A9-1C0A-4251-9000-28CA5FA2F3CF-192731714653291-screen
The following code snipped is suggested for AirPlay / mirroring detection on iOS devices.
Swift
nielsenSdk.updateOTT(currentStatus)
Subscribe to AVAudioSessionRouteChangeNotification
NotificationCenter.default.addObserver(self, selector: #selector(handleRouteChanged(_:)), name: NSNotification.Name.AVAudioSessionRouteChange, object: nil)
Handle AVAudioSessionRouteChangeNotification and prepare OTT dictionary:
func handleRouteChanged(_ notification: Notification) {
var currentStatus: [String: String] = ["ottStatus": "0"]
let session = AVAudioSession.sharedInstance()
let currentRoute = session.currentRoute
for outputPort in currentRoute.outputs {
if outputPort.portType == AVAudioSessionPortAirPlay {
currentStatus["ottStatus"] = "1"
currentStatus["ottDeviceModel"] = outputPort.portName
currentStatus["ottDeviceID"] = outputPort.uid
if outputPort.portName == "AirPlay" {
currentStatus["ottDevice"] = "airplay"
currentStatus["ottType"] = "airplay"
}
else {
if outputPort.portName.contains("Apple TV") {
currentStatus["ottDevice"] = "appleTV"
}
else {
currentStatus["ottDevice"] = "other"
}
if outputPort.uid.hasSuffix("airplay") {
currentStatus["ottType"] = "airplay"
}
else if outputPort.uid.hasSuffix("screen") {
currentStatus["ottType"] = "mirroring"
}
else {
currentStatus["ottType"] = "other"
}
}
}
}
// report OTT status update to Nielsen SDK
self.reportOTTUpdate(currentStatus)
}
Report OTT update to the Nielsen SDK
func reportOTTUpdate(_ ottDict: [String: String]) {
if let nielsenSdk = self.nielsenAppApi {
nielsenSdk.updateOTT(currentStatus)
}
}
Objective C
– (void)updateOTT:(id)ottInfo;
Subscribe to AVAudioSessionRouteChangeNotification
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleRouteChanged:) name:AVAudioSessionRouteChangeNotification object:nil];
Handle AVAudioSessionRouteChangeNotification and prepare OTT dictionary:
- (void)handleRouteChanged:(NSNotification *)notification
{
NSMutableDictionary *ottDict = [NSMutableDictionary dictionaryWithDictionary: @{@"ottStatus": @"0"}];
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
AVAudioSessionRouteDescription *currentRoute = audioSession.currentRoute;
for (AVAudioSessionPortDescription *outputPort in currentRoute.outputs) {
if ([outputPort.portType isEqualToString:AVAudioSessionPortAirPlay]) {
ottDict[@"ottStatus"] = @"1";
ottDict[@"ottDeviceModel"] = outputPort.portName;
ottDict[@"ottDeviceID"] = outputPort.UID;
if ([outputPort.portName isEqualToString:@"AirPlay"]) {
ottDict[@"ottDevice"] = @"airplay";
ottDict[@"ottType"] = @"airplay";
}
else {
if ([outputPort.portName containsString:@"Apple TV"]) {
ottDict[@"ottDevice"] = @"appleTV";
}
else {
ottDict[@"ottDevice"] = @"other";
}
if ([outputPort.UID hasSuffix:@"airplay"]) {
ottDict[@"ottType"] = @"airplay";
}
else if ([outputPort.UID hasSuffix:@"screen"]) {
ottDict[@"ottType"] = @"mirroring";
}
else {
ottDict[@"ottType"] = @"other";
}
}
}
}
// report OTT status update to Nielsen SDK
[self reportOTTWithDict:ottDict];
}
Report OTT update to the Nielsen SDK
- (void)reportOTTWithDict:(NSDictionary *)ottDict
{
[self.nielsenSDK updateOTT:ottDict];
}
Going Live
Following Nielsen testing, users need to make one update to the initialization call to ensure that the site is being measured properly.
- Debug Logging: Disable logging by deleting
{nol_sdkDebug: 'DEBUG'}from initialization call.
Note: before going live you have to inform Nielsen team - this is necessary, because Nielsen team has to adjust internal configuration parameter to enable data collection. Without that notification no data will be collected and no data will be reported.
Removing Simulators (Dynamic Framework Only)
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. Here is an example Shell script that could be added as a Run Script phase in the application.
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"
EXTRACTED_ARCHS=()
for ARCH in $ARCHS
do
echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
done
echo "Merging extracted architectures: ${ARCHS}"
lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"
rm "${EXTRACTED_ARCHS[@]}"
echo "Replacing original executable with thinned version"
rm "$FRAMEWORK_EXECUTABLE_PATH"
mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"
done
Sample Applications
The below sample applications have been designed to show the Simplified API's functionality and are broken into two distinct categories:
- Nielsen API integrated into a custom video player.