Skip to content

Commit

Permalink
feat(permutiveRtd): add ix and custom cohort ortb2.user.data (pre…
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioGargaro authored and jorgeluisrocha committed May 18, 2023
1 parent 1d4729f commit e91409c
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 6 deletions.
10 changes: 8 additions & 2 deletions modules/permutiveRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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 @@ -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,
Expand All @@ -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'] }
}
Expand Down

0 comments on commit e91409c

Please sign in to comment.