DCR & DTVR iOS Adobe Launch Extension

From Engineering Client Portal

Revision as of 22:08, 12 January 2019 by Admin3 (talk | contribs)

Engineering Portal breadcrumbArrow.png Digital breadcrumbArrow.png DCR & DTVR breadcrumbArrow.png DCR & DTVR iOS Adobe Launch Extension

Adobe Launch Extensions

Adobe Launch Extensions are building blocks for mobile application development. The necessary functionality can be implemented independently and put to separate Extensions, but make them able to communicate using Events. These extensions live on Artifactory servers and can be used by clients who develop their mobile applications.

Nielsen AppSDK Extension

Nielsen provides the Adobe Launch Extension based on AppSDK for measuring the video/audio content. It has the name Nielsen AppSDK Extension and is available for android and iOS mobile platforms.

Extension Installation and Configuration

Adobe has developed an Extension to simplify adding Nielsen measurement into your video stream. The first step is to create and publish a property which is outlined in the Getting Started Guide.

Configure the Extension

If the user doesn’t want to set the configuration in the code and wants to make the configuration more flexible and changeable on the fly, it can be configured through the interface. In order to do that, go to the collection of installed extensions of the property. icon The configuration allows to set different configuration for iOS and Android platforms: icon

Build the Extension

After the Extension is configured, it can be “built” under the “library” on the Publishing page with other “libraries”. It is the main step for adding the configuration to the main configuration file and to register the package under specific App Id after building it.

Add a New library

Select to add a new library

icon

Set the name, chose Environment (Production, Staging, Development):

icon

Save and Build

Add all changed resources. When you get the Extension configured, it will appear in the list of changed resources. Select the Latest revision and press “Select & Create a New Revision” button: icon

Confirm

Once built, it will appear in the list of Development libraries:

icon

View in Library

Once it is set up, the user will be prompted to the Environments page where it can be Installed.

icon

Obtain Mobile Installation Instructions

You will then be provided the Mobile Installation Instructions.

icon

How to add the Nielsen AppSDK extension to a Project in iOS

CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. It has over 30 thousand libraries and is used in over 1.9 million apps. The Nielsen SDK now uses this distribution framework for improved version management.

Initial Configuration

The Nielsen SDK integration requires Cocoapods 1.4.0. or higher. The full installation guide for this framework is provided on the Getting Started page. How to set up the Podfile is mentioned in Using Cocoapods page.

Repository Credentials

The first step is to add the credentials received from Nielsen into your .netrc file. Navigate to your home folder and create a file called .netrc

cd ~/
vi .netrc

Within this file you need to add your credentials in the following format:

machine raw.githubusercontent.com
login <Nielsen App SDK client>
password <Auth token>

Your Credentials are:

machine raw.githubusercontent.com
login NielsenSdkRepo
password edec0d01b953171c704188c1d8fc0aa4217ec506

Verify version of Cocoapods

First verify that Cocoapods is installed.

pod --version

If it is not, then install.

Install via gem
sudo gem install cocoapods
Install using homebrew
brew install cocoapods

Add Cocoapod repository

From the command line, type the following:

pod repo add NielsenAppSDKExtension https://github.com/nielsendigitalsdk/nielsenappsdkextension-ios-specs.git

It is also recommended to add the repo source into your podfile to avoid any cache issues. (See examples below) Make sure you run the pod init command in your **project's directory.**

pod init

You now need to slightly modify the PodFile that was created in this directory. The following must be in the PodFile:

Podfile

platform :ios, '11.0'
source 'https://github.com/NielsenDigitalSDK/nielsenappsdkextension-ios-specs.git'
source 'https://github.com/CocoaPods/Specs.git'

target 'YourProjectsNameHere' do
    #Pods for ApplicationTarget
    pod 'NielsenAppSDKExtension'
end


Once that has been edited, you can now execute the install:

pod install

Cocoapods will automatically create a new file with extension “.xcworkspace”. From this moment, that file should be used for using the target project instead of previous one with extension “.xcodeproj”. Inside of this workspace you will see “Pods” target which will include ready to use NielsenAppSDKExtension framework.

Open the file with the extension of .xcworkspace file using Xcode.

Integration

As per integration requirements provided by Adobe, the Extension object can be registered and created only once, and its instance is not accessible from the outside - the ACPCore keeps and doesn’t expose it.

Swift

