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: migrate ozone to ortb2 #9628

Merged
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
47 changes: 9 additions & 38 deletions modules/permutiveRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ function updateOrtbConfig(bidder, currConfig, segmentIDs, sspSegmentIDs, transfo
logger.logInfo(`Extending ortb2.user.ext.data with "${PERMUTIVE_CUSTOM_COHORTS_KEYWORD}"`, customCohortsData)
}

// Set site extensions
if (segmentIDs.length > 0) {
deepSetValue(ortbConfig, `ortb2.site.ext.permutive.${PERMUTIVE_STANDARD_KEYWORD}`, segmentIDs)
logger.logInfo(`Extending ortb2.site.ext.permutive with "${PERMUTIVE_STANDARD_KEYWORD}"`, segmentIDs)
}

logger.logInfo(`Updated ortb2 config`, { bidder, config: ortbConfig })
return ortbConfig
}
Expand Down Expand Up @@ -230,12 +236,11 @@ function setSegments (reqBidsConfigObj, moduleConfig, segmentData) {
}
const acEnabled = isAcEnabled(moduleConfig, bidder)
const customFn = getCustomBidderFn(moduleConfig, bidder)
const defaultFn = getDefaultBidderFn(bidder)

if (customFn) {
customFn(bid, segmentData, acEnabled, utils, defaultFn)
} else if (defaultFn) {
defaultFn(bid, segmentData, acEnabled)
// For backwards compatibility we pass an identity function to any custom bidder function set by a publisher
const bidIdentity = (bid) => bid
customFn(bid, segmentData, acEnabled, utils, bidIdentity)
}
})
})
Expand Down Expand Up @@ -263,40 +268,6 @@ function getCustomBidderFn (moduleConfig, bidder) {
}
}

/**
* Returns a function that receives a `bid` object, a `data` object and a `acEnabled` boolean
* and which will set the right segment targeting keys for `bid` based on `data` and `acEnabled`
* @param {string} bidder - Bidder name
* @return {Object} Bidder function
*/
function getDefaultBidderFn (bidder) {
const isPStandardTargetingEnabled = (data, acEnabled) => {
return (acEnabled && data.ac && data.ac.length) || (data.ssp && data.ssp.cohorts && data.ssp.cohorts.length)
}
const pStandardTargeting = (data, acEnabled) => {
const ac = (acEnabled) ? (data.ac ?? []) : []
const ssp = data?.ssp?.cohorts ?? []
return [...new Set([...ac, ...ssp])]
}
const bidderMap = {
ozone: function (bid, data, acEnabled) {
if (isPStandardTargetingEnabled(data, acEnabled)) {
const segments = pStandardTargeting(data, acEnabled)
deepSetValue(bid, 'params.customData.0.targeting.p_standard', segments)
}

return bid
}
}

// On no default bidder just return the same bid as passed in
function bidIdentity(bid) {
return bid
}

return bidderMap[bidder] || bidIdentity
}

/**
* Check whether ac is enabled for bidder
* @param {Object} moduleConfig - Module configuration
Expand Down
20 changes: 0 additions & 20 deletions test/spec/modules/permutiveRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,26 +560,6 @@ describe('permutiveRtdProvider', function () {
})
})

describe('Default segment targeting', function () {
it('sets segment targeting for Ozone', 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 === 'ozone') {
expect(deepAccess(params, 'customData.0.targeting.p_standard')).to.eql(data.ac.concat(data.ssp.cohorts))
}
})
})
})
})

describe('Existing key-value targeting', function () {
it('doesn\'t overwrite existing key-values for Xandr', function () {
const adUnits = getAdUnits()
Expand Down