Nielsen AppSDK

iOS App Implementation

last update: 24.6.2021



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 for Android and iOS operating systems. It supports a variety of Nielsen Measurement Products like Digital in TV Ratings, Digital Content Ratings (DCR, DTVR), Digital Ad Ratings(DAR), Digital Audio. This guide covers implementation steps for iOS using Xcode.


Prerequisites

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

  • AppID: Unique ID assigned to the player/site and configured by product.
If you do not have any of these prerequisites or if you have any questions, please contact our SDK sales support team - see Contacts.


Get the SDK

The Nielsen AppSDK can either be:

1) Integrated directly within an application through the use of a CocoaPod (iOS) - select to read CocoaPod implementation guide - Recommended solution that will keep your SDK copy latest by each build. Once finished continue to Step 3.

2) Downloaded as ZIP package at Nielsen Downloads. Please accept licence, insert your contact details, select product "Digital Content Ratings (DCR)" and choose "iOS SDK Download" in section "SDK Downloads". Package contains sample apps and Nielsen AppSDK in 2 versions :

  • DynamicFramework - Recommended 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.
    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 in Chapter 11: Going Live.
  • StaticFramework

You will have to update SDK manually always when new version of AppSDK is released. Please keep your version of SDK up to date.


Step 1: Setting up your Development Environment

1) Extract “NielsenAppApi.Framework” from the Nielsen SDK package app and copy it to Frameworks folder of the Xcode project.

2) Add Framework - In the General tab for app configuration add NielsenAppApi.framework in the list of Frameworks. If using Static frameworks - please refer to Static Framework Setup.

3) Add Path - Add path to the NielsenAppApi.framework in the Framework Search Paths build setting.

Note:

  • Nielsen App SDK is compatible with Apple iOS versions 9.0 and above.
  • The SDK uses the NSURLSession instead of the deprecated NSURLConnection.
  • All communications between the SDK and the Census (Collection Facility) use HTTPS


Step 2: Import SDK

Add SDK import

a) Using Objective-C :

Add the code to the View Controller’s header file

#import <NielsenAppApi/NielsenAppApi.h>

b) Using Swift :

Add the code to the ViewController.swift

import NielsenAppApi

Alternatively using Objective-C bridging header : 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.

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

#import <NielsenAppApi/NielsenAppApi.h>


Step 3: 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)

  • 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:
  • When four SDK instances exist, you must destroy an old instance before creating a new one.

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

Parameter Description Source Required Example
appid Unique id for the application assigned by Nielsen. It is GUID data type. Nielsen-specified Yes "PXXXXXXX-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. Put "cz" (for both dev phase + testing and production) Nielsen-specified Yes "cz"
nol_devDebug Enables Nielsen console logging. Only required for testing CNielsen-specified Optional "DEBUG"


Sample SDK Initialization Code

Swift

import UIKit
import NielsenAppApi

class ViewController: UIViewController, NielsenAppApiDelegate {

    var nielsenAppApi: NielsenAppApi?

    override func viewDidLoad() {
        super.viewDidLoad()

        let appInformation:[String: String] = [
            "appid": "PXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
            "appversion": "1.1",
            "appname": "Nielsen Video Player Swift CZ",
            "sfcode": "cz",
            "nol_devDebug": "DEBUG"
        ]
        self.nielsenAppApi = NielsenAppApi(appInfo:appInformation, 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.

Create NlsAppApiFactory.h

                            #import <Foundation/Foundation.h>
                            @class NielsenAppApi;
                            @protocol NielsenAppApiDelegate;
                            
                            @interface NlsAppApiFactory : NSObject
                            + (NielsenAppApi *)createNielsenAppApiWithDelegate:(id)delegate andContainerId:(NSInteger)containerId;
                            @end

Create NlsAppApiFactory.m

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

@implementation NlsAppApiFactory
+ (NielsenAppApi *)createNielsenAppApiWithDelegate:(id)delegate andContainerId:(NSInteger)containerId
{
    NSDictionary *appInformation = @{
	  @"appid": @"PXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXX",
      @"appversion": @"1.0",
      @"sfcode": @"cz",
      @"nol_devDebug": @"DEBUG",
      @"containerId": @"1" };

    return [[NielsenAppApi alloc] initWithAppInfo:appInformation delegate:delegate];
}
@end
                        

Init SDK inside ViewController.m

#import "ViewController.h"
#import "NlsAppApiFactory.h"

@interface ViewController ()
    @property (nonatomic, strong) NielsenAppApi *nielsenAppApi;
@end

@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"viewDidLoad - app started");

		// Nielsen SDK init
    self.nielsenAppApi = [NlsAppApiFactory createNielsenAppApiWithDelegate:nil andContainerId:0];
}
...
                        


AppSDK Errors & Event Codes

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


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 "Initial 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 the play event to occur.
  • "Processing state" – The SDK instance is processing playing information. API calls "play" and "loadMetadata" move the SDK instance into this state. In this state, the SDK instance will be able to process the API calls (see below)
  • "Disabled state" – The SDK instance is disabled and is not processing playing information. SDK instance moves into this state in one of the following scenarios.
    • Initialization fails
    • appDisableApi is called
                                          @property (assign) BOOL appDisableApi;
                                          


Step 4: Create Metadata Objects

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.


Create channelName Metadata

channelName should remain constant throughout the completion of an episode or live stream.

Key Description Values Reqired
channelName Any string representing the channel/stream custom yes


Create Content Metadata

Content metadata should remain constant throughout the completion of an episode / clip including the ads play.
See Specification of Metadata for Czech Republic.


Create Ad Metadata

The ad metadata should be passed for each individual ad.
See Specification of Metadata for Czech Republic.


Metadata Example

Swift