ACPCore.setLogLevel(.debug)
ACPCore.setPrivacyStatus(.optIn)
do {
        NielsenAppSDKExtension.registerListener(forSDKNotifier: NielsenAppSDKEventListener.self)
        try ACPCore.registerExtension(NielsenAppSDKExtension.self)
} catch (let exception) {
        print("Exception: \(exception)")
}

ACPCore.configure(withAppId: Your Adobe Launch Property Key)

ACPCore.start {}

Objective-C

[ACPCore setLogLevel:ACPMobileLogLevelDebug];
[ACPCore setPrivacyStatus:ACPMobilePrivacyStatusOptIn];
NSError *error = nil;

[ACPCore registerExtension:NielsenAppSDKExtension.class error:&error];
if (error)
{
    NSLog(@"%@", error);
}

[ACPCore configureWithAppId:@Your Adobe Launch Property Key””];
[ACPCore start:^{}];

Communication

The communication with the Extension happens by two separate flows: API and Events. The first one just redirects Extension’s class-access methods to direct instances of the NielsenAppSDK. The second one works with ACPCore’s EventHub - the core of the extension. Through the Hub the Core receives all the events and notifies the listeners if they are subscribed for them.

NOTE: be aware of mixing the approaches. Because of different architectures for API approach and Event approach (and the asynchronous nature of Events), it is not guaranteed that events and API will be handled in order of their call.

The list of APIs (the meaning of each event and API is described later in this document)

Public APIs exposed by extension

+ (NSDictionary *)instantiateSDKWithConfiguration:(NSDictionary *)configuration;
+ (NSDictionary *)instantiateSDKWithRemoteConfiguration;
+ (NSDictionary *)removeSDKWithIdentifier:(NSString *)identifier;
+ (NSDictionary *)trackEvent:(NSDictionary *)event forSDKWithIdentifier:(NSString *)identifier;
+ (NSDictionary *)optOutStatusForSDKWithIdentifier:(NSString *)identifier;
+ (NSDictionary *)appDisableForSDKWithIdentifier:(NSString *)identifier;
+ (NSDictionary *)setAppDisable:(BOOL)appDisable forSDKWithIdentifier:(NSString *)identifier;
+ (NSDictionary *)debugForSDKWithIdentifier:(NSString *)identifier;
+ (NSDictionary *)setDebug:(BOOL)debug forSDKWithIdentifier:(NSString *)identifier;
+ (NSDictionary *)demographicIdForSDKWithIdentifier:(NSString *)identifier;
+ (NSDictionary *)optOutURLForSDKWithIdentifier:(NSString *)identifier;
+ (NSDictionary *)meterVersionForSDKWithIdentifier:(NSString *)identifier;
+ (void)registerListenerForSDKNotifier:(Class)aClass;

Events

  1. InstantiateSDKWithLocalConfigEvent
  2. InstantiateSDKWithRemoteConfigEvent
  3. RemoveSDKInstanceEvent
  4. TrackSDKEvent
  5. GetOptoutStatusEvent
  6. GetAppDisableEvent
  7. SetAppDisableEvent
  8. GetDebugEvent
  9. SetDebugEvent
  10. GetDemographicIdEvent
  11. GetOptoutURLEvent
  12. GetMeterVersionEvent


In order to fire the event, the next API of the ACPCore should be used:

NSError *error = nil;
NSString *name = @...;
NSString *type = @com.nielsen.eventType.instanceControl;
NSString *source = @com.nielsen.eventSource.instanceControl;
NSDictionary *payload = @{
    identifier: the identifier under which the instance is kept
or
    data: {appid:..., ...}
};
ACPExtensionEvent *newEvent = [ACPExtensionEvent extensionEventWithName:name
                                                                                                                            type:type 
                                                                                                                        source:source
                                                                                                                            data:payload 
                                                                                                                            error:&error];
if (error)
{
    NSLog(@"Error constructing new event %@:%ld", [error domain], (long)[error code]);
    return;
}

[ACPCore dispatchEventWithResponseCallback:newEvent 
          responseCallback:^(ACPExtensionEvent * _Nonnull responseEvent) {
    //Use responseEvent.eventData to collect the result data
} error:&error];

if (error)
{
    NSLog(@"Error dispatching event %@:%ld", [error domain], (long)[error code]);
}

The Extension listens for specific events’ type and source and handles specific event names differently. The API and Event flows are mirroring each other. And they are mirroring NielsenAppSDK’s api.

Result

The result format that is returning with API flow and with Event flow is the same for both flows - this is a JSON object.

