自作のプレーヤーでフルスロット広告を表示するために、すでにGoogle IMA HTML5 SDK APIを使用しています。
現在、同じ API 内にオーバーレイ広告を追加しようとしていますが、そのドキュメントが見つかりません。FAQにテクニカル クイック スタート ガイドへのリンクがありますが、Flash ActionScript 用に作成されていることがわかりました。しかし、HTML5/JavaScript 用の同じガイドが必要です。
HTML5/JavaScript で Google オーバーレイ広告とフルスロット広告の両方を実装するにはどうすればよいですか?
アップデート
これは、2 つの異なる広告リクエストに対する現在の JavaScript コードです (現在、オーバーレイに対して常に空の広告を返すため、まだ機能しません)。
var google = google || {
ima: 'blocked'
}; //AdBlocker
/*
#################################################################
# #
# Required: Google IMA SDK for HTML5 #
# #
#################################################################
*/
wct.videoads = (function() {
'use strict';
//---------------------------------------------------------------
// AdBlocker
//---------------------------------------------------------------
if (google.ima == 'blocked')
return function() {};
//---------------------------------------------------------------
// $_
//---------------------------------------------------------------
var $_ = {
// (HTML5 Full-Slot Ads)
adTagPostroll: '[url removed]',
adTagOverlay: '[url removed]'
};
//---------------------------------------------------------------
// _
//---------------------------------------------------------------
var _ = {
adsManagerOverlay: {
destroy: function() {},
resize: function() {}
},
adsManagerPostRoll: {
destroy: function() {},
resize: function() {}
},
height: 0,
onError: function() {},
width: 0
};
//---------------------------------------------------------------
// :
var createAds = function($container, width, height) {
//---------------------------------------------------------------
_.height = height;
_.width = width;
//¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
// Init
//¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
google.ima.settings.setLocale(LANGUAGE.id);
var adDisplayContainer = new google.ima.AdDisplayContainer($container.get(0));
adDisplayContainer.initialize();
var adsLoaderPostRoll = new google.ima.AdsLoader(adDisplayContainer);
var adsLoaderOverlay = new google.ima.AdsLoader(adDisplayContainer);
var postRollRequest = new google.ima.AdsRequest();
var overlayRequest = new google.ima.AdsRequest();
postRollRequest.adTagUrl = $_.adTagPostroll;
postRollRequest.linearAdSlotWidth = width;
postRollRequest.linearAdSlotHeight = height;
postRollRequest.nonLinearAdSlotWidth = width;
postRollRequest.nonLinearAdSlotHeight = height;
postRollRequest.forceNonLinearFullSlot = true;
overlayRequest.adTagUrl = $_.adTagOverlay;
overlayRequest.linearAdSlotWidth = width;
overlayRequest.linearAdSlotHeight = height;
overlayRequest.nonLinearAdSlotWidth = width;
overlayRequest.nonLinearAdSlotHeight = height;
overlayRequest.forceNonLinearFullSlot = false;
//¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
// LOCAL Events
//¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
adsLoaderPostRoll.addEventListener(
google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,
onAdsManagerPostRollLoaded,
false
);
adsLoaderPostRoll.addEventListener(
google.ima.AdErrorEvent.Type.AD_ERROR,
onAdErrorPostRoll,
false
);
adsLoaderOverlay.addEventListener(
google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,
onAdsManagerOverlayLoaded,
false
);
adsLoaderOverlay.addEventListener(
google.ima.AdErrorEvent.Type.AD_ERROR,
onAdErrorOverlay,
false
);
//¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
// :
var startOverlay = function(options) {
//¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
var options = options || {};
adsLoaderOverlay.contentComplete();
adsLoaderOverlay.requestAds(overlayRequest);
_.onErrorOverlay = options.onEmpty || function() {};
};
//¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
// :
var startPostRoll = function(details) {
//¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
return;//postroll is disabled for the moment to avoid any possible conflict with the overlay
_.onContentPauseRequested = details.onAdStart;
_.onContentResumeRequested = details.onAdFinish;
adsLoaderPostRoll.requestAds(postRollRequest);
_.onErrorPostRoll = details.onEmpty || function() {};
};
//¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
// >
//¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
return {
startOverlay: startOverlay,
startPostRoll: startPostRoll,
resize: resize
};
};
//---------------------------------------------------------------
// :
var onAdErrorOverlay = function(adErrorEvent) {
//---------------------------------------------------------------
_.onErrorOverlay();
console.warn(adErrorEvent.getError());
// _.adsManagerOverlay.destroy();
};
//---------------------------------------------------------------
// :
var onAdErrorPostRoll = function(adErrorEvent) {
//---------------------------------------------------------------
_.onErrorPostRoll();
console.warn(adErrorEvent.getError());
// _.adsManagerPostRoll.destroy();
};
//---------------------------------------------------------------
// :
var onAdsManagerOverlayLoaded = function(adsManagerLoadedEvent) {
//---------------------------------------------------------------
console.debug('overlay ad loaded:');
console.log(adsManagerLoadedEvent);
};
//---------------------------------------------------------------
// :
var onAdsManagerPostRollLoaded = function(adsManagerLoadedEvent) {
//---------------------------------------------------------------
_.adsManagerPostRoll = adsManagerLoadedEvent.getAdsManager(document.createElement('video'));
_.adsManagerPostRoll.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, onAdError);
_.adsManagerPostRoll.addEventListener(google.ima.AdEvent.Type.CONTENT_PAUSE_REQUESTED, _.onContentPauseRequested);
_.adsManagerPostRoll.addEventListener(google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED, _.onContentResumeRequested);
_.adsManagerPostRoll.addEventListener(google.ima.AdEvent.Type.LOADED, function(event) {});
try {
_.adsManagerPostRoll.init(_.width, _.height, google.ima.ViewMode[$(document).fullScreen() ? 'FULLSCREEN' : 'NORMAL']);
// Call start to show ads. Single video and overlay ads will
// start at this time; this call will be ignored for ad rules, as ad rules
// ads start when the adsManager is initialized.
_.adsManagerPostRoll.start();
} catch (adError) {
console.error(adError);
}
};
//---------------------------------------------------------------
// :
var resize = function(width, height) {
//---------------------------------------------------------------
_.adsManagerPostRoll.resize(width, height, google.ima.ViewMode[$(document).fullScreen() ? 'FULLSCREEN' : 'NORMAL']);
};
//---------------------------------------------------------------
// >
//---------------------------------------------------------------
return createAds;
}());