Google integration
If using Google as ad provider, it requires few additional steps.
- Follow Setup ad insertion
- A player that supports ad tracking
- Use Google as ad provider
1. Setup Google PAL SDK
- Android
- iOS & tvOS
- Web
The Google PAL SDK has to be included manually (not yet available on the Google official repository).
Find the latest version on the Google developer platform: https://developers.google.com/ad-manager/pal/android/
And add it as a local maven repository to your root build.gradle
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven {
url "https://delivery-platform.broadpeak.tv/android/repository/all"
}
// Google PAL local repository
maven {
url file("PATH_TO_PAL_SDK/GooglePAL")
}
}
}
Next, add the dependency to the build.gradle file of your app module. We highly recommend to use PAL SDK 17.1.0, please ask us if you need another version.
implementation 'com.google.android.gms:play-services-pal:17.1.0'
implementation 'com.google.android.gms:play-services-tasks:17.1.0'
Finally, add the rule to the proguard file
-keep class com.google.ads.interactivemedia.pal.* { *; }
-keep public interface com.google.ads.interactivemedia.pal.NonceGenerator$NonceGeneratorCallback { *; }
-keep class com.google.ads.interactivemedia.pal.NonceRequest$Builder { *; }
-keep interface com.google.android.gms.tasks.OnSuccessListener { *; }
-keep interface com.google.android.gms.tasks.OnFailureListener { *; }
-keep class com.google.android.gms.tasks.Task { *; }
The Google PAL SDK has to be included manually (not available through a repository).
Find the latest version on the Google developer platform:
- iOS: https://developers.google.com/ad-manager/pal/ios/
- tvOS: https://developers.google.com/ad-manager/pal/tvos/
And embed the framework to the application. We recommend to use PAL SDK 2.5.3, please ask us if you need another version.
iOS and tvOS 14+ require an extra authorization regarding the app tracking transparency. Please follow the documentation on the Google PAL SDK website (prepare for iOS/tvOS 14+ and app store data disclosure).
The Google PAL SDK has to be included manually (not available through a repository).
Find the latest version on the Google developer platform: https://developers.google.com/ad-manager/pal/html5/
And load the JS file to the application. We recommend to use PAL SDK 1.25.0, please ask us if you need another version.
2. Initialize the Google PAL SDK
- Android
- iOS & tvOS
- Web
First, you need to create a ConsentSettings and pass it to SmartLib. It has to be set before setPalParameters(...).
Find more details on the Google PAL documentation.
// The default value for allowStorage() is false, but can be
// changed once the appropriate consent has been gathered. The
// getConsentToStorage() method is a placeholder for the publisher's own
// method of obtaining user consent, either by integrating with a CMP or
// based on other methods the publisher chooses to handle storage consent.
boolean isConsentToStorage = getConsentToStorage();
ConsentSettings consentSettings = ConsentSettings.builder()
.allowStorage(isConsentToStorage)
.build();
AdManager.getInstance().setConsentSettings(consentSettings);
To enable nonce generation, the PAL parameters have to be initialized once, after SmartLib init.
If parameters are not yet known, set values to null.
Depending on your Google ad campaign, pal parameters may have to be set before each streaming session with ads.
/**
* Set Google PAL parameters
*
* @param descriptionURL Google PAL parameter, set null if not used
* @param partnerName Google PAL parameter, set null if not used
* @param partnerVersion Google PAL parameter, set null if not used
* @param omidVersion Google PAL parameter, set null if not used
* @param playerType Google PAL parameter, set null if not used
* @param playerVersion Google PAL parameter, set null if not used
* @param ppid Google PAL parameter, set null if not used
* @param videoPlayerHeight Google PAL parameter, set 0 if not used
* @param videoPlayerWidth Google PAL parameter, set 0 if not used
* @param willAdAutoPlay Google PAL parameter, set false if not used
* @param willAdPlayMuted Google PAL parameter, set false if not used
*/
AdManager.getInstance().setPalParameters(descriptionURL, partnerName, partnerVersion,
omidVersion, playerType, playerVersion, ppid,
videoPlayerHeight, videoPlayerWidth, willAdAutoPlay, willAdPlayMuted);
Parameters are reset when SmartLib release is called.
First, you need to set the PAL parameters. Parameters have to be initialized once, after SmartLib init.
If parameters are not yet known, set values to nil.
Depending on your Google ad campaign, PAL parameters may have to be set before each streaming session with ads.
/**
* Set Google PAL parameters
*
* @param descriptionURL Google PAL parameter, set nil if not used
* @param partnerName Google PAL parameter, set nil if not used
* @param partnerVersion Google PAL parameter, set nil if not used
* @param omidVersion Google PAL parameter, set nil if not used
* @param playerType Google PAL parameter, set nil if not used
* @param playerVersion Google PAL parameter, set nil if not used
* @param ppid Google PAL parameter, set nil if not used
* @param videoPlayerHeight Google PAL parameter, set 0 if not used
* @param videoPlayerWidth Google PAL parameter, set 0 if not used
* @param willAdAutoPlay Google PAL parameter, set false if not used
* @param willAdPlayMuted Google PAL parameter, set false if not used
*/
[[AdManager sharedManager] setPalParameters:descriptionURL
partnerName:partnerName
partnerVersion:partnerVersion
omidVersion:omidVersion
playerType:playerType
playerVersion:playerVersion
ppid:ppid
videoPlayerHeight:videoPlayerHeight
videoPlayerWidth:videoPlayerWidth
willAdAutoPlay:willAdAutoPlay
willAdPlayMuted:willAdPlayMuted];
Parameters are reset when SmartLib release is called.
First, attach the PAL SDK to SmartLib.
// goog is a global object registered with pal.js
AdManager.getInstance().attachPALSDK(goog);
Next, you need to create a ConsentSettings and pass it to SmartLib. It has to be set before setPalParameters(...).
Find more details on the Google PAL documentation.
// The default value for allowStorage() is false, but can be
// changed once the appropriate consent has been gathered. The
// getConsentToStorage() method is a placeholder for the publisher's own
// method of obtaining user consent, either by integrating with a CMP or
// based on other methods the publisher chooses to handle storage consent.
const isConsentToStorage = getConsentToStorage();
const consentSettings = new goog.pal.ConsentSettings();
consentSettings.allowStorage = isConsentToStorage;
AdManager.getInstance().setConsentSettings(consentSettings);
To enable nonce generation, the PAL parameters have to be initialized once, after SmartLib init.
If parameters are not yet known, set values to undefined.
Depending on your Google ad campaign, PAL parameters may have to be set before each streaming session with ads.
/**
* Set Google PAL parameters
*
* @param descriptionURL Google PAL parameter, set undefined if not used
* @param partnerName Google PAL parameter, set undefined if not used
* @param partnerVersion Google PAL parameter, set undefined if not used
* @param omidVersion Google PAL parameter, set undefined if not used
* @param playerType Google PAL parameter, set undefined if not used
* @param playerVersion Google PAL parameter, set undefined if not used
* @param ppid Google PAL parameter, set undefined if not used
* @param videoPlayerHeight Google PAL parameter, set 0 if not used
* @param videoPlayerWidth Google PAL parameter, set 0 if not used
* @param willAdAutoPlay Google PAL parameter, set false if not used
* @param willAdPlayMuted Google PAL parameter, set false if not used
*/
AdManager.getInstance().setPalParameters(descriptionURL, partnerName, partnerVersion,
omidVersion, playerType, playerVersion, ppid,
videoPlayerHeight, videoPlayerWidth, willAdAutoPlay, willAdPlayMuted);
Parameters are reset when SmartLib release is called.
3. Notify Google PAL SDK of user events
Most of PAL SDK events are handled automatically by SmartLib :
- sendAdImpression: Informs PAL that an ad click has occurred
- sendPlaybackStart: Informs PAL that playback has started
- sendPlaybackEnd: Informs PAL that playback has ended
The ad touch needs to be handled manually.
- Android
- iOS & tvOS
- Web
// Send touch when the player view is receiving a MotionEvent object
playerView.setOnTouchListener((view, motionEvent) -> {
session.adTouch(motionEvent);
return false;
});
The PAL SDK is requiring to access the view that show the ad (to add a gesture recognizer).
It has to be set before starting the session (i.e calling getURL).
/**
* Set ad view (PAL SDK)
* @param view view object
*/
[session setAdView:uiView];
// Send touch when the video element is clicked
videoElement.addEventListener('mousedown', (e) => onVideoTouch(e));
videoElement.addEventListener('touchstart', (e) => onVideoTouch(e));
function onVideoTouch(touchEvent) {
session.adTouch(touchEvent);
}
4. Full example
- Android
- iOS & tvOS
- Web
// Init SmartLib and Google PAL
SmartLib.getInstance().init(getApplicationContext(), ..., ..., ...);
// Set consent settings (if using Google)
boolean isConsentToStorage = getConsentToStorage();
ConsentSettings consentSettings = ConsentSettings.builder()
.allowStorage(isConsentToStorage)
.build();
AdManager.getInstance().setConsentSettings(consentSettings);
// Set Google PAL parameters at init (if using Google, to speed up first nonce generation)
AdManager.getInstance().setPalParameters(descriptionURL, partnerName, partnerVersion,
omidVersion, playerType, playerVersion, ppid,
videoPlayerHeight, videoPlayerWidth, willAdAutoPlay, willAdPlayMuted);
// Create a new session
StreamingSession session = SmartLib.getInstance().createStreamingSession();
// Attach the player
session.attachPlayer(player);
// Forward touch events to Google PAL
playerView.setOnTouchListener((view, motionEvent) -> {
session.adTouch(motionEvent);
return false;
});
// Listen to ad events
session.setAdEventsListener(new AdManager.AdEventsListener() {
@Override
public void onAdBreakBegin(AdBreakData adBreak) {
// Lock player controls
mControlsLayout.setClickable(false);
}
@Override
public void onAdBegin(AdData adData, AdBreakData adBreakData) {
// Show ad link button if needed
mAdLink.setVisible(View.VISIBLE);
mAdLink.setClickURL(clickURL); // on click, it will call session.adUserInteraction(AdInteractionType.CLICK);
}
@Override
public void onAdSkippable(AdData adData, AdBreakData adBreakData, long adSkippablePosition, long adEndPosition, long adBreakEndPosition) {
// Show the skip message/button "skip ad in x seconds"
mAdSkipMessage.setVisibility(View.VISIBLE);
}
@Override
public void onAdEnd(AdData adData, AdBreakData adBreakData) {
// Hide ad link and ad skip button
mAdLink.setVisible(View.GONE);
mAdSkipMessage.setVisibility(View.GONE);
}
@Override
public void onAdBreakEnd(AdBreakData adBreakData) {
// Hide ad link and ad skip button
mAdLink.setVisible(View.GONE);
mAdSkipMessage.setVisibility(View.GONE);
// Unlock player controls
mControlsLayout.setClickable(true);
}
});
...
// Start the session with/without ads
if (contentContainsAds) { // To be adapted
session.activateAdvertising();
// Set ad parameters
session.setAdParameter("name1", "value1");
session.setAdParameter("name2", "value2");
}
// You must not call getURL on the main thread !
// Because of generation duration of the nonce and technical requirements, it has to be done on another thread
StreamingSessionResult result = session.getURL(CONTENT_URL);
...
// Notify that the user opened the ad link
session.adUserInteraction(AdInteractionType.CLICK);
// Stop the session
session.stopStreamingSession();
...
// Init SmartLib
[SmartLib initSmartLib:... nanoCDNHost:... broadpeakDomainNames:...];
// Init PAL SDK (if using Google)
[[AdManager sharedManager] setPalParameters:descriptionURL
partnerName:partnerName
partnerVersion:partnerVersion
omidVersion:omidVersion
playerType:playerType
playerVersion:playerVersion
ppid:ppid
videoPlayerHeight:videoPlayerHeight
videoPlayerWidth:videoPlayerWidth
willAdAutoPlay:willAdAutoPlay
willAdPlayMuted:willAdPlayMuted];
// Create a session
StreamingSession *session = [SmartLib createStreamingSession];
// Attach the player
[session attachPlayer:player];
// Forward ad view to Google PAL
[session setAdView:player.uiView];
// Listen to ad events
[session setAdEventsListener:self];
...
// Start the session with/without ads
if (contentContainsAds) { // To be adapted
[session activateAdvertising];
[session setAdView:player.view]
// Set ad parameters
[session setAdParameter:@"name1" value:@"value1"];
[session setAdParameter:@"name2" value:@"value2"];
}
// Start the session
StreamingSessionResult *result = [session getURL:CONTENT_URL];
...
// Notify that the user opened the ad link
[session adUserInteraction:BPAdInteractionTypeClick];
// Stop the session
[session stopStreamingSession];
...
// Init SmartLib
SmartLib.getInstance().init(...);
// Attach PAL SDK (if using Google)
AdManager.getInstance().attachPALSDK(goog);
// Set consent settings (if using Google)
const isConsentToStorage = getConsentToStorage();
const consentSettings = new goog.pal.ConsentSettings();
consentSettings.allowStorage = isConsentToStorage;
AdManager.getInstance().setConsentSettings(consentSettings);
// Set Google PAL parameters at init (if using Google, to speed up first nonce generation)
AdManager.getInstance().setPalParameters(descriptionURL, partnerName, partnerVersion,
omidVersion, playerType, playerVersion, ppid,
videoPlayerHeight, videoPlayerWidth, willAdAutoPlay, willAdPlayMuted);
// Create a session
const session = SmartLib.getInstance().createStreamingSession();
// Forward touch events to Google PAL
videoElement.addEventListener('mousedown', (e) => onVideoTouch(e));
videoElement.addEventListener('touchstart', (e) => onVideoTouch(e));
// Attach the player
session.attachPlayer(player);
// Listen to ad events
session.setAdEventsListener({
onAdBreakBegin: (adBreakData) => {
// Lock player controls
},
onAdBegin: (adData, adBreakData) => {
// Show ad link button if needed
},
onAdSkippable: (adData, adBreakData, adSkippablePosition, adEndPosition, adBreakEndPosition) => {
// Show the skip message/button "skip ad in x seconds"
},
onAdEnd: (adData, adBreakData) => {
// Hide ad link, hide ad skip button
},
onAdBreakEnd: (adBreakData) => {
// Unlock player controls, hide ad link, hide ad skip button
}
});
...
// Start the session with/without ads
if (contentContainsAds) { // To be adapted
session.activateAdvertising();
// Set ad parameters
session.setAdParameter('name1', 'value1');
session.setAdParameter('name2', 'value2');
}
// Start the session
session.getURL(CONTENT_URL)
.then(result => {
...
});
...
// Notify that the user opened the ad link
session.adUserInteraction('click');
...
// Stop the session
session.stopStreamingSession();
...
function onVideoTouch(touchEvent) {
session.adTouch(touchEvent);
}