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

Rubicon Bid Adapter: Pass on carbon segtaxes #10985

Merged
merged 14 commits into from
Feb 24, 2024
24 changes: 24 additions & 0 deletions modules/rubiconBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,13 @@ export const spec = {
if (bidRequest?.ortb2Imp?.ext?.ae) {
data['o_ae'] = 1;
}

const topics = getCarbonTopics(bidderRequest);
if (topics) {
Object.keys(topics).forEach(field => {
data[field] = topics[field];
});
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not really a huge performance increase but no need to have two loops when we can just add those keys to the data object during the initial getCarbonTopics loop.

And maybe we can generalize it to not say carbon and just "Get wanted segtax" or topics or whatever. And it just takes in list of taxonomy numbers?

So if we need to add another one we just update the list or something. - guess you can just update the if statement also so no worries.

// loop through userIds and add to request
if (bidRequest.userIdAsEids) {
bidRequest.userIdAsEids.forEach(eid => {
Expand Down Expand Up @@ -1001,6 +1008,23 @@ function applyFPD(bidRequest, mediaType, data) {
}
}

function getCarbonTopics(bidderRequest) {
if (rubiConf.readTopics === false) {
return undefined;
}
let fields = {};
let userData = bidderRequest.ortb2?.user?.data || [];
userData.forEach(topic => {
const taxonomy = topic.ext?.segtax;
if (taxonomy == 507 || taxonomy == 508) {
const domain = bidderRequest.refererInfo.domain;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should be

const domain = topic.name || bidderRequest.refererInfo.domain;

fields[`s_segs_${taxonomy}_${domain}`] = topic.segment?.map(seg => seg.id).join(',')
}
})
let hasProps = Object.keys(fields).length > 0;
return hasProps ? fields : undefined;
}

/**
* @param sizes
* @returns {*}
Expand Down
26 changes: 26 additions & 0 deletions test/spec/modules/rubiconBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2718,6 +2718,32 @@ describe('the rubicon adapter', function () {

expect(slotParams['o_ae']).to.equal(1)
});

it('should pass along Carbon segtaxes, but not non-Carbon ones', () => {
const localBidderRequest = Object.assign({}, bidderRequest);
localBidderRequest.refererInfo = {domain: 'bob'};
localBidderRequest.ortb2.user = {
data: [{
ext: {
segtax: '404'
},
segment: [{id: 5}, {id: 6}]
}, {
ext: {
segtax: '507'
},
segment: [{id: 1}, {id: 2}]
}, {
ext: {
segtax: '508'
},
segment: [{id: 3}, {id: 4}]
}]
}
const slotParams = spec.createSlotParams(bidderRequest.bids[0], localBidderRequest);
expect(slotParams.s_segs_507_bob).is.equal('1,2');
expect(slotParams.s_segs_508_bob).is.equal('3,4');
});
});

describe('classifiedAsVideo', function () {
Expand Down