Skip to content

Commit

Permalink
chore: update getAudiencesAsBidderOrtb2 implementation and test (pr…
Browse files Browse the repository at this point in the history
  • Loading branch information
naripok authored Mar 29, 2023
1 parent 9a180db commit dd4bd96
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
24 changes: 17 additions & 7 deletions modules/airgridRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import { config } from '../src/config.js';
import { submodule } from '../src/hook.js';
import {
mergeDeep,
deepSetValue,
deepAccess,
} from '../src/utils.js';
Expand Down Expand Up @@ -85,13 +84,24 @@ function setAudiencesToAppNexusAdUnits(adUnits, audiences) {
* @param {Array} audiences
* @return {{}} a map from bidder code to ORTB2 config
*/
export function getAudiencesAsBidderOrtb2(rtdConfig, audiences) {
export function setAudiencesAsBidderOrtb2(rtdConfig, audiences) {
const bidders = deepAccess(rtdConfig, 'params.bidders');
if (!bidders || bidders.length === 0) return {};
const agOrtb2 = {}
deepSetValue(agOrtb2, 'ortb2.user.ext.data.airgrid', audiences || []);
if (!bidders || bidders.length === 0 || !audiences || audiences.length === 0) return;

return Object.fromEntries(bidders.map(bidder => [bidder, agOrtb2]));
const keywords = audiences.map(
(audienceId) => `perid=${audienceId}`
).join(',');

config.mergeBidderConfig({
bidders: bidders,
config: {
ortb2: {
site: {
keywords,
}
}
}
})
}

export function setAudiencesUsingAppNexusAuctionKeywords(audiences) {
Expand Down Expand Up @@ -131,7 +141,7 @@ export function passAudiencesToBidders(
const audiences = getMatchedAudiencesFromStorage();
if (audiences.length > 0) {
setAudiencesUsingAppNexusAuctionKeywords(audiences);
mergeDeep(bidConfig?.ortb2Fragments?.bidder, getAudiencesAsBidderOrtb2(rtdConfig, audiences));
setAudiencesAsBidderOrtb2(rtdConfig, audiences)
if (adUnits) {
setAudiencesToAppNexusAdUnits(adUnits, audiences);
}
Expand Down
12 changes: 9 additions & 3 deletions test/spec/modules/airgridRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,18 @@ describe('airgrid RTD Submodule', function () {
.withArgs(agRTD.AG_AUDIENCE_IDS_KEY)
.returns(JSON.stringify(MATCHED_AUDIENCES));
const audiences = agRTD.getMatchedAudiencesFromStorage();
const bidderOrtb2 = agRTD.getAudiencesAsBidderOrtb2(RTD_CONFIG.dataProviders[0], audiences);

const bidders = RTD_CONFIG.dataProviders[0].params.bidders;
agRTD.setAudiencesAsBidderOrtb2(RTD_CONFIG.dataProviders[0], audiences);

const bidderConfig = config.getBidderConfig()
const bidders = RTD_CONFIG.dataProviders[0].params.bidders
const bidderOrtb2 = bidderConfig

Object.keys(bidderOrtb2).forEach((bidder) => {
if (bidders.indexOf(bidder) === -1) return;
expect(deepAccess(bidderOrtb2[bidder], 'ortb2.user.ext.data.airgrid')).to.eql(MATCHED_AUDIENCES);
MATCHED_AUDIENCES.forEach((audience) => {
expect(deepAccess(bidderOrtb2[bidder], 'ortb2.site.keywords')).to.contain(audience);
})
});
});

Expand Down

0 comments on commit dd4bd96

Please sign in to comment.