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 $_ = { //SnigelWeb: AdX for Video Product (HTML5 Full-Slot Ads) adTagPostroll: 'https://pubads.g.doubleclick.net/gampad/ads?sz=400x300|640x480&iu=/22152718/Lookr_640x480_Video_Vast&ciu_szs=300x250,310x260,336x280&impl=s&gdfp_req=1&env=vp&output=vast&unviewed_position_start=-1&url=[referrer_url]&description_url= http%3A%2F%2Flookr.com &correlator=[timestamp]', };
//--------------------------------------------------------------- // _ //--------------------------------------------------------------- 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; _.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;}());
I am sending my ad request based on user clicks, but you can do it based on other factors (such as timestamps, other events, etc.). I put together a live demo here.if (adsManager != null) {console.log("adsManager is active. Destroying...");adsManager.destroy();adsLoader.contentComplete();}var adsRequest = new google.ima.AdsRequest();adsRequest.linearAdSlotWidth = 640;adsRequest.linearAdSlotHeight = 400;adsRequest.nonLinearAdSlotWidth = 640;adsRequest.nonLinearAdSlotHeight = 150;switch (adType) {case "overlay":adsRequest.adTagUrl = overlayTag;break;case "fullslot":adsRequest.adTagUrl = fullslotTag;adsRequest.forceNonLinearFullSlot = true;break;}adsLoader.requestAds(adsRequest);
By default, non-linear overlays will always be rendered at the bottom of the video player screen. To enable customization, you need to turn autoAlign on your adsRenderingSettings to false. By turning it to false, the SDK will render the nonlinear overlay at 0,0 of the adsContainer div, which means you have the freedom to position the div yourself. The demo has been updated to reflect this so be sure to check out the new logic.
Right now, I'm actually using two adsContainer div's - one for the nonlinear, and one for everything else. Once you start moving the nonlinear container around, if you use the same div for your fullslot or linear ad, the ad is going to look off (because we are moving the actual container rather than moving the nonlinear overlay image). Having two adsContainer div's gives more flexibility.
You can set useStyledNonLinearAds on your adsRenderingSettings to true. With that setting, the ad will have a close and recall button. I have updated the demo to reflect the change.
I'm not sure what you meant by this, so feel free to elaborate on this request.
// Initialize the container. Must be done via a user action on mobile devices.
PS: The text banners do have a nice shadow prerendered already, is it possible to opt-in a shadow for display banners also?
2) LinearAd Height
Also, what I wanted to ask you (again), is why you chose 150(px) as height for the overlay?
adsRequest.nonLinearAdSlotHeight = 150;
if (!ad.isLinear()) {
videoContent.play();
// If the ad is a nonlinear overlay, we want to the adsManager to have roughly the same size
// so that it won't occupy other UI elements nearby outside the video player.
adsManager.resize(ad.getWidth() + 10, ad.getHeight() + 10, google.ima.ViewMode.NORMAL);
}
<fon