From 8aecf19a57b7d7e1c3829d500043d834fc31cd3d Mon Sep 17 00:00:00 2001 From: TheMediaGrid <44166371+TheMediaGrid@users.noreply.github.com> Date: Thu, 14 Jul 2022 17:07:36 +0300 Subject: [PATCH] TheMediaGrid: added ortb2.user.data to gridNMBidAdapter (#8652) --- modules/gridNMBidAdapter.js | 49 ++++++++++++++++++++-- test/spec/modules/gridNMBidAdapter_spec.js | 32 ++++++++++++++ 2 files changed, 77 insertions(+), 4 deletions(-) diff --git a/modules/gridNMBidAdapter.js b/modules/gridNMBidAdapter.js index 63c42f609..b44f94f04 100644 --- a/modules/gridNMBidAdapter.js +++ b/modules/gridNMBidAdapter.js @@ -1,4 +1,13 @@ -import { isStr, deepAccess, isArray, isNumber, logError, logWarn, parseGPTSingleSizeArrayToRtbSize } from '../src/utils.js'; +import { + isStr, + deepAccess, + isArray, + isNumber, + logError, + logWarn, + parseGPTSingleSizeArrayToRtbSize, + mergeDeep +} from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { Renderer } from '../src/Renderer.js'; import { VIDEO } from '../src/mediaTypes.js'; @@ -153,9 +162,7 @@ export const spec = { user = { data: [{ name: 'iow_labs_pub_data', - segment: jwpseg.map((seg) => { - return {name: 'jwpseg', value: seg}; - }) + segment: segmentProcessing(jwpseg, 'jwpseg'), }] }; } @@ -174,9 +181,27 @@ export const spec = { user.ext = userExt; } + const ortb2UserData = deepAccess(bidderRequest, 'ortb2.user.data'); + if (ortb2UserData && ortb2UserData.length) { + if (!user) { + user = { data: [] }; + } + user = mergeDeep(user, { + data: [...ortb2UserData] + }); + } + if (user) { request.user = user; } + const site = deepAccess(bidderRequest, 'ortb2.site'); + if (site) { + const data = deepAccess(site, 'content.data'); + if (data && data.length) { + const siteContent = request.site.content || {}; + request.site.content = mergeDeep(siteContent, { data }); + } + } if (gdprConsent && gdprConsent.gdprApplies) { request.regs = { @@ -408,4 +433,20 @@ export function getSyncUrl() { return SYNC_URL; } +function segmentProcessing(segment, forceSegName) { + return segment + .map((seg) => { + const value = seg && (seg.value || seg.id || seg); + if (typeof value === 'string' || typeof value === 'number') { + return { + value: value.toString(), + ...(forceSegName && { name: forceSegName }), + ...(seg.name && { name: seg.name }), + }; + } + return null; + }) + .filter((seg) => !!seg); +} + registerBidder(spec); diff --git a/test/spec/modules/gridNMBidAdapter_spec.js b/test/spec/modules/gridNMBidAdapter_spec.js index c09aca07c..b400ef339 100644 --- a/test/spec/modules/gridNMBidAdapter_spec.js +++ b/test/spec/modules/gridNMBidAdapter_spec.js @@ -226,6 +226,38 @@ describe('TheMediaGridNM Adapter', function () { } ]; + it('if content and segment is present in jwTargeting, payload must have right params', function () { + const jsContent = {id: 'test_jw_content_id'}; + const jsSegments = ['test_seg_1', 'test_seg_2']; + const bidRequestsWithJwTargeting = bidRequests.map((bid) => { + return Object.assign({ + rtd: { + jwplayer: { + targeting: { + segments: jsSegments, + content: jsContent + } + } + } + }, bid); + }); + const requests = spec.buildRequests(bidRequestsWithJwTargeting, bidderRequest); + requests.forEach((req, i) => { + const payload = req.data; + expect(req).to.have.property('data'); + expect(payload).to.have.property('user'); + expect(payload.user.data).to.deep.equal([{ + name: 'iow_labs_pub_data', + segment: [ + {name: 'jwpseg', value: jsSegments[0]}, + {name: 'jwpseg', value: jsSegments[1]} + ] + }]); + expect(payload).to.have.property('site'); + expect(payload.site.content).to.deep.equal(jsContent); + }); + }); + it('should attach valid params to the tag', function () { const requests = spec.buildRequests(bidRequests, bidderRequest); const requestsSizes = ['300x250,300x600', '728x90'];