Skip to content

Commit

Permalink
Video module: log error when adUnit provides unknown player div ID (#…
Browse files Browse the repository at this point in the history
…10664)

* Video module: log error when adUnit provides unknown player div ID

* moves error logging to separate function

* remove trailing spaces

* Update modules/videoModule/coreVideo.js

---------

Co-authored-by: Karim Mourra <karim@jwplayer.com>
  • Loading branch information
dgirardi and karimMourra authored Jan 30, 2024
1 parent 2592706 commit ad85b03
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
5 changes: 4 additions & 1 deletion modules/videoModule/coreVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ export function VideoCore(parentModule_) {
getOrtbContent,
setAdTagUrl,
onEvents,
offEvents
offEvents,
hasProviderFor(divId) {
return !!parentModule.getSubmodule(divId);
}
};
}

Expand Down
19 changes: 18 additions & 1 deletion modules/videoModule/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { config } from '../../src/config.js';
import { find } from '../../src/polyfill.js';
import * as events from '../../src/events.js';
import { mergeDeep, logWarn } from '../../src/utils.js';
import {mergeDeep, logWarn, logError} from '../../src/utils.js';
import { getGlobal } from '../../src/prebidGlobal.js';
import CONSTANTS from '../../src/constants.json';
import {
Expand Down Expand Up @@ -99,6 +99,7 @@ export function PbVideo(videoCore_, getConfig_, pbGlobal_, pbEvents_, videoEvent
return { init, renderBid, getOrtbVideo, getOrtbContent };

function beforeBidsRequested(nextFn, bidderRequest) {
logErrorForInvalidDivIds(bidderRequest);
enrichAuction(bidderRequest);

const bidsBackHandler = bidderRequest.bidsBackHandler;
Expand All @@ -109,6 +110,22 @@ export function PbVideo(videoCore_, getConfig_, pbGlobal_, pbEvents_, videoEvent
return nextFn.call(this, bidderRequest);
}

function logErrorForInvalidDivIds(bidderRequest) {
const adUnits = bidderRequest.adUnits || pbGlobal.adUnits || [];
adUnits.forEach(adUnit => {
const video = adUnit.video;
if (!video) {
return;
}
if (!video.divId) {
logError(`Missing Video player div ID for ad unit '${adUnit.code}'`);
}
if (!videoCore.hasProviderFor(video.divId)) {
logError(`Video player div ID '${video.divId}' for ad unit '${adUnit.code}' does not match any registered player`);
}
});
}

function enrichAuction(bidderRequest) {
if (mainContentDivId) {
enrichOrtb2(mainContentDivId, bidderRequest);
Expand Down
4 changes: 3 additions & 1 deletion test/spec/modules/videoModule/pbVideo_spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'src/prebid.js';
import { expect } from 'chai';
import { PbVideo } from 'modules/videoModule';
import CONSTANTS from 'src/constants.json';
Expand Down Expand Up @@ -26,7 +27,8 @@ function resetTestVars() {
onEvents: sinon.spy(),
getOrtbVideo: () => ortbVideoMock,
getOrtbContent: () => ortbContentMock,
setAdTagUrl: sinon.spy()
setAdTagUrl: sinon.spy(),
hasProviderFor: sinon.spy(),
};
getConfigMock = () => {};
requestBidsMock = {
Expand Down

0 comments on commit ad85b03

Please sign in to comment.