Skip to content

Commit cf53c88

Browse files
committed
add bidderDefaultFunction
1 parent 38b9816 commit cf53c88

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

modules/imRtdProvider.js

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

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

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

74103
adUnits.forEach(adUnit => {
75104
adUnit.bids.forEach(bid => {
105+
const bidderFunction = getBidderFunction(bid.bidder);
76106
const overwriteFunction = getCustomBidderFunction(moduleConfig, bid.bidder);
77107
if (overwriteFunction) {
78108
overwriteFunction(bid, data, utils, config);
109+
} else if (bidderFunction) {
110+
bidderFunction(bid, data);
79111
}
80112
})
81113
});

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)