Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permutive RTD Module: add ix custom cohorts #9631

Merged
merged 1 commit into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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