From b658c1e1d8e92328ccf17b6007d33b7a1830637a Mon Sep 17 00:00:00 2001 From: Antonio Gargaro Date: Tue, 7 Mar 2023 17:29:27 +0000 Subject: [PATCH] feat(permutiveRtd): add `ix` and custom cohort `ortb2.user.data` --- modules/permutiveRtdProvider.js | 10 ++- .../spec/modules/permutiveRtdProvider_spec.js | 65 +++++++++++++++++-- 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/modules/permutiveRtdProvider.js b/modules/permutiveRtdProvider.js index 8af963f37dc..4ff41627135 100644 --- a/modules/permutiveRtdProvider.js +++ b/modules/permutiveRtdProvider.js @@ -146,12 +146,17 @@ function updateOrtbConfig(bidder, currConfig, segmentIDs, sspSegmentIDs, transfo .filter(({ id }) => ortb2UserDataTransformations.hasOwnProperty(id)) .map(({ id, config }) => ortb2UserDataTransformations[id](permutiveUserData, config)) + const customCohortsUserData = { + name: PERMUTIVE_CUSTOM_COHORTS_KEYWORD, + segment: customCohortsData.map(cohortID => ({ id: cohortID })), + } + const ortbConfig = mergeDeep({}, currConfig) const currentUserData = deepAccess(ortbConfig, 'ortb2.user.data') || [] const updatedUserData = currentUserData - .filter(el => el.name !== name) - .concat(permutiveUserData, transformedUserData) + .filter(el => el.name !== permutiveUserData.name && el.name !== customCohortsUserData.name) + .concat(permutiveUserData, transformedUserData, customCohortsUserData) deepSetValue(ortbConfig, 'ortb2.user.data', updatedUserData) @@ -311,6 +316,7 @@ export function getSegments (maxSegs) { const segments = { ac: [..._pcrprs, ..._ppam, ...legacySegs], + ix: readSegments('_pindexs', []), rubicon: readSegments('_prubicons', []), appnexus: readSegments('_papns', []), gam: readSegments('_pdfps', []), diff --git a/test/spec/modules/permutiveRtdProvider_spec.js b/test/spec/modules/permutiveRtdProvider_spec.js index 207771731a7..18d413acdad 100644 --- a/test/spec/modules/permutiveRtdProvider_spec.js +++ b/test/spec/modules/permutiveRtdProvider_spec.js @@ -196,12 +196,67 @@ describe('permutiveRtdProvider', function () { setBidderRtb(bidderConfig, moduleConfig, segmentsData) acBidders.forEach(bidder => { - expect(bidderConfig[bidder].user.data).to.deep.include.members([{ - name: 'permutive.com', - segment: expectedTargetingData - }]) + const customCohorts = segmentsData[bidder] || [] + expect(bidderConfig[bidder].user.data).to.deep.include.members([ + { + name: 'permutive.com', + segment: expectedTargetingData, + }, + // Should have custom cohorts specific for that bidder + { + name: 'permutive', + segment: customCohorts.map(seg => { + return { id: seg } + }), + }, + ]) }) }) + + it('should override existing ortb2.user.data reserved by permutive RTD', function () { + const reservedPermutiveStandardName = 'permutive.com' + const reservedPermutiveCustomCohortName = 'permutive' + + const moduleConfig = getConfig() + const acBidders = moduleConfig.params.acBidders + const segmentsData = transformedTargeting() + + const sampleOrtbConfig = { + user: { + data: [ + { + name: reservedPermutiveCustomCohortName, + segment: [{ id: 'remove-me' }, { id: 'remove-me-also' }] + }, + { + name: reservedPermutiveStandardName, + segment: [{ id: 'remove-me-also-also' }, { id: 'remove-me-also-also-also' }] + } + ] + } + } + + const bidderConfig = Object.fromEntries(acBidders.map(bidder => [bidder, sampleOrtbConfig])) + + setBidderRtb(bidderConfig, moduleConfig, segmentsData) + + acBidders.forEach(bidder => { + const customCohorts = segmentsData[bidder] || [] + + expect(bidderConfig[bidder].user.data).to.not.deep.include.members([...sampleOrtbConfig.user.data]) + expect(bidderConfig[bidder].user.data).to.deep.include.members([ + { + name: reservedPermutiveCustomCohortName, + segment: customCohorts.map(id => ({ id })), + }, + { + name: reservedPermutiveStandardName, + segment: segmentsData.ac.map(id => ({ id })), + }, + ]) + }) + }) + it('should include ortb2 user data transformation for IAB audience taxonomy', function() { const moduleConfig = getConfig() const bidderConfig = {} @@ -647,6 +702,7 @@ function transformedTargeting (data = getTargetingData()) { return { ac: [...data._pcrprs, ...data._ppam, ...data._psegs.filter(seg => seg >= 1000000)], appnexus: data._papns, + ix: data._pindexs, rubicon: data._prubicons, gam: data._pdfps, ssp: data._pssps, @@ -660,6 +716,7 @@ function getTargetingData () { _papns: ['appnexus1', 'appnexus2'], _psegs: ['1234', '1000001', '1000002'], _ppam: ['ppam1', 'ppam2'], + _pindexs: ['pindex1', 'pindex2'], _pcrprs: ['pcrprs1', 'pcrprs2', 'dup'], _pssps: { ssps: ['xyz', 'abc', 'dup'], cohorts: ['123', 'abc'] } }