Google IMA SDK Overlay & Fullslot Link for JavaScript

I am already using the Google IMA HTML5 SDK API to display a full-text ad in our homemade player.

Now I am trying to add an overlay ad within the same API, but I can not find the documentation for this. The Frequently Asked Questions is a link to a quick start technical guide , but it turns out that it was created for Flash ActionScript, but I need the same way for HTML5 / JavaScript.

How to implement both Google overlay and full-text ad with HTML5 / JavaScript?


Update

This is my current JavaScript code for two different ad requests (it always returns an empty overlay ad right now, so it still doesn't work):

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;
}());
Run codeHide result
+4
source share
2 answers
+1
source

Fullslot ads are displayed in full screen using the skip button. Are you sure you want to display the overlay banner at the same time?

adsManager: . , adsManager. fullslot, . , , . , , Policy, , .

+3

Source: https://habr.com/ru/post/1660168/


All Articles