                            let channelInfo = [
                            "channelName": "My Channel Name 1",
                         ]
                    
                         let contentMetadata = [
                           "assetid" : "c1",
                            "type" : "content",
                            "program" : "myProgram",
                            "title" : "Anime Movie",
                            "length" : "52",
                            "airdate" : "20161013 20:00:00",
                            "isfullepisode" : "y",
                            "crossId1" : "9827411",
                            "nol_c1" : "p1,",
                            "nol_c2" : "p2,TVident",
                            "segB" : "Programový typ",
                            "segC" : "",
                            "adloadtype" : "1",
                            "hasAds" : "1"
                         ]
                    
                        let adMetadata = [
                            "assetid" : "ad1",
                            "type" : "midroll",
                            "length" : "34",
                            "title" : "Ad Renault",
                            "nol_c4" : "p4,ASMEA code for ad",
                            "nol_c5" : "p5,Atribut for ad",
                            "nol_c6" : "p6,midroll",
                            "nol_ac" : "ad"
                        ]
                           

Objective C

                            NSDictionary  *channelInfo = @
                            {
                              @"channelName":@"My Channel Name 1",
                            }
                            
                            NSDictionary *contentMetadata = @
                              {
                              @"assetid" : "c1",
                              @"type" : "content",
                              @"program" : "myProgram",
                              @"title" : "Anime Movie",
                              @"length" : "52",
                              @"mediaUrl" : "",
                              @"airdate" : "20161013 20:00:00",
                              @"isfullepisode" : "y",
                              @"crossId1" : "9827411",
                              @"nol_c1" : "p1,",
                              @"nol_c2" : "p2,TVident",
                              @"segB" : "Programový typ",
                              @"segC" : "",
                              @"adloadtype" : "1",
                              @"hasAds" : "1"
                            }
                            
                            NSDictionary *adMetadata = @
                              {
                              @"assetid" : "ad1",
                              @"type" : "midroll",
                              @"length" : "34",
                              @"title" : "Ad Renault",
                              @"nol_c4" : "p4,ASMEA code for ad",
                              @"nol_c5" : "p5,Atribut for ad",
                              @"nol_c6" : "p6,midroll",
                              @"nol_ac" : "ad"
                            }
                           


Step 5: Configure API Calls


Overview of SDK API Calls


play

The play method prepares the SDK for reporting once an asset has loaded and playback has begun. Use play to pass the channel descriptor information through channelName parameter when the user taps the ""Play"" button on the player. Call play only when initially starting the video.

Swift

self.nielsenAppApi?.play(channelInfo);

Objective C

nielsenAppApi play:(JSONObject channelInfo);

loadMetadata

Needs to be called at the beginning of each asset, pass JSON object for relevant content or ad. Make sure to pass as 1st loadMetadata for content at the begining of playlist - see below API call sequence examples.

Swift

self.nielsenAppApi?.loadMetadata(contentMetadata)

Objective C

nielsenAppApi loadMetadata:(id)contentMetadata;

playheadPosition

Pass playhead position every second during playback. for VOD: pass current position in seconds. for Live: current Unix timestamp (seconds since Jan-1-1970 UTC) - if it is possible to seek back in Live content, then pass related Unix time (not current). Pass whole number that increments only by 1 like 1,2,3..

Swift

self.nielsenAppApi?.playheadPosition(pos);

Objective C

nielsenAppApi playheadPosition: (long long) playheadPos

stop

Call when

