From a54d7ba3c3fee52d70fb2217ff12f8ab9674d08d Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Tue, 30 Jan 2024 13:33:57 -0800 Subject: [PATCH] Video module: log error when adUnit provides unknown player div ID (#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 --- modules/videoModule/coreVideo.js | 5 ++++- modules/videoModule/index.js | 19 ++++++++++++++++++- test/spec/modules/videoModule/pbVideo_spec.js | 4 +++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/modules/videoModule/coreVideo.js b/modules/videoModule/coreVideo.js index ce66acc2b02..fc54d0d0b98 100644 --- a/modules/videoModule/coreVideo.js +++ b/modules/videoModule/coreVideo.js @@ -218,7 +218,10 @@ export function VideoCore(parentModule_) { getOrtbContent, setAdTagUrl, onEvents, - offEvents + offEvents, + hasProviderFor(divId) { + return !!parentModule.getSubmodule(divId); + } }; } diff --git a/modules/videoModule/index.js b/modules/videoModule/index.js index b9cba60594d..bfb239210db 100644 --- a/modules/videoModule/index.js +++ b/modules/videoModule/index.js @@ -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 { @@ -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; @@ -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); diff --git a/test/spec/modules/videoModule/pbVideo_spec.js b/test/spec/modules/videoModule/pbVideo_spec.js index 2e26737da40..1ccd9766eab 100644 --- a/test/spec/modules/videoModule/pbVideo_spec.js +++ b/test/spec/modules/videoModule/pbVideo_spec.js @@ -1,3 +1,4 @@ +import 'src/prebid.js'; import { expect } from 'chai'; import { PbVideo } from 'modules/videoModule'; import CONSTANTS from 'src/constants.json'; @@ -26,7 +27,8 @@ function resetTestVars() { onEvents: sinon.spy(), getOrtbVideo: () => ortbVideoMock, getOrtbContent: () => ortbContentMock, - setAdTagUrl: sinon.spy() + setAdTagUrl: sinon.spy(), + hasProviderFor: sinon.spy(), }; getConfigMock = () => {}; requestBidsMock = {