Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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