gpt4 book ai didi

javascript - 适用于 JavaScript 的 Google IMA SDK 重叠式广告和全幅广告引用

转载 作者:搜寻专家 更新时间:2023-10-31 08:15:14 25 4
gpt4 key购买 nike

我已经在使用 Google IMA HTML5 SDK API用于在我们自制的播放器中显示全幅广告。

现在,我正尝试在同一个 API 中添加重叠式广告,但找不到相关文档。在FAQ是指向 technical quick start guide 的链接,但事实证明它是为 Flash ActionScript 制作的 - 但我需要相同的 HTML5/JavaScript 指南。

如何使用 HTML5/JavaScript 实现 Google 重叠式广告和全幅广告?


更新

这是我当前针对两个不同广告请求的 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;
}());

最佳答案

全幅广告以全屏呈现,带有一个跳过按钮。您确定要同时呈现覆盖横幅吗?

您需要两个 adsManager 实例:一个用于全幅广告,一个用于叠加广告。在需要的时间发出两个广告请求,但在各自的 adsManager 实例中呈现每个请求。从理论上讲,您应该首先呈现全幅广告,这样叠加层就可以呈现在全幅广告之上。但是,请谨慎对待它,因为它可能会对多个对象和多个生命周期造成困惑。另外,请务必向政策团队说明这一点,因为我不确定叠加广告是否符合政策。

关于javascript - 适用于 JavaScript 的 Google IMA SDK 重叠式广告和全幅广告引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40484274/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com