DCR Static iOS SDK: Difference between revisions
From Engineering Client Portal
NickParrucci (talk | contribs) |
No edit summary |
||
Line 2: | Line 2: | ||
[[Category:Digital]] | [[Category:Digital]] | ||
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 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: | 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: |
Latest revision as of 02:50, 27 March 2024
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
- How long each app page/section was viewed (if enabled by your Nielsen representative)
Prerequisites for Static Measurement
This Guide is for the Implementation of Static Measurement. For implementation of Static and Video, please refer to the iOS DCR Video Implementation Guide.
To start using the App SDK, the following items are required:
Item | Description | Source |
---|---|---|
App ID (appid) | Unique ID assigned to the player/site and configured by product. | Contact Nielsen |
sfcode | Environment that the SDK must point to | 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.
Setting up your Development Environment
Prior to SDK Version 6.2.0.0 the IOS framework has been distributed as a static library packaged into framework bundle format. Apple recommends to use dynamic framework, it has some benefits over static libraries like less executable file size of an app, faster startup time and native support in xCode IDE. Nielsen AppSDK has been transformed into dynamic framework in this release (static framework is still available).
If migrating from the static library to this new dynamic framework, once implemented, unless your specific application requires, you can remove the following Frameworks that were once required: [AdSupport, JavascriptCore, SystemConfiguration, Security, AVFoundation, libc++]
The Dynamic framework is created as a fat framework. It means that it contains slices required for devices (armv7, arm64) as well as slices required for simulators (i386, x86_64). Simulator slices are needed to let clients build and debug their app on the simulators, but they should be removed before sending the app to the AppStore. The example of the shell script that should be added as a Run Script phase in the application can be found here.
How to obtain the NielsenAppApi.Framework
The Nielsen AppSDK can either be downloaded directly or can be integrated directly within an application through the use of CocoaPods. We recommend using the CocoaPods-based integration whenever possible to ensure you maintain the most recent changes and enhancements to the Nielsen libraries.
Configuring Xcode Development Environment
Starting with SDK version 6.0.0.0, the Nielsen App SDK is compatible with Apple iOS versions 8.0 and above. In addition, when using the dynamic framework, all the required frameworks are linked automatically as the are needed. More details can be found here: https://stackoverflow.com/questions/24902787/dont-we-need-to-link-framework-to-xcode-project-anymore
Note: All communications between the SDK and the Census (Collection Facility) use HTTPS.
Download Framework
The first step is to download and copy the NielsenAppApi.framework bundle to the app project directory. (Not required if using CocaPods)
Add Framework
In the General tab for app configuration add NielsenAppApi.framework in the list of Embedded Binaries. (Not required if using CocaPods)
Add Path
Add path to the NielsenAppApi.framework in the Framework Search Paths build setting. (Not required if using CocaPods)
Import Framework
Add NielsenAppApi.framework module in the source file of your app:
Using Swift
Add the following:
import NielsenAppApi
Using Objective-C
@import NielsenAppApi;
SDK Initialization
The latest version of the Nielsen App SDK allows instantiating multiple instances of the SDK object, which can be used simultaneously without any issue. The sharedInstance API that creates a singleton object was deprecated prior to version 5.1.1. (Click here for an example of multiple instances)
The following table contains the list of arguments that can be passed via the AppInfo JSON schema.
- The appid is provided by the Nielsen Technical Account Manager (TAM). The appid is a GUID data type and is specific to the application.
Parameter / Argument | Description | Source | Required? | Example |
---|---|---|---|---|
appid | Unique id for the application assigned by Nielsen. It is GUID data type. | Nielsen-specified | Yes | PXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX |
appname | Name of the application | Client-defined | Optional; automatically detected in SDK 6.0.0.4 and above | Nielsen Sample App |
sfcode | Nielsen collection facility to which the SDK should connect.
DTVR
DCR
|
Nielsen-specified | Yes | dcr |
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",
"sfcode": "dcr",
"nol_devDebug": "DEBUG"
]
return NielsenAppApi(appInfo:appInformation, delegate:delegate)
}
}
Sample code using AVPlayer.
LandingVC.swift
import UIKit
import NielsenAppApi
class LandingVC: UIViewController, NielsenAppApiDelegate {
var nielsenMain : NielsenAppApi!
var sdkMethods : SDKMethods!
var data : [String : Any]!
class ViewController: UIViewController, NielsenAppApiDelegate, AVPlayerViewControllerDelegate {
// your code//
override func viewDidLoad() {
super.viewDidLoad()
//Getting the instance of NielsenApi
self.nielsenApi = NielsenInit.createNielsenApi(delegate: self)
}
}
override func viewDidAppear(_ animated: Bool) {
self.data = sdkMethods.loadStaticMaster() // This is just an example of populating the metadata
self.nielsenMain.loadMetadata(self.data)
}
Objective C
Initialize the Nielsen App object within the viewDidLoad view controller delegate method using initWithAppInfo:delegate:
If App SDK is initialized using init or new methods, it will ignore the API calls resulting in no measurement. The SDK will not return any errors.
#import "NielsenInit.h"
#import <NielsenAppApi/NielsenEventTracker.h>
@implementation NielsenInit
+ (NielsenAppApi *)createNielsenAppApiWithDelegate:(id<NielsenAppApiDelegate>)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",
@"sfcode": @"dcr",
@"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];
API Call sequence
Call loadMetadata with JSON metadata as below.
Swift
class SDKMethods : NSObject{
func loadStaticMaster() -> [String : Any] {
//Loading Static Main data
let staticData =
[
"type": "static",
"assetid": "C77664", //optional for static measurement
"section": "siteSection",
"segA": "segmentA",
"segB": "CustomSegmentValueB", //optional
"segC": "CustomSegmentValueC", //optional
]
return staticData
}
Objective C
NSDictionary * staticMetadata = @ {
@ "type": @ "static",
@ "assetid": @ "C77664", //optional for static measurement
@ "section": @ "siteSection",
@ "segA": @ "Segment A",
@ "segB": @ "CustomSegmentValueB", //optional
@ "segC": @ "CustomSegmentValueC", //optional
}
Configure Metadata
Map the Nielsen keys to variables so that the content metadata is dynamically updated.
The Nielsen reserved keys are:
Key | Description | Data Type | Value | Required? |
---|---|---|---|---|
type | asset type | fixed | 'static' |
Yes |
assetid | Unique ID for each article | dynamic | custom (no Special Characters) |
No |
section | section of each site (e.g. section value should be first level in page URL: website.com/section). Limit to 25 unique values | dynamic | custom | Yes |
segA | custom segment for reporting: Limit to 25 unique values across custom segments (segA + segB + segC) | dynamic | custom | No |
segB | custom segment for reporting: Limit to 25 unique values across custom segments (segA + segB + segC) | dynamic | custom | No |
segC | custom segment for reporting: Limit to 25 unique values across custom segments (segA + segB + segC) | dynamic | custom | No |
The values passed through the Nielsen keys will determine the breakouts that are seen in reporting. The custom segments (A, B & C) will roll into the sub-brand. To not use custom segments A, B and C, do not pass any value in these keys.
Aggregation Limits There are limits on the number of unique values that can be aggregated on in reporting. The specific limitations by key are:
Key | Aggregation Limit |
---|---|
section | maximum of 25 unique values (section <= 25) |
segA | Maximum number of unique values allowed across segA, segB, and segC is 25 (segA + segB + segC<= 25) |
segB | Maximum number of unique values allowed across segA, segB, and segC is 25 (segA + segB + segC<= 25) |
segC | Maximum number of unique values allowed across segA, segB, and segC is 25 (segA + segB + segC<= 25) |
DCR Static Duration Measurement per Section/Page/Asset
If your Nielsen AppID is enabled for DCR Static duration measurement, a view event will be recorded and a timer will be started for each screen/page. Duration will be measured until a new page is loaded or the app is moved to the background. The event which triggers recognition of page view and timer start is the loadMetadata API call with a metadata object of type 'static'. Once a page is viewed and the timer has started, duration will be measured until a new page has loaded with associated loadMetadata call having a different section name from the previous page. If a new loadMetadata call is made with the same section name, it will be ignored - no new view will be recorded. If it is desired to have a new view event even though the metadata contains the same section name (example: single-page apps having several assedIDs but common section name), staticEnd API can be called between page views.
Show flow diagram for above description
Example 1 - In this example, a static view and duration ping with duration=25 will be generated for "SPORTS" section.
Show Swift Example
let staticMetadataSports = [ "type": "static", "section": "SPORTS" ]
nielsenSDK.loadMetadata(staticMetadataSports)
//in this example, after 25 seconds, new metadata is loaded for section "MOVIES"
let staticMetadataMovies = [ "type": "static", "section": "MOVIES" ]
nielsenSDK.loadMetadata(staticMetadataMovies)
Show Objective-C Example
NSDictionary *staticMetadataSports = @{@"type": @"static", @"section": @"SPORTS"};
[self.nielsenSDK loadMetadata:staticMetadataSports];
//in this example, after 25 seconds, new metadata is loaded for section "MOVIES"
NSDictionary *staticMetadataMovies = @{@"type": @"static", @"section": @"MOVIES"};
[self.nielsenSDK loadMetadata:staticMetadataMovies];
Example 2 - In this example,, let's assume 20 seconds after the page is viewed, the app goes to background. A static duration ping with duration=20 will be generated for "SPORTS" section.
Show Swift Example
let staticMetadataSports = [ "type": "static", "section": "SPORTS" ]
nielsenSDK.loadMetadata(staticMetadataSports)
//App goes to background or killed after 20 seconds.
Show Objective-C Example
NSDictionary *staticMetadataSports = @{@"type": @"static", @"section": @"SPORTS"};
[self.nielsenSDK loadMetadata:staticMetadataSports];
//App goes to background or killed after 20 seconds.
Note: Once the app is returned to foreground or relaunched, the app needs to pass static metadata again in order to restart measuring DCR Static duration.
Example 3 - Here we wish to generate a new view event and start a new duration timer even though the section name in the metadata is the same.
Show Swift Example
let staticMetadataSports = [ "type": "static", "section": "SPORTS", "assetid": "TENNIS"]
nielsenSDK.loadMetadata(staticMetadataSports)
//in this example, after 25 seconds, we pass staticEnd before new metadata is loaded for section "SPORTS", but assetid "CRICKET"
nielsenSDK.staticEnd()
let staticMetadataSports = [ "type": "static", "section": "SPORTS", "assetid": "CRICKET"]
nielsenSDK.loadMetadata(staticMetadataSports)
Show Objective-C Example
NSDictionary *staticMetadataSports = @{@"type": @"static", @"section": @"SPORTS", @"assetid": @"TENNIS"};
[self.nielsenSDK loadMetadata:staticMetadataSports];
//in this example, after 25 seconds, we pass staticEnd before new metadata is loaded for section "SPORTS", but assetid "CRICKET"
[self.nielsenSDK staticEnd];
NSDictionary *staticMetadataSports = @{@"type": @"static", @"section": @"SPORTS", @"assetid": @"CRICKET"};
[self.nielsenSDK loadMetadata:staticMetadataSports];
Note: Even though the assetid has changed, a new view event would not be recognized unless staticEnd() is called in between loadMetadata calls, because the section name did not change.
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 currently 3 flavors of the Nielsen SDK. Please check the "Implementation" section for a comparison of the three flavors. Implementing opt-out for the three flavors are different:
- Global iOS SDK Opt-out - managed by AppTracking or Limit Ad Tracking setting on device.
- Global iOS SDK No Ad Framework Opt-out - Direct call to SDK. Can be used without the Ad Framework.
- Global iOS SDK No ID Opt-out - Direct call to SDK. Should be used for Kids Category.
Global iOS SDK Opt-out
OS-level Opt-out method available on Nielsen iOS
The Nielsen SDK automatically leverages the iOS's Limit Ad Tracking or AppTracking setting.
- If the User's device is running < iOS 13.x, the Nielsen SDK will check the status of Limit Ad Tracking.
- iOS14 modifies the way Apple manages the collection of a User's Opt-In status through AppTracking. Starting with Version 8.x+, the Nielsen App SDK will check the iOS version during initialization. If the device is running iOS12 or iOS13, the Limit Ad Tracking setting is requested. If iOS14.x +, then AppTracking is utilized.
Webview Element
It is a requirement to display a WebView element whose loadUrl is set to the value obtained from optOutURL. If using the Global iOS SDK, this optOutURL informs the user how to deactivate/activate “App Tracking/Limit Ad Tracking”.
If you are implementing on AppleTV here are your Opt Out verbiage options : https://engineeringportal.nielsen.com/docs/DCR_Video_%26_Static_CTV_Device_SDK_Privacy
Sample Code for Global Build
Swift
import UIKit
import WebKit
import NielsenAppApi
class OptOutVC: UIViewController, NielsenAppApiDelegate, WKNavigationDelegate {
var nielsenApi : NielsenAppApi!
var webView: WKWebView!
override func loadView() {
webView = WKWebView()
webView.navigationDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
if let appApi = self.nielsenApi {
//Getting the optPut URL from SDK
if let url = URL(string: appApi.optOutURL) {
webView.load(URLRequest(url: url))
webView.allowsBackForwardNavigationGestures = true
}}}
func closeOptOutView() {
self.dismiss(animated: true, completion: nil)
}}
Objective-C
#import "OptOutVC.h"
#import "NielsenInit.h"
#import <NielsenAppApi/NielsenAppApi.h>
@interface OptOutVC ()
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@end
@implementation OptOutVC
- (void)viewDidLoad {
[super viewDidLoad];
- (void)viewDidLoad {
[super viewDidLoad];
//Getting the optPut URL from eventTracker
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL
URLWithString:self.nielsenApi.optOutURL]]];
}}
Global iOS SDK No Ad Framework Opt-out
The User Choice method can be used without the Ad Framework, or in situations where the publisher does not wish to use the App Tracking Transparency Framework. As this flavor of the Nielsen SDK does not use the Ad Framework, so it is necessary to display an Optout Page to the user and capture their selection.
Similar to the Global iOS SDK Flavor, it is a requirement to display a WebView element whose loadUrl is set to the value obtained from optOutURL. This is a special URL that indicates Opt-in, or Opt-out and close the WebView. The steps are as follows:
- Get the Nielsen opt-out URL via optOutURL
- Display a WebView element whose loadUrl is set to the value obtained from optOutURL
- Detect if the WebView URL changes to a special URL that indicates Opt-in, or Opt-out and close the WebView
- Opt-out if the WebView URL =
nielsenappsdk://1
- Opt-in if the WebView URL =
nielsenappsdk://0
- Opt-out if the WebView URL =
- Pass the detected URL to the userOptOut function
- Example:
NielsenAppApi?.userOptOut("nielsenappsdk://1"); // User opt-out
- Example:
Sample code for No Ad Framework Build
Swift
import UIKit
import WebKit
import NielsenAppApi
class OptOutVC: UIViewController, NielsenAppApiDelegate, WKNavigationDelegate {
var nielsenApi : NielsenAppApi!
var webView: WKWebView!
override func loadView() {
webView = WKWebView()
webView.navigationDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
if let appApi = self.nielsenApi {
//Getting the optPut URL from SDK
if let url = URL(string: appApi.optOutURL) {
webView.load(URLRequest(url: url))
webView.allowsBackForwardNavigationGestures = true
}}}
func closeOptOutView() {
self.dismiss(animated: true, completion: nil)
}
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler:
@escaping (WKNavigationActionPolicy) -> Void) {
print(navigationAction.request.url?.absoluteString as Any) //For debugging to check what is being passed from webpage.
if navigationAction.request.url?.absoluteString == "nielsen://close" {
closeOptOutView()
decisionHandler(.cancel)
} else {
if let url = navigationAction.request.url?.absoluteString, url.hasPrefix("nielsen") {
nielsenApi?.userOptOut(url). //either nielsenappsdk://1 or nielsenappsdk://0
decisionHandler(.cancel)
} else {
if navigationAction.navigationType == .linkActivated {
if let url = navigationAction.request.url?.absoluteString, url.hasSuffix("#") {
decisionHandler(.allow)
} else {
decisionHandler(.cancel)
webView.load(navigationAction.request)
}
} else {
decisionHandler(.allow)
}}}}
}
Objective-C
#import "OptOutVC.h"
#import "NielsenInit.h"
#import <NielsenAppApi/NielsenAppApi.h>
@interface OptOutVC ()
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@end
@implementation OptOutVC
- (void)viewDidLoad {
[super viewDidLoad];
- (void)viewDidLoad {
[super viewDidLoad];
//Getting the optPut URL from eventTracker
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL
URLWithString:self.nielsenApi.optOutURL]]];
}
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction
decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
{
if ([navigationAction.request.URL.absoluteString isEqualToString:kNielsenWebClose])
{ [self performSelector:@selector(closeOptOutView) withObject:nil afterDelay:0];
decisionHandler(WKNavigationActionPolicyCancel);
} else {
if ([navigationAction.request.URL.absoluteString hasPrefix:@"nielsen"])
{[self.nielsenAppApi userOptOut:navigationAction.request.URL.absoluteString];
decisionHandler(WKNavigationActionPolicyCancel);
} else {
if (navigationAction.navigationType == WKNavigationTypeLinkActivated)
{ if ([navigationAction.request.URL.absoluteString hasSuffix:@"#"])
{decisionHandler(WKNavigationActionPolicyAllow);
} else {
decisionHandler(WKNavigationActionPolicyCancel);
[webView loadRequest:[NSURLRequest requestWithURL:navigationAction.request.URL]];
}} else {
decisionHandler(WKNavigationActionPolicyAllow);
}}}
}
Global iOS SDK No ID Opt-out
If you are building an app that will be listed in the Kids Category:
- Ensure that you are using the NoID version of the Nielsen SDK Framework.
- Immediately following the initialization of the Nielsen SDK ensure you call the userOptOut API with Opt out selection:
NielsenAppApi?.userOptOut("nielsenappsdk://1"); // User opt-out
Retrieve current Opt-Out preference
Whether the user is opted out via OS-level Opt-out or via User Choice Opt-out, the current Opt-Out status as detected by the SDK is available via the optOutStatus property in the Nielsen SDK API
@property (readonly) BOOL optOutStatus
Pre-Certification Checklists
After the application is ready to be sent for Nielsen Certification, please go through the Pre-Certification Checklist and ensure the app behaves as expected, before submitting to Nielsen.
Testing an Implementation - App
See Digital Measurement Testing.
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.