From ecc3441914e14d9d4543f5c4cc7b531ad2c14d7e Mon Sep 17 00:00:00 2001 From: Andrew Slagle <42588549+spotxslagle@users.noreply.github.com> Date: Fri, 23 Feb 2024 20:49:57 -0700 Subject: [PATCH] Rubicon Bid Adapter: Pass on carbon segtaxes (#10985) * Pass through Carbon segments * Fix rubiconBidAdapter for unit tests * segtax spec * Fix access issues * Remove dup ortb2 work * Adjust unit tests * Fix lint issues * Add all desired segtaxes * Fix unit tests * Fix linting * Don't concat undefined * Unit test pub added segtaxes * Pull site data from site.content.data * Update unit tests --- modules/rubiconBidAdapter.js | 23 ++++++++++ test/spec/modules/rubiconBidAdapter_spec.js | 50 +++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/modules/rubiconBidAdapter.js b/modules/rubiconBidAdapter.js index 973c6660ece..c4f6e7d545d 100644 --- a/modules/rubiconBidAdapter.js +++ b/modules/rubiconBidAdapter.js @@ -532,6 +532,8 @@ export const spec = { if (bidRequest?.ortb2Imp?.ext?.ae) { data['o_ae'] = 1; } + + addDesiredSegtaxes(bidderRequest, data); // loop through userIds and add to request if (bidRequest.userIdAsEids) { bidRequest.userIdAsEids.forEach(eid => { @@ -1037,6 +1039,27 @@ function applyFPD(bidRequest, mediaType, data) { } } +function addDesiredSegtaxes(bidderRequest, target) { + if (rubiConf.readTopics === false) { + return; + } + let iSegments = [1, 2, 5, 6, 7, 507].concat(rubiConf.sendSiteSegtax?.map(seg => Number(seg)) || []); + let vSegments = [4, 508].concat(rubiConf.sendUserSegtax?.map(seg => Number(seg)) || []); + let userData = bidderRequest.ortb2?.user?.data || []; + let siteData = bidderRequest.ortb2?.site?.content?.data || []; + userData.forEach(iterateOverSegmentData(target, 'v', vSegments)); + siteData.forEach(iterateOverSegmentData(target, 'i', iSegments)); +} + +function iterateOverSegmentData(target, char, segments) { + return (topic) => { + const taxonomy = Number(topic.ext?.segtax); + if (segments.includes(taxonomy)) { + target[`tg_${char}.tax${taxonomy}`] = topic.segment?.map(seg => seg.id).join(','); + } + } +} + /** * @param sizes * @returns {*} diff --git a/test/spec/modules/rubiconBidAdapter_spec.js b/test/spec/modules/rubiconBidAdapter_spec.js index 0312114e75b..184bea07d04 100644 --- a/test/spec/modules/rubiconBidAdapter_spec.js +++ b/test/spec/modules/rubiconBidAdapter_spec.js @@ -2770,6 +2770,56 @@ describe('the rubicon adapter', function () { expect(slotParams['o_ae']).to.equal(1) }); + + it('should pass along desired segtaxes, but not non-desired ones', () => { + const localBidderRequest = Object.assign({}, bidderRequest); + localBidderRequest.refererInfo = {domain: 'bob'}; + config.setConfig({ + rubicon: { + sendUserSegtax: [9], + sendSiteSegtax: [10] + } + }); + localBidderRequest.ortb2.user = { + data: [{ + ext: { + segtax: '404' + }, + segment: [{id: 5}, {id: 6}] + }, { + ext: { + segtax: '508' + }, + segment: [{id: 5}, {id: 2}] + }, { + ext: { + segtax: '9' + }, + segment: [{id: 1}, {id: 2}] + }] + } + localBidderRequest.ortb2.site = { + content: { + data: [{ + ext: { + segtax: '10' + }, + segment: [{id: 2}, {id: 3}] + }, { + ext: { + segtax: '507' + }, + segment: [{id: 3}, {id: 4}] + }] + } + } + const slotParams = spec.createSlotParams(bidderRequest.bids[0], localBidderRequest); + expect(slotParams['tg_i.tax507']).is.equal('3,4'); + expect(slotParams['tg_v.tax508']).is.equal('5,2'); + expect(slotParams['tg_v.tax9']).is.equal('1,2'); + expect(slotParams['tg_i.tax10']).is.equal('2,3'); + expect(slotParams['tg_v.tax404']).is.equal(undefined); + }); }); describe('classifiedAsVideo', function () {