  • ads complete playing
  • when a user pauses playback
  • upon any user interruption scenario - see bellow chapter Interruption scenario

Swift

self.nielsenAppApi?.stop

Objective C

nielsenAppApi stop

end

Call when the content asset completes playback. Stops measurement progress.

Swift

self.nielsenAppApi?.end

Objective C

nielsenAppApi end;


Content Only

In order to start the measurement, follow the 3 first steps below for Content without Ads. When terminating the Content playback call end to terminate the Content Measurement for the given asset.

Playlist Sample code Description
1. Start of stream play(channelName) channelName contains JSON metadata of channel/video name being played
loadMetadata(contentMetadataObject) contentMetadataObject contains the JSON metadata for the content being played
2. Content is playing playheadPosition(position) playheadPosition is position of the playhead while the content is being played
3. End of Stream end Content playback is completed.


Content with Ads

Playlist : ad preroll - content - ad midroll - content continues - ad postroll. 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.

Playlist Sample code Description
1. Start of stream play(channelName); channelName contains JSON metadata of channel/video name being played
loadMetadata(contentMetaDataObject); contentMetadataObject contains the JSON metadata for the content being played
2. Preroll loadMetadata(prerollMetadataObject); prerollMetadataObject contains the JSON metadata for the preroll ad
setPlayheadPosition(playheadPosition); position is position of the playhead while the preroll ad is being played
stop(); Call stop after preroll occurs
3. Content loadMetadata(contentMetaDataObject); contentMetadataObject contains the JSON metadata for the content being played
setPlayheadPosition(playheadPosition); position is position of the playhead while the content is being played
stop(); Call stop after the content is paused (ad starts)
4. Midroll loadMetadata(midrollMetaDataObject); midrollMetadataObject contains the JSON metadata for the midroll ad
setPlayheadPosition(playheadPosition); position is position of the playhead while the midroll ad is being played
stop(); Call stop after midroll occurs
5. Content (End) loadMetadata(contentMetaDataObject); contentMetadataObject contains the JSON metadata for the content being played
setPlayheadPosition(playheadPosition); position is position of the playhead while the content is being played
6. End of Stream end(); Call end() at the end of content
7. Postroll loadMetadata(postrollMetaDataObject); postrollMetadataObject contains the JSON metadata for the postroll ad
setPlayheadPosition(playheadPosition); position is position of the playhead while the postroll ad is being played
stop(); Call stop after postroll occurs


Step 6: Stop/Resume the Measurement for video Playback Interruptions

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 headphones

In case of encountering one of the above interruptions, the player application needs to

  • Call stop immediately (except when content is buffering) and withhold sending playhead position.
  • Once the playback resumes, start sending pings playheadPosition for the new viewing session.

Please see the Interruption Scenarios Page for more details


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.


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 with anonymous data.
  • A link to the Nielsen Digital Measurement Privacy Policy located at http://priv-policy.imrworldwide.com/priv/mobile/cz/cs/optout.html .


Opt-out

A user can opt-out if they would prefer not to participate in any Nielsen online measurement research. To implement the opt-out option, include the following two items in your app settings screen or to your Privacy Policy / EULA section.

  • A notice that the player includes proprietary measurement software that allows users to contribute to market research (such as Nielsen TV Ratings). The following paragraph is a template for an opt-out statement (in Czech).
    Tato aplikace obsahuje proprietární měřící software spolecnosti Nielsen, která uživatélům umožní přispívat k průzkumu trhu. Chcete-li se dozvědet více o informacich, které může software Nielsen shromažďovat a o Vaši možnosti měření deaktivovat, prečtěte si zásady ochrany osobní údajů Nielsen Digital Measurement na Nielsen Digital Measurement Privacy Policy.
  • A link to the Nielsen Digital Measurement Privacy Policy.

1. Get URL

URL for the Nielsen Privacy web page should be retrieved using below API method

                            self.nielsenAppApi!.optOutURL

If the App SDK returns NULL in the optOutURL, handle the exception gracefully and retry later. Example of returned Url is http://priv-policy.imrworldwide.com/priv/mobile/cz/cs/optout.html followed by unique hash.

2. Open URL in webView

Recieved URL should be opened in 'WebView' / External browser. App should provide a UI control like 'close' or 'back' button to close the 'WebView' / External browser.

3. Get current Opt-Out status (voluntarily)

To retrieve the current Opt-Out status of a device, use the API getOptOutStatus method.

