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

AirGrid RTD Provider: update audience segmentation data setting method for the Ortb2 bidder config #9720

Merged
merged 2 commits into from
Mar 29, 2023
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
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewers: we plan to remove this Xandr specific method / handling in another PR once this is live and tested.

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