It consists of the result code, description and the identifier. { ‘identifier’ : ‘...’, //might not be there if the “remove” API or Event is made ‘code’ : 5001, ‘description’ : ‘...’ }

Possible error codes are:

typedef NS_ENUM(NSUInteger) {
    NielsenAppSDKExtensionResultCodeSuccess = 5001,
    NielsenAppSDKExtensionResultCodeUnexpected = 5002,
    NielsenAppSDKExtensionResultCodeNoRemoteConfiguration = 5003,
    NielsenAppSDKExtensionResultCodeNoLocalConfiguration = 5004,
    NielsenAppSDKExtensionResultCodeMissingParameter = 5005,
    NielsenAppSDKExtensionResultCodeSDKInstantiationFailure = 5006,
    NielsenAppSDKExtensionResultCodeNoSDKInstance = 5010,
    NielsenAppSDKExtensionResultCodeExceptionOccured = 5011,
    NielsenAppSDKExtensionResultCodeInvalidEventReceived = 5012
} NielsenAppSDKExtensionResultCode;

API and Events description

Instantiating the SDK

NielsenAppSDK can support multiple instances, and not to lose this feature, the Extension keeps SDK instances by the identifiers. When the user requests to create the instance, the Extension instantiates it and returning back the identifier which the user will use for further SDK control.

There are two ways of initializing the SDK with configuration: the configuration provided in the code and configuration that is set up on the Adobe Launch panel of your property.

To support four flows (API, Events, Local Configuration and the Remote Configuration) the next APIs and events are introduced:

NSDictionary *result = [NielsenAppSDKExtension instantiateSDKWithConfiguration:@{"appid":"...", "sfcode":"..."}]
NSDictionary *result = [NielsenAppSDKExtension instantiateSDKWithRemoteConfiguration]

Event “InstantiateSDKWithLocalConfigurationEvent” “InstantiateSDKWithRemoteConfigurationEvent”

To provide the configuration for “InstantiateSDKWithLocalConfigurationEvent” event, put the configuration under the “data” key in the JSON object:

{
	"data" : {"appid":"...", "sfcode":"..."}
}

The result of those APIs and events is a JSON object. It returns the identifier string under which a newly created instance is kept. Use the identifier to make further calls to control the NielsenAppSDK.

Removing the SDK instance

In order to remove the instance that the Extension is keeping, call the remove API or fire an event with providing the identifier.

NSDictionary *result = [NielsenAppSDKExtension removeSDKWithIdentifier:@"the identifier under which instance is kept"]

Event

“RemoveSDKInstanceEvent”

To provide the identifier for “RemoveSDKInstanceEvent” event, put the configuration under the “identifier” key in the JSON object:

{
	"identifier" : "the identifier under which instance is kept"
}

All result returned are in JSON object

Tracking the SDK Event

To track NielsenAppSDK’s event call the track SDK Event API or fire an event with providing the identifier.

NSDictionary *result = [NielsenAppSDKExtension trackEvent:@{"event":"playhead", "playheadPosition":"0", ...} 
                            forSDKWithIdentifier:@"the identifier under which instance is kept"]

Event

"TrackSDKEvent"

To provide the identifier for "TrackSDKEvent" event, put the identifier under the "identifier" key in the JSON object and the event metadata:

{
	"identifier" : "the identifier under which instance is kept",
	"data" : {"event":"playhead", "playheadPosition":"0", ...}
}

Retrieving the Opt Out Status

To get the opt out/opt in status, call according API or fire an event with providing the identifier.

NSDictionary *result = [NielsenAppSDKExtension optOutStatusForSDKWithIdentifier:@"the identifier under which instance is kept"]

Event

"GetOptoutStatusEvent"

To provide the identifier for "GetOptoutStatusEvent" event, put the identifier under the “identifier” key in the JSON object:

{
	"identifier" : "the identifier under which instance is kept"
}

The result of those APIs and events is a JSON object. The status is provided in the json object under the “optout_status” key:

{
	"optout_status" : 0 or 1,
	...}

Enabling and disabling the SDK

The user is able to get the SDK disabled if he doesn’t want to use its functionality. To use it, the disable API or Event should be made. To get the status, call API or fire an Event for getting the status.


NSDictionary *result = [NielsenAppSDKExtension setAppDisable:YES/NO forSDKWithIdentifier:@"the identifier under which instance is kept"]
NSDictionary *result = [NielsenAppSDKExtension appDisableForSDKWithIdentifier:@"the identifier under which instance is kept"]

Event

"SetAppDisableEvent"
"GetAppDisableEvent"

To provide the identifier for "SetAppDisableEvent” event, put the identifier under the “identifier” key in the JSON object and if it is needed to disable the SDK, provide the value of 1 for “app_disable” key:

{
	"identifier" : "the identifier under which instance is kept"
}

To retrieve the status just provide the identifier in the object for the "GetAppDisableEvent" event:

{
"identifier" : "the identifier under which instance is kept"
}

The status for "GetAppDisableEvent" event is provided in the json object under the “app_disable” key:

{
"app_disable" : 0 or 1,
}

Setting Debug mode for the SDK

The user is able to set the debug mode of the SDK to write debug logs into file. To use it, the debug API or Event should be made. To get the status, call API or fire an Event for getting the status.

NSDictionary *result = [NielsenAppSDKExtension setDebug:YES/NO forSDKWithIdentifier:@"the identifier under which instance is kept"
NSDictionary *result = [NielsenAppSDKExtension debugForSDKWithIdentifier:@"the identifier under which instance is kept"]

Event

"SetDebugEvent"
"GetDebugEvent"

To provide the identifier for “SetDebugEvent” event, put the identifier under the “identifier” key in the JSON object and if it is needed to change the mode of the SDK to debug, provide the value of 1 for “debug” key:

{
	"identifier" : "the identifier under which instance is kept",
"debug" : 0 or 1
}

To retrieve the status just provide the identifier in the object for the “GetDebugEvent” event:

{
	"identifier" : "the identifier under which instance is kept"
}

Retrieving the Demographic Identifier

To get the demographic identifier, call according API or fire an event with providing the identifier.

NSDictionary *result = [NielsenAppSDKExtension demographicIdForSDKWithIdentifier:@"the identifier under which instance is kept"]

Event

“GetDemographicIdEvent” To provide the identifier for “GetDemographicIdEvent” event, put the identifier under the “identifier” key in the JSON object:

{
	"identifier" : "the identifier under which instance is kept"
}

The result of those APIs and events is a JSON object. The demographic identifier is provided in the json object under the “demographic_id” key:

{
"demographic_id" : "the demographic identifier",
	...
}

Retrieving the OptOut URL

To get the opt out URL, call according API or fire an event with providing the identifier.

NSDictionary *result = [NielsenAppSDKExtension optOutURLForSDKWithIdentifier:@"the identifier under which instance is kept"]

Event

“GetOptoutURLEvent” To provide the identifier for “GetOptoutURLEvent” event, put the identifier under the “identifier” key in the JSON object:

{
	"identifier" : "the identifier under which instance is kept"
}

The result of those APIs and events is a JSON object. The opt out URL is provided in the json object under the "optout_url" key:

{
"optout_url" : "https://optout.url",
	...
}

Retrieving the SDK Version

To get the SDK version, call according API or fire an event with providing the identifier.

NSDictionary *result = [NielsenAppSDKExtension meterVersionForSDKWithIdentifier:@"the identifier under which instance is kept"]

Event

“GetMeterVersionEvent” To provide the identifier for "GetMeterVersionEvent" event, put the identifier under the “identifier” key in the JSON object:

{
	"identifier" : "the identifier under which instance is kept"
}

The result of those APIs and events is a JSON object. The version of the SDK is provided in the json object under the "meter_version" key:

{
"meter_version" : "version of the meter",
	...}

Listening for NielsenAppSDK error events

If something happening in the internal kitchen of the SDK, it is always useful to get this information and use it. In order to achieve this, the Extension fires specific event to the EventHub, so user from the outside is able to listen to it and get the info. The listener can be built as standard ACPExtensionListener child of the ACPCore framework.

Once the class is created and the “hear” method is implemented, the listener can be registered by the NielsenAppSDKExtension using next API:

[NielsenAppSDKExtension registerListenerForSDKNotifier:NielsenAppSDKEventListener.class]

As per the architecture of the ACPCore, user doesn’t have access to the instance of the EventListener. But in order to be able to show a result somewhere, write to specific file, and so forth, he might fire Notification so the observers will be notified about the error happened (for example, a File Manager that will write the error to the file.

@implementation NielsenAppSDKEventListener
- (void)hear:(ACPExtensionEvent *)event
{
    NSNotification *notification = [NSNotification notificationWithName:@"NielsenAppSDKEventNotification" object:nil userInfo:event.eventData];
    [NSNotificationCenter.defaultCenter postNotification:notification];
}
@end