                        self.nielsenAppApi!.optOutStatus
                        

Put it inside AsyncTask to get proper result.

Users can opt out or opt back into Nielsen Measurement. Opt-Out feature relies on iOS' system settins in Settings → Privacy → Advertising → Limit Ad Tracking. User is opted out of Nielsen online measurement research when the "Limit Ad Tracking" setting is enabled.

Note: SDK will be sending the data pings to census even though SDK is opted out (In earlier releases all the traffic from SDK to census will be ceased). However, all the outgoing pings will have the parameter uoo=true using which backend can ignore this data.


Step 8 : Test your player by yourself


Guide

1. Connect your PC and test device (tablet or phone) via same router.

2. PC side: run Proxy sw (like Charles) and get local IP

3. Test device: modify Wifi setting to pass through Proxy IP from step 2.

4. Test device: run your player, launch video

5. PC side: filter traffic by "nmr" and confirm presence of GN pings


Example of GN ping

                            https://secure-cert.imrworldwide.com/cgi-bin/gn?prd=dcr&ci=cz-509218&ch=cz-509218_c04_P&asn=defChnAsset&sessionId=epHSOa1alCOKVx84Ghso0nyQbXiAL1558443517&tl=Nielsen%2520preroll&prv=1&c6=vc,c04&ca=cz-509218_c04_assetid_example_preroll&cg=ProgramName&c13=asid,P24E981D1-5A7F-471B-BB3A-9E8207A77B39&c32=segA,NA&c33=segB,Program%2520type&c34=segC,NA&c15=apn,CZ%20demo%20Artifactory&plugv=&playerv=&sup=1&segment2=-1&segment1=cze&forward=0&ad=1&cr=4_00_99_D1_00000&c9=devid,&enc=true&c1=nuid,&at=timer&rt=video&c16=sdkv,aa.6.0.0&c27=cln,27&crs=0&lat=&lon=&c29=plid,P24E981D1-5A7F-471B-BB3A-9E8207A77B39&c30=bldv,aa.6.2.0.0_ga&st=dcr&c7=osgrp,DROID&c8=devgrp,TAB&c10=plt,MBL&c40=adbid,&c14=osver,Android6.0.1&c26=dmap,1&dd=&hrd=&wkd=&c35=adrsid,&c36=cref1,IDEC&c37=cref2,&c11=agg,1&c12=apv,&c51=adl,27&c52=noad,1&sd=30&devtypid=asus-Nexus-7&pc=NA&c53=fef,n&c54=oad,&c55=cref3,&c57=adldf,2&ai=assetid_example_preroll&c3=st%252Ca&c64=starttm,1558443522&adid=assetid_example_preroll&c58=isLive,false&c59=sesid,JVThto0RdZkCNLXyA5TPa2DBNo0CO1558443522&c61=createtm,1558443552&c63=pipMode,&c60=cvarall,p0%252Cdcrcz~~~~~~st%252Ca~~p4%252CASMEAcode~~p5%252CAtributForAd~~p6%252Cpreroll&c62=sendTime,1558443552&c68=bndlid,cz.nielsenadmosphere.androiddemo&c69=cvw,&nodeTM=&logTM=&c73=phtype,Tablet&c74=dvcnm,Google+Nexus+7&c76=adbsnid,&df=-1&uoo=true&c44=progen,&davty=1&si=&c66=mediaurl,&vtoff=0&rnd=1558443552224
                        


Step 9: Provide your app for certification

Once ready please send your application to Nielsen local staff for verification - see Contacts.


Step 10 : Going Live

After the integration has been certified (but not prior that), disable debug logging by deleting {nol_devDebug: "DEBUG"} from initialization call - see Step 3.


Removing Simulators

If using 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 or exporting to IPA. 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               
                        


Demos

See live demos with sample implementation available at http://sdkdemo.admosphere.cz/


Contacts

Company

Nielsen Admosphere

Českobratrská 2778/1

130 00 Praha 3

www.nielsen-admosphere.cz


Administration, testing, certification and technical support

Tomáš Kuchler

Technical Account Manager

+420 777 814 468

tomas.kuchler@admosphere.cz


NielsenSDK Team

SDKsupport@admosphere.cz


FAQ

When to instantiate Nielsen SDK?
Right at application start and only once during runtime.

Which API calls shall be executed and when?
a) for standard runtime - see Chapter 5
b) for intertuption scenario - see Chapter 6