Skip to content

Commit

Permalink
triggers event before loading ad
Browse files Browse the repository at this point in the history
  • Loading branch information
karimMourra committed Feb 1, 2022
1 parent b968c5a commit 32c848f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 2 additions & 0 deletions modules/videoModule/constants/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export const allVideoEvents = [
CAST
];

export const AUCTION_AD_LOAD_ATTEMPT = 'auctionAdLoadAttempt';

// Param options
export const PLAYBACK_MODE = {
VOD: 0,
Expand Down
23 changes: 16 additions & 7 deletions modules/videoModule/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { config } from '../../src/config.js';
import events from '../../src/events.js';
import { allVideoEvents } from './constants/events.js';
import {allVideoEvents, AUCTION_AD_LOAD_ATTEMPT } from './constants/events.js';
import CONSTANTS from '../../src/constants.json';
import { videoCoreFactory } from './coreVideo.js';
import { coreAdServerFactory } from './adServer.js';
import find from 'core-js-pure/features/array/find.js';
import { vastXmlEditorFactory } from './shared/vastXmlEditor.js';


events.addEvents(allVideoEvents);

export function PbVideo(videoCore_, getConfig_, pbGlobal_, pbEvents_, videoEvents_, adServerCore_, vastXmlEditor_) {
Expand Down Expand Up @@ -76,15 +77,15 @@ export function PbVideo(videoCore_, getConfig_, pbGlobal_, pbEvents_, videoEvent
const videoConfig = adUnit.video;
const divId = videoConfig.divId;
const adServerConfig = videoConfig.adServer;
let adTagUrl;
let adUrl;
if (adServerConfig) {
adTagUrl = adServerCore.getAdTagUrl(adServerConfig.vendorCode, adUnit, adServerConfig.baseAdTagUrl);
adUrl = adServerCore.getAdTagUrl(adServerConfig.vendorCode, adUnit, adServerConfig.baseAdTagUrl);
}

const adUnitCode = adUnit.code;
const options = { adUnitCode };
if (adTagUrl) {
videoCore.setAdTagUrl(adTagUrl, divId, options);
if (adUrl) {
loadAdTag(adUrl, divId, options);
return;
}

Expand All @@ -94,9 +95,17 @@ export function PbVideo(videoCore_, getConfig_, pbGlobal_, pbEvents_, videoEvent
return;
}

adTagUrl = highestBid.vastUrl;
adUrl = highestBid.vastUrl;
options.adXml = highestBid.vastXml;
videoCore.setAdTagUrl(adTagUrl, divId, options);
options.winner = highestBid.bidder;
loadAdTag(adUrl, divId, options);
}

// options: adXml, winner, adUnitCode,
function loadAdTag(adUrl, divId, options) {
const payload = Object.assign({ adUrl }, options);
pbEvents.emit(AUCTION_AD_LOAD_ATTEMPT, payload);
videoCore.setAdTagUrl(adUrl, divId, options);
}

function addTrackingNodesToVastXml(bid, trackingConfig) {
Expand Down

0 comments on commit 32c848f

Please sign in to comment.