DCR & DTVR Android Adobe Launch Extension

From Engineering Client Portal

Revision as of 21:43, 12 January 2019 by Admin3 (talk | contribs)

Engineering Portal breadcrumbArrow.png Digital breadcrumbArrow.png DCR & DTVR breadcrumbArrow.png DCR & DTVR Android 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 install the Nielsen AppSDK using Gradle for Android

Below are the steps which needs to be performed by app developers to integrate nielsen app sdk within an android application.

Update grade.properties

The first step is to add the credentials received from Nielsen into your gradle.properties file, generally near the end of the file. We recommend using the version in your home folder (Global Properties). Grade looks for gradle.properties files in this sequence:

  • gradle.properties in project root directory.
  • gradle.properties in GRADLE_USER_HOME directory.
  • system properties, e.g. when -Dgradle.user.home is set on the command line.

Properties from one file will override the properties from the previous ones (so file in gradle user home has precedence over the others, and file in sub-project has precedence over the one in project root).

Reference: https://gradle.org/docs/current/userguide/build_environment.html

machine raw.githubusercontent.com
nielsen_user=<Nielsen App SDK client>
nielsen_authCode=<Auth token>


Your Credentials are:

machine raw.githubusercontent.com
login NielsenSdkRepo
password edec0d01b953171c704188c1d8fc0aa4217ec506

Add Nielsen Maven Repository

Please add the nielsen maven repository inside the repositories section of your app's module build.gradle file like below:

android{ 
repositories {
   //Copy below code inside repository section of app’s build.gradle file
maven { url 'https://raw.githubusercontent.com/NielsenDigitalSDK/nielsenappsdk-extension-android/master/'
   credentials {
      //Make sure you add nielsen_user and nielsen_passwd with respective nielsen provided
     // values to global gradle.properties file
       username = project.property("nielsen_user")
       password = project.property("nielsen_authCode")
   }
   authentication {
       basic(BasicAuthentication)
   }
}
}

}

Add gradle dependency

Please add nielsen app sdk as compile time dependency inside build.gradle file as below

grade 4.x and above

For gradle version starting with 4.x add below line inside dependencies section of build.gradle file.

implementation 'com.nielsenappsdk.extension:${flavour}:${version}'

grade prior to 4.x

For gradle version previous to 4.x add below line inside dependencies section of build.gradle file.

compile 'com.nielsenappsdk.extension:${flavour}:${version}'

Adding Dependency

Below is an example for dependency

dependencies { ....
implementation 'com.nielsenappsdk.extension:global:1.0.0'
}

Ensuring you have the latest release information

It is recommended to use the most recent version of the NielsenSDK by using the following:

dependencies { ....
implementation 'com.nielsenappsdk:global:+'
}


In addition, please add below gradle task inside your build.gradle (Module:app) or build.gradle(Project:My-app) file to fetch latest release details of nielsen app sdk as below:

Please note: The build.gradle (Module:app) can overwrite the build.gradle(Project:My-app).

task NielsenSdkReleaseCheck {
   def login_details = project.property("nielsen_user")+":"+project.property("nielsen_authCode")
   def p = ['curl', '-u',login_details ,"https://raw.githubusercontent.com/NielsenDigitalSDK/nielsenappsdk-android/master/com/nielsenappsdk/global/NielsenAppSdk-ReadMe.md"].execute().text
   project.logger.log(LogLevel.ERROR,p)
}
preBuild.dependsOn('NielsenSdkReleaseCheck')

Sync

If you are finished with all previous steps then you can sync your build.gradle and after successful build you are ready to use nielsen app sdk library in your code.


Integration

To use nielsen app sdk extension in your android code you need to register your extension inside your Application class or very first activity like below. Please make sure that you register it only once in complete life cycle of your application.

//Register Nielsen extension and configure adobe launch mobile core
  MobileCore.setApplication(this);
  MobileCore.setLogLevel(LoggingMode.DEBUG); //Log level can be changed to your required one 

   //Register NielsenSdkExtension 
   NielsenSdkExtension.registerExtension();
   //Pass application context to NielsenSdkExtension
   NielsenSdkExtension.setApplicationContext(getApplicationContext());
   //Register notify listener to listen errors or messages informed by extension
   NielsenSdkExtension.registerNotifyEventListener(ExtensionErrorListener.class);
   Identity.registerExtension();
   Lifecycle.registerExtension();
   Signal.registerExtension();
   UserProfile.registerExtension();
   MobileCore.start(new AdobeCallback()
  {
       @Override
       public void call(Object o) 
       {
MobileCore.configureWithAppID("adobe launch configuration id");
       }
   });

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

//This function should be called to register extension
public static boolean registerExtension()

//This function should be called to set app context inside extension
public static void setApplicationContext(Context cntx)

//This function should be called to listen errors informed by extension
public static JSONObject registerNotifyEventListener(Class<T> extensionListenerClass)

//This function should be called to create app sdk instance with app info from launch configuration page
//This will return json object like {'identifier':'unique identifier', 'code':integer_error_code,'description':'string message'}
//Application should remember returned 'identifier' value for later use.
public static JSONObject instantiateSdkWithRemoteConfig()

//This function should be called to create app sdk instance with app info passed as argument
//This will return json object like {'identifier':'unique identifier', 'code':integer_error_code,'description':'string message'}
//Application should remember returned 'identifier' value for later use.
public static JSONObject instantiateSdkWithConfig(JSONObject appInfo)

//This function should be called to remove already created app sdk instance.
//Pass identifier received while creating app sdk instance
//This will return json object like {'code':integer_error_code,'description':'string message'}
public static JSONObject removeSdkInstance(String sdkId)

