Logo

Application collectors

MediaTailor Ad Framework

For the IOS / tvOS Collector with AVPlayer Media Player v3

The MediaTailor Ad Framework Extension is a configuration option for the IOS / tvOS Collector by Datazoom when it is configured with the AVPlayer Media Player v3 to make the following additional data points automatically collectable in real time.

Integration Instructions

Prerequisites

  • Add dependencies.
  • Procure a MediaTailor session-init URL or ad-tracking URL.
  • Configure the Datazoom collector.

Add dependencies

Swift Package Manager

To install DzAVPlayerAdapter and DzMediaTailorAdapter using Swift Package Manager you can follow the tutorial published by Apple using the URL for the DzAVPlayerAdapter and DzMediaTailorAdapter repos with the current version:

  1. In Xcode, select “File” → “Add Packages...”
  2. Enter https://gitlab.com/datazoom/apple/libraries-release/apple_dz_avplayer_adapter for DzAVPlayerAdapter
  3. Enter https://gitlab.com/datazoom/apple/libraries-release/apple_dz_mediatailor_adapter for DzMediaTailorAdapter

CocoaPods

Add the pod to your Podfile:

source 'https://gitlab.com/datazoom/pod-specs.git'
pod 'DzAVPlayerAdapter'
pod 'DzMediaTailorAdapter'

Google PAL SDK

Make sure to integrate Google PAL SDK for ios and tvos.

Note:

To successfully build and run the project, it is required to integrate the Google Programmatic Access Library (PAL) SDK for both iOS and tvOS. These dependencies are not optional. Without them, the project will fail to compile.

Procure a MediaTailor session-init URL or ad-tracking URL

In most common cases the client application initiates the initialization of MediaTailor playback sessions using a session-init URL (specific to a given content) procured through MediaTailor's services. The session-init URLs are in the following format:

HLS:

https://<mediatailorURL>/v1/session/<hashed-account-id>/<origin-id>/<asset-id>.m3u8

MPEG-DASH:

https://<mediatailorURL>/v1/session/<hashed-account-id>/<origin-id>/<asset-id>.mpd

Alternatively, the client application may utilize a third-party web service to handle the MediaTailor session initialization on its behalf. In such a case, the client application will receive both a content-playback URL and an ad-tracking URL from the web service. The former should be handed to a player to start playback, while the latter should be used in a step described later in this document.

Please refer to MediaTailor's ad-reporting-client-side page for detailed information.

Configure the Datazoom collector

The Datazoom collector must be initialized, with a Datazoom configuration ID, before its functionalities become available. Please refer to Datazoom's platform guide on how to set up a configuration and receive the ID. Once the Datazoom configuration ID is procured, follow Datazoom's collector initialization tutorial to finish configuring the collector.

Create a media player instance and the associated Datazoom collector context

The process of creating a media player instance and the associated Datazoom collector context is specific to the kind of media player chosen by the client application. Please refer to Datazoom's player integration tutorial for instructions.

For example, if AVPlayer is the chosen media player:

let player = AVPlayer()
let datazoomContext = Datazoom.shared.createContext(player)

Some media players require the content playback URL being passed as a parameter for creating instances. If so, use the value of the session.playbackUrl property for this purpose.

Configure the MediaTailor SDK

The MediaTailor SDK provides some global configuration options, such as:

For example, to output more debug log information:

MediaTailor.shared.setLogLevel(LogLevel.DEBUG)

To enable Google PAL SDK integration:

import MediaTailorSDK

let palConsentSettings = PalConsentSettings.Builder()
    .allowStorage(value: true) // Note that this value must be based on user consents
    .directedForChildOrUnknownAge(value: false)
    .build()

MediaTailor.shared.initPal(consentSettings: palConsentSettings)

Please note that it's the application's responsibility to obtain user consent in order to set the settings like allowStorage accordingly.

MediaTailor Session Initialization

The process to initialize a MediaTailor playback session (with client-side ad tracking support) involves the following steps:

  • Prepare a MediaTailor SessionConfiguration builder.
  • Add Google PAL nonce-request parameters (optional).
  • Add other optional configurations.
  • Create a MediaTailor Session object.

Prepare a MediaTailor SessionConfiguration builder

The MediaTailor session initialization can be done through either a session-init URL or an ad-tracking URL. In both cases, a SessionConfiguration builder should be created with the corresponding method invoked to set the URL procured through MediaTailor's services. As demonstrated below.

With session-init URL (common use cases):

import MediaTailorSDK

let configBuilder = SessionConfiguration.Builder().sessionInitUrl(value: sessionInitUrl)

With ad-tracking URL (use cases with third-party web services):

import MediaTailorSDK

let configBuilder = SessionConfiguration.Builder().trackingUrl(value: trackingUrl)

Add Google PAL nonce-request parameters (optional)

Optionally, to leverage the Google PAL SDK, add Google PAL nonce-request parameters to the MediaTailor SessionConfiguration builder as demonstrated below:

