Skip to content

Commit

Permalink
Handle audiences for appNexus by putting them in config.appnexusAucti…
Browse files Browse the repository at this point in the history
…onKeywords
  • Loading branch information
bwhisp committed Jul 13, 2022
1 parent 1c0c339 commit 7d91251
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 41 deletions.
36 changes: 23 additions & 13 deletions modules/1plusXRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,25 +106,23 @@ export const buildOrtb2Updates = ({ segments = [], topics = [] }, bidder) => {
// Therefore, writing them in `site.keywords` until it's supported
// Other bidAdapters do fine with `site.content.data.segment`
const writeToLegacySiteKeywords = LEGACY_SITE_KEYWORDS_BIDDERS.includes(bidder);
if (writeToLegacySiteKeywords) {
const site = {
keywords: topics.join(',')
};
return { site };
}

const userData = {
name: ORTB2_NAME,
segment: segments.map((segmentId) => ({ id: segmentId }))
};

if (writeToLegacySiteKeywords) {
const site = {
keywords: topics.join(',')
};
return { userData, site };
} else {
const siteContentData = {
name: ORTB2_NAME,
segment: topics.map((topicId) => ({ id: topicId })),
ext: { segtax: segtaxes.CONTENT }
}
return { userData, siteContentData };
const siteContentData = {
name: ORTB2_NAME,
segment: topics.map((topicId) => ({ id: topicId })),
ext: { segtax: segtaxes.CONTENT }
}
return { userData, siteContentData };
}

/**
Expand Down Expand Up @@ -168,6 +166,14 @@ export const updateBidderConfig = (bidder, ortb2Updates, bidderConfigs) => {
return bidderConfigCopy;
};

const setAppnexusAudiences = (audiences) => {
config.setConfig({
appnexusAuctionKeywords: {
'1plusX': audiences,
},
});
}

/**
* Updates bidder configs with the targeting data retreived from Profile API
* @param {Object} papiResponse Response from Profile API
Expand All @@ -187,6 +193,10 @@ export const setTargetingDataToConfig = (papiResponse, { bidders }) => {
config: updatedBidderConfig
});
}
if (bidder === 'appnexus') {
// Do the legacy stuff for appnexus with segments
setAppnexusAudiences(segments);
}
}
}

Expand Down
33 changes: 5 additions & 28 deletions test/spec/modules/1plusXRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,13 @@ describe('1plusXRtdProvider', () => {
}
expect([ortb2Updates]).to.deep.include.members([expectedOutput]);
});
it('fills site.keywords & user.data in the ortb2 config (appnexus specific)', () => {
it('fills site.keywords in the ortb2 config (appnexus specific)', () => {
const rtdData = { segments: fakeResponse.s, topics: fakeResponse.t };
const ortb2Updates = buildOrtb2Updates(rtdData, 'appnexus');

const expectedOutput = {
site: {
keywords: rtdData.topics.join(','),
},
userData: {
name: '1plusX.com',
segment: rtdData.segments.map((segmentId) => ({ id: segmentId }))
}
}
expect([ortb2Updates]).to.deep.include.members([expectedOutput]);
Expand All @@ -224,21 +220,6 @@ describe('1plusXRtdProvider', () => {
}
expect(ortb2Updates).to.deep.include(expectedOutput);
})
it('defaults to empty array if no segment is given (appnexus specific)', () => {
const rtdData = { topics: fakeResponse.t };
const ortb2Updates = buildOrtb2Updates(rtdData, 'appnexus');

const expectedOutput = {
site: {
keywords: rtdData.topics.join(','),
},
userData: {
name: '1plusX.com',
segment: []
}
}
expect(ortb2Updates).to.deep.include(expectedOutput);
})

it('defaults to empty array if no topic is given', () => {
const rtdData = { segments: fakeResponse.s };
Expand All @@ -264,10 +245,6 @@ describe('1plusXRtdProvider', () => {
const expectedOutput = {
site: {
keywords: '',
},
userData: {
name: '1plusX.com',
segment: rtdData.segments.map((segmentId) => ({ id: segmentId }))
}
}
expect(ortb2Updates).to.deep.include(expectedOutput);
Expand Down Expand Up @@ -327,7 +304,6 @@ describe('1plusXRtdProvider', () => {
// Check that the targeting data has been set in the config
expect(newBidderConfig).not.to.be.null;
expect(newBidderConfig.ortb2.site).to.deep.include(ortb2UpdatesAppNexus.site);
expect(newBidderConfig.ortb2.user.data).to.deep.include(ortb2UpdatesAppNexus.userData);
// Check that existing config didn't get erased
expect(newBidderConfig.ortb2.site).to.deep.include(bidderConfigInitial.ortb2.site);
expect(newBidderConfig.ortb2.user).to.deep.include(bidderConfigInitial.ortb2.user);
Expand Down Expand Up @@ -417,8 +393,7 @@ describe('1plusXRtdProvider', () => {
}
const expectedOrtb2 = {
appnexus: {
site: { keywords: expectedKeywords },
user: expectedUserObj
site: { keywords: expectedKeywords }
},
rubicon: {
site: { content: expectedSiteContentObj },
Expand All @@ -442,7 +417,9 @@ describe('1plusXRtdProvider', () => {
// Check that we got what we expect
const expectedConfErr = (prop) => `New config for ${bidder} doesn't comply with expected at ${prop}`;
expect(newConfig.ortb2.site, expectedConfErr('site')).to.deep.include(expectedOrtb2[bidder].site);
expect(newConfig.ortb2.user, expectedConfErr('user')).to.deep.include(expectedOrtb2[bidder].user);
if (expectedOrtb2[bidder].user) {
expect(newConfig.ortb2.user, expectedConfErr('user')).to.deep.include(expectedOrtb2[bidder].user);
}
// Check that existing config didn't get erased
const existingConfErr = (prop) => `Existing config for ${bidder} got unlawfully overwritten at ${prop}`;
expect(newConfig.ortb2.site, existingConfErr('site')).to.deep.include(bidderConfigInitial.ortb2.site);
Expand Down

0 comments on commit 7d91251

Please sign in to comment.