//This function should be called to pass metadata to app sdk instance.
//Pass identifier received while creating app sdk instance along with metadata
public static JSONObject trackSdkEvent(String sdkId, JSONObject eventData)

//This function should be called to get opt out status from app sdk instance.
//Pass identifier received while creating app sdk instance
//This function should be called on worker thread but not on main thread
//This will return json object like {'optout_status':1,'code':integer_error_code,'description':'string message'}
public static JSONObject getOptoutStatus(String sdkId)

//This function should be called to inform that app sdk is in foreground.
//Pass identifier received while creating app sdk instance
//This will return json object like {'code':integer_error_code,'description':'string message'}
public static JSONObject appInForeground(String sdkId)

//This function should be called to inform that app sdk is in background.
//Pass identifier received while creating app sdk instance
//This will return json object like {'code':integer_error_code,'description':'string message'}
public static JSONObject appInBackground(String sdkId)

//This function should be called to get demographic id from app sdk instance.
//Pass identifier received while creating app sdk instance
//This function should be called on worker thread but not on main thread
//This will return json object like {'demographic_id':'XXXXXXXXXX','code':integer_error_code,'description':'string message'}
public static JSONObject getDemographicId(String sdkId)

//This function should be called to set disable/enable state of app sdk.
//Pass identifier received while creating app sdk instance along with true/false
public static JSONObject appDisableApi(String sdkId, boolean disable)

//This function should be called to get app sdk's current disable state.
//Pass identifier received while creating app sdk instance
//This will return json object like {'app_disable':1,'code':integer_error_code,'description':'string message'}
public static JSONObject getAppDisable(String sdkId)

//This function should be called to get app sdk's opt out url string.
//Pass identifier received while creating app sdk instance
//This will return json object like {'optout_url':'url','code':integer_error_code,'description':'string message'}
public static JSONObject userOptOutURLString(String sdkId)

//This function should be called to get app sdk's version.
//This will return json object like {'meter_version':'6.1.0.1','code':integer_error_code,'description':'string message'}
public static JSONObject getMeterVersion()

//This function should be called to check if app sdk is valid or in-valid.
//Pass identifier received while creating app sdk instance
//This will return json object like {'is_valid':1,'code':integer_error_code,'description':'string message'}
public static JSONObject isValid(String sdkId)

//This function should be called to close app sdk instance.
//Pass identifier received while creating app sdk instance
public static JSONObject close(String sdkId)

//This function should be called to set debug level of app sdk .
//Pass debugLevel as 'w','d','e'
public static JSONObject setDebug(char debugState)

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:

AdobeCallback responseCallback = new AdobeCallback<Event>()
{
  @Override
  public void call(Event event)
  {
   }
};
ExtensionErrorCallback errorCallback = new ExtensionErrorCallback() {
  @Override
  public void error(Object o) {    
  }
};

HashMap eventData = new HashMap();
Event instantiateEvent = new Event.Builder(event name, NielsenSdkExtension.NielsenEventType, NielsenSdkExtension.NielsenEventSource).setEventData(eventData).build();
MobileCore.dispatchEventWithResponseCallback(instantiateEvent, responseCallback, errorCallback);

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:

public static final int ResultCodeSuccess = 5001;
public static final int ResultCodeUnknownError = 5002;
public static final int ResultCodeRemoteConfigNotAvailable = 5003;
public static final int ResultCodeInvalidAppInfo = 5004;
public static final int ResultCodeInvalidParameters = 5005;
public static final int ResultCodeSdkInstantiationError = 5006;
public static final int ResultCodeEventListenerRegistrationFailed = 5007;
public static final int ResultCodeExtensionRegistrationFailed = 5008;
public static final int ResultCodeExtensionNotRegistered = 5009;
public static final int ResultCodeInvalidSdkInstance = 5010;
public static final int ResultCodeExceptionOccurred = 5011;
public static final int ResultCodeInvalidEventData = 5012;
public static final int ResultCodeInvalidAppContext = 5013;

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:

JSONObject result = NielsenSdkExtension.instantiateSdkWithConfig(jsonObject);
JSONObject result = NielsenSdkExtension.instantiateSdkWithRemoteConfig();

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.

JSONObject result =  NielsenSdkExtension.removeSdkInstance("identifier");

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.

JSONObject result =  NielsenSdkExtension.trackSdkEvent(identifier);

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.

JSONObject result =  NielsenSdkExtension.getOptoutStatus("identifier");

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"
}

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.


JSONObject result =  NielsenSdkExtension.appDisableApi("identifier", true/false);

JSONObject result =  NielsenSdkExtension.getAppDisable("identifier");

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.


JSONObject result =  NielsenSdkExtension.setDebug('w'); //possible character values for debug level w,d,e etc.

Event

"SetDebugLevelEvent" There is no need to provide the identifier for "SetDebugLevelEvent" event, but put the debug level under the “debug_level” key in the JSON object and if it is needed to change the mode of the SDK to debug, provide the value of w,d,e for “debug_level” key:

{
"debug_level" : 'w'/'d'/'e'
}

Retrieving the Demographic Identifier

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

JSONObject result =  NielsenSdkExtension.getDemographicId("identifier");

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.

JSONObject result =  NielsenSdkExtension.userOptOutURLString("identifier");

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.

JSONObject result =  NielsenSdkExtension.getMeterVersion("identifier");

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:

{
public static JSONObject registerNotifyEventListener(Class<T> extensionListenerClass)
	...}

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.

{
public class AppEventListener extends ExtensionListener
{
    @Override
    public void hear(Event event)
    {
        //handle received event here...   
    }
}