let palNonceRequestParams = PalNonceRequestParams.Builder()
    .adWillAutoPlay(value: true)
    .adWillPlayMuted(value: false)
    .descriptionUrl(value: "https://example.com/content1")
    .iconsSupported(value: true)
    .playerType(value: "ExamplePlayerType")
    .playerVersion(value: "1.0.0")
    .ppid(value: "12JD92JD8078S8J29SDOAKC0EF230337")
    .videoHeight(value: 480)
    .videoWidth(value: 640)
    .omidPartnerName(value: "amazon2")
    .omidPartnerVersion(value: "1.0.0")
    .build()

configBuilder.palNonceRequestParams(value: palNonceRequestParams)

For the omidPartnerName and omidPartnerVersion parameters, as shown in the example above, the corresponding values can be retrieved from

datazoomContext?.omidPartnerInfo.version
datazoomContext?.omidPartnerInfo.name

Please note that it's important to invoke the MediaTailor.initPal() method before creating MediaTailor sessions that are intended to be integrated with Google PAL SDK.

If the MediaTailor SessionConfiguration builder was created with an ad-tracking URL (instead of a session-init URL), enabling Google PAL SDK and adding nonce-request parameters will not have any effects since the actual session initialization request (to which the PAL SDK nonce is attached) was performed outside the control of the MediaTailor SDK.

Add other optional configurations

The MediaTailor SessionConfiguration builder has more configuration methods defined as documented in the API reference of SessionConfiguration.

Create a MediaTailor Session object

With the MediaTailor SessionConfiguration builder prepared in the steps above, create a MediaTailor Session object as demonstrated below:

let configBuilder = ....

private func onSessionCreationOK(session: Session) {
    ....
}

private func onSessionCreationError(error: SessionError) {
    ....
}

MediaTailor.shared.createSession(config: configBuilder.build(), callback: { session, error in
    if (error == nil) {
        onSessionCreationOK(session)
    }
    else {
        onSessionCreationError(error)
    }
}

When the asynchronous process is completed, the MediaTailor.createSession() method invokes the callback function specified by the caller. If successful, a Session object is created and passed as an argument to the callback function. Otherwise, an error object is provided (also as a callback function argument). The Session object represents a MediaTailor playback session and provides methods to interact with the session and observe session status.

Please note that the callback function invocation is always through the main UI thread.

Manage the MediaTailor Session

Once the MediaTailor session is created, the following steps should be taken to manage the session:

  • Create a media player instance and the associated Datazoom collector context.
  • Link the MediaTailor session object with the Datazoom collector context.
  • Set up playback of the content.
  • Listen to UI events related to the MediaTailor session.

For the MediaTailor SDK to track ads effectively, it needs to have timely access to the media player's playback progress and other information. The Datazoom collector context serves an essential role in facilitating this communication. Therefore, it's important to link the MediaTailor session object with the Datazoom collector context, by invoking the Datazoom context's setupAdSession() method, as demonstrated below:

import DzMediaTailorAdapter
import MediaTailorSDK

func onSessionCreationOK(session: Session) {
    ....
    datazoomContext.setupAdSession(session, playerView, contentUrl)
    ....
}

Set up playback of the content

The process of setting the content playback URL and initiate playback is specific to the kind of media player chosen by the client application. In all cases, the content playback URL is retrieved from the session.playbackUrl property, but the method of playback URL assignment differs among player vendors. Please refer to the player vendor's documentation or Datazoom's player integration tutorial for instructions.

Please note that if a third-party web service is used to perform session initialization, the session.playbackUrl property will be null and the application should set up content playback based on information derived from the third-party web service.

The MediaTailor SDK defines several listener events observable from a MediaTailor session object. They are useful for implementing ad-related UI features. Each listener event callback is invoked with a SessionUiEventData argument which provides detailed information about the current ad. The listener event definitions are listed in the API reference of SessionUiEvent.

As demonstrated below, the client application can register various callback functions for these listener events:

private func onSessionCreationOK(session: Session) {
    ....
    session.addUiEventListener(event: SessionUiEvent.adStart) { event, eventData in
        ....
    }
    session.addUiEventListener(event: SessionUiEvent.adEnd) { event, eventData in
        ....
    }
    session.addUiEventListener(event: SessionUiEvent.adProgress) { event, eventData in
        ....
    }
    session.addUiEventListener(event: SessionUiEvent.adClick) { event, eventData in
        ....
    }
    session.addUiEventListener(event: SessionUiEvent.adCanSkip) { event, eventData in
        ....
    }
    session.addUiEventListener(event: SessionUiEvent.adIncoming) { event, eventData in
        ....
    }
    session.addUiEventListener(event: SessionUiEvent.NonlinearAdStart) { event, eventData in
        ....
    }
    session.addUiEventListener(event: SessionUiEvent.NonlinearAdEnd) { event, eventData in
        ....
    }
    session.addUiEventListener(event: SessionUiEvent.adTrackingInfoResponse) { event, eventData in
        ....
    }
    ....
}

Fluxdata

Metrics measuring changing parameters over time