Skip to content

Commit

Permalink
Permutive RTD Module: migrate appnexus to ortb2 (#9630)
Browse files Browse the repository at this point in the history
* fix(permutiveRtd): migrate appnexus to ortb2 keywords

* test(permutiveRtd): remove outdated appnexus test

* fix(permutiveRtd): remove bidder specific logic for keywords

* fix(permutiveRtd): remove alias map in legacy segment setting

* Revert "fix(permutiveRtd): remove alias map in legacy segment setting"

This reverts commit e1fa634.
  • Loading branch information
AntonioGargaro authored Mar 22, 2023
1 parent 7585fed commit a144f5a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 38 deletions.
47 changes: 29 additions & 18 deletions modules/permutiveRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ export function setBidderRtb (bidderOrtb2, moduleConfig, segmentData) {
* @return {Object} Merged ortb2 object
*/
function updateOrtbConfig(bidder, currConfig, segmentIDs, sspSegmentIDs, transformationConfigs, segmentData) {
logger.logInfo(`Current ortb2 config`, { bidder, config: currConfig })

const customCohortsData = deepAccess(segmentData, bidder) || []

const name = 'permutive.com'
Expand All @@ -158,13 +160,34 @@ function updateOrtbConfig(bidder, currConfig, segmentIDs, sspSegmentIDs, transfo
.filter(el => el.name !== permutiveUserData.name && el.name !== customCohortsUserData.name)
.concat(permutiveUserData, transformedUserData, customCohortsUserData)

logger.logInfo(`Updating ortb2.user.data`, { bidder, user_data: updatedUserData })
deepSetValue(ortbConfig, 'ortb2.user.data', updatedUserData)

// As of writing this, only used for AppNexus/Xandr in place of appnexusAuctionKeywords in config
const currentUserKeywords = deepAccess(ortbConfig, 'ortb2.user.keywords') || ''
const keywords = sspSegmentIDs.map(segment => `${PERMUTIVE_STANDARD_AUD_KEYWORD}=${segment}`).join(',')
const updatedUserKeywords = (currentUserKeywords === '') ? keywords : `${currentUserKeywords},${keywords}`
deepSetValue(ortbConfig, 'ortb2.user.keywords', updatedUserKeywords)
// Set ortb2.user.keywords
const currentKeywords = deepAccess(ortbConfig, 'ortb2.user.keywords')
const keywordGroups = {
[PERMUTIVE_STANDARD_KEYWORD]: segmentIDs,
[PERMUTIVE_STANDARD_AUD_KEYWORD]: sspSegmentIDs,
[PERMUTIVE_CUSTOM_COHORTS_KEYWORD]: customCohortsData,
}

// Transform groups of key-values into a single array of strings
// i.e { permutive: ['1', '2'], p_standard: ['3', '4'] } => ['permutive=1', 'permutive=2', 'p_standard=3',' p_standard=4']
const transformedKeywordGroups = Object.entries(keywordGroups)
.flatMap(([keyword, ids]) => ids.map(id => `${keyword}=${id}`))

const keywords = [
currentKeywords,
...transformedKeywordGroups,
]
.filter(Boolean)
.join(',')

logger.logInfo(`Updating ortb2.user.keywords`, {
bidder,
keywords,
})
deepSetValue(ortbConfig, 'ortb2.user.keywords', keywords)

// Set user extensions
if (segmentIDs.length > 0) {
Expand All @@ -177,8 +200,7 @@ function updateOrtbConfig(bidder, currConfig, segmentIDs, sspSegmentIDs, transfo
logger.logInfo(`Extending ortb2.user.ext.data with "${PERMUTIVE_CUSTOM_COHORTS_KEYWORD}"`, customCohortsData)
}

logger.logInfo(`Updating ortb2 config for ${bidder}`, ortbConfig)

logger.logInfo(`Updated ortb2 config`, { bidder, config: ortbConfig })
return ortbConfig
}

Expand Down Expand Up @@ -256,17 +278,6 @@ function getDefaultBidderFn (bidder) {
return [...new Set([...ac, ...ssp])]
}
const bidderMap = {
appnexus: function (bid, data, acEnabled) {
if (isPStandardTargetingEnabled(data, acEnabled)) {
const segments = pStandardTargeting(data, acEnabled)
deepSetValue(bid, 'params.keywords.p_standard', segments)
}
if (data.appnexus && data.appnexus.length) {
deepSetValue(bid, 'params.keywords.permutive', data.appnexus)
}

return bid
},
ozone: function (bid, data, acEnabled) {
if (isPStandardTargetingEnabled(data, acEnabled)) {
const segments = pStandardTargeting(data, acEnabled)
Expand Down
38 changes: 18 additions & 20 deletions test/spec/modules/permutiveRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {
getModuleConfig,
PERMUTIVE_SUBMODULE_CONFIG_KEY,
readAndSetCohorts,
PERMUTIVE_STANDARD_KEYWORD,
PERMUTIVE_STANDARD_AUD_KEYWORD,
PERMUTIVE_CUSTOM_COHORTS_KEYWORD,
} from 'modules/permutiveRtdProvider.js'
import { deepAccess, deepSetValue, mergeDeep } from '../../../src/utils.js'
import { config } from 'src/config.js'
Expand Down Expand Up @@ -365,9 +368,23 @@ describe('permutiveRtdProvider', function () {
setBidderRtb(bidderConfig, moduleConfig, segmentsData)

acBidders.forEach(bidder => {
const customCohortsData = segmentsData[bidder] || []
const keywordGroups = {
[PERMUTIVE_STANDARD_KEYWORD]: segmentsData.ac,
[PERMUTIVE_STANDARD_AUD_KEYWORD]: segmentsData.ssp.cohorts,
[PERMUTIVE_CUSTOM_COHORTS_KEYWORD]: customCohortsData
}

// Transform groups of key-values into a single array of strings
// i.e { permutive: ['1', '2'], p_standard: ['3', '4'] } => ['permutive=1', 'permutive=2', 'p_standard=3',' p_standard=4']
const transformedKeywordGroups = Object.entries(keywordGroups)
.flatMap(([keyword, ids]) => ids.map(id => `${keyword}=${id}`))

const keywords = `${sampleOrtbConfig.user.keywords},${transformedKeywordGroups.join(',')}`

expect(bidderConfig[bidder].site.name).to.equal(sampleOrtbConfig.site.name)
expect(bidderConfig[bidder].user.data).to.deep.include.members([sampleOrtbConfig.user.data[0]])
expect(bidderConfig[bidder].user.keywords).to.deep.equal('a,b,p_standard_aud=123,p_standard_aud=abc')
expect(bidderConfig[bidder].user.keywords).to.deep.equal(keywords)
})
})
it('should merge ortb2 correctly for ac and ssps', function () {
Expand Down Expand Up @@ -544,25 +561,6 @@ describe('permutiveRtdProvider', function () {
})

describe('Default segment targeting', function () {
it('sets segment targeting for Xandr', function () {
const data = transformedTargeting()
const adUnits = getAdUnits()
const config = getConfig()

readAndSetCohorts({ adUnits }, config)

adUnits.forEach(adUnit => {
adUnit.bids.forEach(bid => {
const { bidder, params } = bid

if (bidder === 'appnexus') {
expect(deepAccess(params, 'keywords.permutive')).to.eql(data.appnexus)
expect(deepAccess(params, 'keywords.p_standard')).to.eql(data.ac.concat(data.ssp.cohorts))
}
})
})
})

it('sets segment targeting for Ozone', function () {
const data = transformedTargeting()
const adUnits = getAdUnits()
Expand Down

0 comments on commit a144f5a

Please sign in to comment.