Skip to content

Commit

Permalink
feat(permutiveRtd): add ix and custom cohort ortb2.user.data
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioGargaro committed Mar 8, 2023
1 parent 983f807 commit f506cae
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 11 deletions.
20 changes: 13 additions & 7 deletions modules/permutiveRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,27 @@ export function setBidderRtb (bidderOrtb2, moduleConfig, segmentData) {
*/
function updateOrtbConfig(bidder, currConfig, segmentIDs, sspSegmentIDs, transformationConfigs, segmentData) {
const name = 'permutive.com'

const permutiveUserData = {
const permutiveStandardUserData = {
name,
segment: segmentIDs.map(segmentId => ({ id: segmentId })),
}

const transformedUserData = transformationConfigs
.filter(({ id }) => ortb2UserDataTransformations.hasOwnProperty(id))
.map(({ id, config }) => ortb2UserDataTransformations[id](permutiveUserData, config))
.map(({ id, config }) => ortb2UserDataTransformations[id](permutiveStandardUserData, config))

const biddersCustomCohorts = deepAccess(segmentData, bidder) || []
const customCohortsUserData = {
name: PERMUTIVE_CUSTOM_COHORTS_KEYWORD,
segment: biddersCustomCohorts.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 !== permutiveStandardUserData.name && el.name !== customCohortsUserData.name)
.concat(permutiveStandardUserData, transformedUserData, customCohortsUserData)

deepSetValue(ortbConfig, 'ortb2.user.data', updatedUserData)

Expand All @@ -165,8 +170,8 @@ function updateOrtbConfig(bidder, currConfig, segmentIDs, sspSegmentIDs, transfo
deepSetValue(ortbConfig, 'ortb2.user.ext.data.' + PERMUTIVE_STANDARD_KEYWORD, segmentIDs)
}

if (segmentData?.rubicon?.length > 0) {
deepSetValue(ortbConfig, 'ortb2.user.ext.data.' + PERMUTIVE_CUSTOM_COHORTS_KEYWORD, segmentData.rubicon.map(String))
if (biddersCustomCohorts.length > 0) {
deepSetValue(ortbConfig, 'ortb2.user.ext.data.' + PERMUTIVE_CUSTOM_COHORTS_KEYWORD, biddersCustomCohorts.map(String))
}

logger.logInfo(`Extending ortb2.user.ext.data for ${bidder}`, deepAccess(ortbConfig, 'ortb2.user.ext.data'))
Expand Down Expand Up @@ -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', []),
Expand Down
65 changes: 61 additions & 4 deletions test/spec/modules/permutiveRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -635,6 +690,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,
Expand All @@ -648,6 +704,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'] }
}
Expand Down

0 comments on commit f506cae

Please sign in to comment.