From dd4bd963f94ac74284f65d437b88a256b6af6adb Mon Sep 17 00:00:00 2001 From: Fernando Canteruccio Date: Wed, 29 Mar 2023 12:38:10 -0300 Subject: [PATCH] chore: update `getAudiencesAsBidderOrtb2` implementation and test (#9720) --- modules/airgridRtdProvider.js | 24 ++++++++++++++------ test/spec/modules/airgridRtdProvider_spec.js | 12 +++++++--- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/modules/airgridRtdProvider.js b/modules/airgridRtdProvider.js index 3578cc4b87e..174502d1757 100644 --- a/modules/airgridRtdProvider.js +++ b/modules/airgridRtdProvider.js @@ -8,7 +8,6 @@ import { config } from '../src/config.js'; import { submodule } from '../src/hook.js'; import { - mergeDeep, deepSetValue, deepAccess, } from '../src/utils.js'; @@ -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) { @@ -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); } diff --git a/test/spec/modules/airgridRtdProvider_spec.js b/test/spec/modules/airgridRtdProvider_spec.js index 5b1df6f9d4c..c587ef1a133 100644 --- a/test/spec/modules/airgridRtdProvider_spec.js +++ b/test/spec/modules/airgridRtdProvider_spec.js @@ -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); + }) }); });