From b2081481fdf3c08416d6227245766171344fc079 Mon Sep 17 00:00:00 2001 From: Danijel Ristic Date: Fri, 25 Oct 2024 12:25:31 +0200 Subject: [PATCH 1/2] Add emqsegs support --- modules/targetVideoAdServerVideo.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/modules/targetVideoAdServerVideo.js b/modules/targetVideoAdServerVideo.js index 335fbcda730..3ce8e1ab843 100644 --- a/modules/targetVideoAdServerVideo.js +++ b/modules/targetVideoAdServerVideo.js @@ -34,6 +34,7 @@ export function buildVideoUrl(options) { const adUnit = options.adUnit; const bid = options.bid || targeting.getWinningBids(adUnit.code)[0]; const allTargetingData = getAllTargetingData(options); + const emqsegs = getEmetriqSegments(); const custParams = options.params.cust_params; let iu = options.params.iu; @@ -58,6 +59,10 @@ export function buildVideoUrl(options) { urlComponents.search.cust_params = Object.entries(custParams).map(([key, value]) => key + '%3D' + value).join('%26'); } + if (emqsegs) { + urlComponents.search.emqsegs = emqsegs; + } + return buildUrl(urlComponents); } @@ -72,6 +77,10 @@ export function buildVideoUrl(options) { search.cust_params = Object.entries(custParams).map(([key, value]) => key + '%3D' + value).join('%26'); } + if (emqsegs) { + search.emqsegs = emqsegs; + } + return buildUrl({ protocol: 'https', host: 'vid.tvserve.io', @@ -91,6 +100,10 @@ function getAllTargetingData(options) { return allTargetingData; } +function getEmetriqSegments() { + return window?._emqsegs; +} + registerVideoSupport('targetVideo', { buildVideoUrl, }); From 17b7961d2a7d23d9bb64746b75f801dc0e90e11b Mon Sep 17 00:00:00 2001 From: Danijel Ristic Date: Mon, 28 Oct 2024 10:42:49 +0100 Subject: [PATCH 2/2] Add unit test --- .../modules/targetVideoAdServerVideo_spec.js | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/test/spec/modules/targetVideoAdServerVideo_spec.js b/test/spec/modules/targetVideoAdServerVideo_spec.js index c4c2e34b73f..b66b6faca73 100644 --- a/test/spec/modules/targetVideoAdServerVideo_spec.js +++ b/test/spec/modules/targetVideoAdServerVideo_spec.js @@ -45,10 +45,12 @@ describe('TargetVideo Ad Server Video', function() { }, }; adUnit = utils.deepClone(AD_UNIT); + window._emqsegs = null; }); afterEach(() => { sandbox.restore(); + window._emqsegs = null; }); it('should return undefined if required properties are missing', () => { @@ -176,4 +178,50 @@ describe('TargetVideo Ad Server Video', function() { getWinningBidsStub.restore(); getAllTargetingDataStub.restore(); }); + + it('should include emqsegs parameter when window._emqsegs is present', () => { + const optionsUrl = { + params: { ...unitUrl } + }; + + const optionsId = { + params: { ...unitId } + }; + + window._emqsegs = '1,2,3,4,5'; + + const getWinningBidsStub = sandbox.stub(targeting, 'getWinningBids').returns([bid]); + const getAllTargetingDataStub = sandbox.stub(targeting, 'getAllTargeting').returns(allTargeting); + + const url1 = buildVideoUrl(Object.assign(optionsUrl, { bid, adUnit })); + const url2 = buildVideoUrl(Object.assign(optionsId, { bid, adUnit })); + + expect(url1).to.include('emqsegs=1,2,3,4,5'); + expect(url2).to.include('emqsegs=1,2,3,4,5'); + + getWinningBidsStub.restore(); + getAllTargetingDataStub.restore(); + }); + + it('should not include emqsegs parameter when window._emqsegs is not present', () => { + const optionsUrl = { + params: { ...unitUrl } + }; + + const optionsId = { + params: { ...unitId } + }; + + const getWinningBidsStub = sandbox.stub(targeting, 'getWinningBids').returns([bid]); + const getAllTargetingDataStub = sandbox.stub(targeting, 'getAllTargeting').returns(allTargeting); + + const url1 = buildVideoUrl(Object.assign(optionsUrl, { bid, adUnit })); + const url2 = buildVideoUrl(Object.assign(optionsId, { bid, adUnit })); + + expect(url1).to.not.include('emqsegs'); + expect(url2).to.not.include('emqsegs'); + + getWinningBidsStub.restore(); + getAllTargetingDataStub.restore(); + }); });