Skip to content

Commit 1463ed9

Browse files
authored
add bidderDefaultFunction (#7628)
1 parent 39b26b3 commit 1463ed9

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

modules/imRtdProvider.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,34 @@ function setImDataInCookie(value) {
3737
);
3838
}
3939

40+
/**
41+
* @param {string} bidderName
42+
*/
43+
export function getBidderFunction(bidderName) {
44+
const biddersFunction = {
45+
ix: function (bid, data) {
46+
if (data.im_segments && data.im_segments.length) {
47+
config.setConfig({
48+
ix: {firstPartyData: {im_segments: data.im_segments}},
49+
});
50+
}
51+
return bid
52+
},
53+
pubmatic: function (bid, data) {
54+
if (data.im_segments && data.im_segments.length) {
55+
const dctr = deepAccess(bid, 'params.dctr');
56+
deepSetValue(
57+
bid,
58+
'params.dctr',
59+
`${dctr ? dctr + '|' : ''}im_segments=${data.im_segments.join(',')}`
60+
);
61+
}
62+
return bid
63+
}
64+
}
65+
return biddersFunction[bidderName] || null;
66+
}
67+
4068
export function getCustomBidderFunction(config, bidder) {
4169
const overwriteFn = deepAccess(config, `params.overwrites.${bidder}`)
4270

@@ -73,9 +101,12 @@ export function setRealTimeData(bidConfig, moduleConfig, data) {
73101

74102
adUnits.forEach(adUnit => {
75103
adUnit.bids.forEach(bid => {
104+
const bidderFunction = getBidderFunction(bid.bidder);
76105
const overwriteFunction = getCustomBidderFunction(moduleConfig, bid.bidder);
77106
if (overwriteFunction) {
78107
overwriteFunction(bid, data, utils, config);
108+
} else if (bidderFunction) {
109+
bidderFunction(bid, data);
79110
}
80111
})
81112
});

test/spec/modules/imRtdProvider_spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
imRtdSubmodule,
33
storage,
4+
getBidderFunction,
45
getCustomBidderFunction,
56
setRealTimeData,
67
getRealTimeData,
@@ -47,6 +48,30 @@ describe('imRtdProvider', function () {
4748
})
4849
})
4950

51+
describe('getBidderFunction', function () {
52+
const assumedBidder = [
53+
'ix',
54+
'pubmatic'
55+
];
56+
assumedBidder.forEach(bidderName => {
57+
it(`should return bidderFunction with assumed bidder: ${bidderName}`, function () {
58+
expect(getBidderFunction(bidderName)).to.exist.and.to.be.a('function');
59+
});
60+
61+
it(`should return bid with correct key data: ${bidderName}`, function () {
62+
const bid = {bidder: bidderName};
63+
expect(getBidderFunction(bidderName)(bid, {'im_segments': ['12345', '67890']})).to.equal(bid);
64+
});
65+
it(`should return bid without data: ${bidderName}`, function () {
66+
const bid = {bidder: bidderName};
67+
expect(getBidderFunction(bidderName)(bid, '')).to.equal(bid);
68+
});
69+
});
70+
it(`should return null with unexpected bidder`, function () {
71+
expect(getBidderFunction('test')).to.equal(null);
72+
});
73+
})
74+
5075
describe('getCustomBidderFunction', function () {
5176
it('should return config function', function () {
5277
const config = {

0 commit comments

Comments
 (0)