var videoDomElement;
var adDomElement;
var adDisplayContainer;
var adsLoader;
var adsManager;
window.addEventListener('load', function(event) {
videoDomElement = document.getElementById('video-dom-element');
videoDomElement.setAttribute("currentTime", 0);
videoDomElement.addEventListener('click', Initialize);
adDomElement = document.getElementById('ad-dom-element');
});
function Initialize(event) {
adDisplayContainer = new google.ima.AdDisplayContainer(adDomElement, videoDomElement);
adDisplayContainer.initialize();
adsLoader = new google.ima.AdsLoader(adDisplayContainer);
adsLoader.addEventListener(google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,
onAdsManagerLoaded, false);
adsLoader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, onAdError, false);
var adsRequest = new google.ima.AdsRequest();
adsRequest.adTagUrl = 'https://x3.instreamatic.com/v3/vast/1218';
adsRequest.linearAdSlotWidth = 320;
adsRequest.linearAdSlotHeight = 50;
adsRequest.nonLinearAdSlotWidth = 320;
adsRequest.nonLinearAdSlotHeight = 50;
adsLoader.requestAds(adsRequest);
}
function onAdsManagerLoaded(adsManagerLoadedEvent) {
adsManager = adsManagerLoadedEvent.getAdsManager(videoDomElement);
adsManager.init(320, 50, google.ima.ViewMode.NORMAL);
adsManager.start();
// adsManager.addEventListener(google.ima.AdEvent.Type.STARTED, onAdStarted);
}
function onAdError(adErrorEvent) {
console.log(adErrorEvent.getError());
}
Hi Andrey,
Thank you for your response and for sharing this example. As per our documentation, by default companion ads are enabled for each ad request, explaining why the HTML resources for companions are being requested even without using the getCompanionAds method.
Regards,
Sherwin Diesta
IMA SDK Team