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

Ensure All Permutive Segments Can Be Used for SDA #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 10 additions & 5 deletions modules/permutiveRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,33 @@ export function setBidderRtb (bidderOrtb2, customModuleConfig) {

acBidders.forEach(function (bidder) {
const currConfig = { ortb2: bidderOrtb2[bidder] || {} }
const nextConfig = updateOrtbConfig(currConfig, segmentData.ac, transformationConfigs) // ORTB2 uses the `ac` segment IDs
const nextConfig = updateOrtbConfig(currConfig, segmentData, transformationConfigs) // ORTB2 uses the `ac` segment IDs
bidderOrtb2[bidder] = nextConfig.ortb2;
})
}

/**
* Updates `user.data` object in existing bidder config with Permutive segments
* @param {Object} currConfig - Current bidder config
* @param {Object} segmentData - Permutive segments
* @param {Object[]} transformationConfigs - array of objects with `id` and `config` properties, used to determine
* the transformations on user data to include the ORTB2 object
* @param {string[]} segmentIDs - Permutive segment IDs
* @return {Object} Merged ortb2 object
*/
function updateOrtbConfig (currConfig, segmentIDs, transformationConfigs) {
function updateOrtbConfig (currConfig, segmentData, transformationConfigs) {
const name = 'permutive.com'

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

const transformedUserData = transformationConfigs
.filter(({ id }) => ortb2UserDataTransformations.hasOwnProperty(id))
.map(({ id, config }) => ortb2UserDataTransformations[id](permutiveUserData, config))
.map(({ id, config }) => ortb2UserDataTransformations[id]({
name,
segment: segmentData.transformations.map(segmentId => ({ id: segmentId })),
}, config))

const ortbConfig = mergeDeep({}, currConfig)
const currentUserData = deepAccess(ortbConfig, 'ortb2.user.data') || []
Expand Down Expand Up @@ -234,6 +237,7 @@ export function isPermutiveOnPage () {
*/
export function getSegments (maxSegs) {
const legacySegs = readSegments('_psegs').map(Number).filter(seg => seg >= 1000000).map(String)
const legacySegsUnfiltered = readSegments('_psegs').map(String)
const _ppam = readSegments('_ppam')
const _pcrprs = readSegments('_pcrprs')

Expand All @@ -242,6 +246,7 @@ export function getSegments (maxSegs) {
rubicon: readSegments('_prubicons'),
appnexus: readSegments('_papns'),
gam: readSegments('_pdfps'),
transformations: [..._pcrprs, ..._ppam, ...legacySegsUnfiltered],
}

for (const bidder in segments) {
Expand Down
4 changes: 3 additions & 1 deletion test/spec/modules/permutiveRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ describe('permutiveRtdProvider', function () {
config: {
segtax: 4,
iabIds: {
1234: '9000007',
1000001: '9000009',
1000002: '9000008'
}
Expand All @@ -86,7 +87,7 @@ describe('permutiveRtdProvider', function () {
{
name: 'permutive.com',
ext: { segtax: 4 },
segment: [{ id: '9000009' }, { id: '9000008' }]
segment: [{ id: '9000007' }, { id: '9000009' }, { id: '9000008' }]
}
])
})
Expand Down Expand Up @@ -374,6 +375,7 @@ function transformedTargeting () {
appnexus: data._papns,
rubicon: data._prubicons,
gam: data._pdfps,
transformations: [...data._pcrprs, ...data._ppam, ...data._psegs],
}
}

Expand Down