4

I'm already using the Google IMA HTML5 SDK API for displaying a fullslot ad in our self-made player.

Now, I'm trying to add an overlay ad within the same API, but I can't find the documentation for that. In the FAQ is a link to a technical quick start guide, but it turns out that it is made for Flash ActionScript - but I need the same guide for HTML5/JavaScript.

How do I implement both, a Google overlay AND fullslot ad with HTML5/JavaScript?


Update

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

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;
}());
Simon Ferndriger
  • 4,455
  • 6
  • 28
  • 53

1 Answers1

3

Fullslot ads are rendered full-screen, with a skip button. Are you sure you want to render an overlay banner at the same time?

You would need two adsManager instances: one for your fullslot, and one for the overlay. At the desired time, send out the two ad requests, but render each in its own adsManager instance. Theoretically you would render the fullslot ad first, so that the overlay can be rendered on top of the fullslot ad. However, take that with a pinch of salt, because it can be messy with multiple objects and multiple lifecycles. Also, make sure you clear that with the Policy team, because I'm not sure if overlaying an ad is policy-compliant.

andzrev
  • 544
  • 1
  • 6
  • 17
  • You are right of course, they are not displayed at the same time. – Simon Ferndriger Nov 14 '16 at 09:55
  • I duplicated everything now beginning with the `google.img.AdsLoader`. However, I always get the message the the ad is empty even though the VAST url (https://pubads.g.doubleclick.net/gampad/ads?ad_type=image_text_flash_video&sz=320x60|468x60|728x90&iu=/22152718/Lookr_in-video_overlay&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]&overlay=1) was tested and should deliver ads. I updated my question to show you which JavaScript I currently use to create the two ad requests. – Simon Ferndriger Nov 14 '16 at 10:21
  • If the server returns empty VAST, it's because it thinks the ad requests are duplicated. Make sure you destroy your respective adsManager instance **and** call `contentComplete` on your adsLoader before you make your new ad request. Doing that resets the SDK, and make your ad requests look legitimate to the server. – andzrev Nov 14 '16 at 15:24
  • Thanks. However, calling `contentComplete` didn't change anything. The overlay was the first ad to call anyway, the fullsize is a postroll (which still works fine) and gets called afterwards. However, for testing purposes I even disabled the postroll fullsize ad, didn't change anything either. By the way, I think the `contentComplete` is only needed for postroll ads *"This will allow the SDK to play post-roll ads."* - I now inserted the full JavaScript code I use to manage both ads into my question, can you perhaps have a quick look? – Simon Ferndriger Nov 16 '16 at 11:51
  • Today is your last chance to get the bounty if your are still interested in helping me out here – Simon Ferndriger Nov 18 '16 at 09:36
  • @SimonFerndriger, your nonlinear overlay ad tag isn't returning anything if you load it in a browser itself. Seems to be a serving issue on the server side - you might need to either generate another ad tag, or request with a more relaxed configuration. – andzrev Nov 18 '16 at 14:42
  • I first thought too that I need another ad tag, but they even let the Google team have a look at it and they said that the ad tag was just fine: *"I’ve checked the line item #117343278 and creative settings, they look fine to me. Also, there isn’t any need to create a special ad unit for the overlay to serve on the page."* – Simon Ferndriger Nov 21 '16 at 15:49
  • Can you give me an example of a *"more relaxed configuration"* for the ad request? I'm not sure what you mean by that. – Simon Ferndriger Nov 21 '16 at 15:50