iOS Step By Step

From Engineering Client Portal

Revision as of 14:16, 5 May 2023 by NickParrucci (talk | contribs) (Created page with "{{Breadcrumb|}} {{Breadcrumb|Digital}} {{CurrentBreadcrumb}} Category:Digital __NOTOC__ Provided below are step-by-step quick start guides for implementing Nielsen iOS SD...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Engineering Portal / Digital / iOS Step By Step


Provided below are step-by-step quick start guides for implementing Nielsen iOS SDK for DCR Static, DCR Video, and DTVR products. Click each section to get started.

→ iOS DCR Static

Show/hide DCR Static

iOS DCR Static Introduction

Show/hide Intro

The Digital Content Ratings (DCR) Static product provides content consumption measurement on client webpages. This measurement includes insight into the total time a user spent on a webpage, how they navigated through the page via links, and many other data points. This tutorial provides the steps to implement the DCR Static product in a sample iOS app. It includes:

  • SDK Initialization Call
  • DCR Static Metadata: information about the sections being tracked

By the end of this guide you will have the needed steps to integrate Nielsen's AppSDK in the background of your app.

iOS DCR Static Step 1 - Obtain AppID

Show/hide step 1

To begin using the iOS SDK (AppSDK) you will need to obtain an Application ID (AppId)

Item Description Source
App ID (appid) Unique ID assigned to the player/site and configured by product Contact your Nielsen TAM

The appid is a 37 character unique ID assigned to the player/site and configured by product and is required when creating a new instance of the AppSDK on the webpage.
Example: PXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX

iOS DCR Static Step 2 - SDK Initialization

Show/hide step 2

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;

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];



iOS DCR Static Step 3 - Create/Load DCR Static Metadata Object

Show/hide step 3

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.


Configure API calls - loadMetadata

Use loadMetadata to pass 'content' Digital Measurement Metadata. The CMS data must be passed as a JSON object.

    loadMetadata(JSONObject jsonMetadata);

Note: The loadMetadata call must have ("type": "static").


Call loadMetadata with JSON metadata as below.

    new JSONObject()
        .put("type", "static")
        .put("section", "siteSection")
        .put("assetid", "vid345-67483")
        .put("segA", "segmentA")
        .put("segB", "segmentB")
        .put("segC","segmentC")
    }

As soon as this loadMetadata call is made, AppSDK will record a view event and start tracking the section/page time spent (AppSDK 9.1 and above).

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. For the purposes of this overview, staticend will not be used. See this page for more information.


Keep Going

Show/hide

Congratulations, you've successfully integrated the iOS SDK in your app!

You can add static loadMetadata calls for more sections/pages in your app to see what happens when transitioning between sections.

View your application's debug logs and search for the term (AppSDK) to see messages emitted by Nielsen AppSDK.

Next Steps

Show/hide

Now that you've integrated DCR Static for the AppSDK, what's next?

Going Live

In addition to the basic steps above, before going live developers need to handle app background/foreground events, make certain privacy disclosures, and allow users to opt out of Nielsen measurement. More details can be found here, along with a more comprehensive reference for implementing DCR Static measurement with AppSDK.

Once the DCR Tracking Code is added, Nielsen will validate the implementation. Following Nielsen testing, developers need to make a few updates to the initialization call to ensure that the app is being measured properly.

  1. App ID: Ensure that correct is used during initialization PXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
  2. Debug Logging: Disable logging by changing initialization call to use @"nol_devDebug":@"INFO".




→ iOS DCR Video (coming soon)

→ iOS DTVR (coming soon)