Skip to content

Commit fb211ac

Browse files
mmethnerPedro López Jiménez
authored and
Pedro López Jiménez
committed
Add adapter specific params to orbidder adapter (prebid#3467)
* initial orbidder version in personal github repo * use adUnits from orbidder_example.html * replace obsolete functions * forgot to commit the test * check if bidderRequest object is available * try to fix weird safari/ie issue * ebayK: add more params * update orbidderBidAdapter.md * use spec.<function> instead of this.<function> for consistency reasons
1 parent a2ce93f commit fb211ac

File tree

3 files changed

+54
-17
lines changed

3 files changed

+54
-17
lines changed

modules/orbidderBidAdapter.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {registerBidder} from '../src/adapters/bidderFactory';
44

55
export const spec = {
66
code: 'orbidder',
7+
bidParams: {},
78
orbidderHost: (() => {
89
let ret = 'https://orbidder.otto.de';
910
try {
@@ -14,7 +15,10 @@ export const spec = {
1415
})(),
1516

1617
isBidRequestValid(bid) {
17-
return !!(bid.sizes && bid.bidId);
18+
return !!(bid.sizes && bid.bidId && bid.params &&
19+
(bid.params.accountId && (typeof bid.params.accountId === 'string')) &&
20+
(bid.params.placementId && (typeof bid.params.placementId === 'string')) &&
21+
((typeof bid.params.keyValues === 'undefined') || (typeof bid.params.keyValues === 'object')));
1822
},
1923

2024
buildRequests(validBidRequests, bidderRequest) {
@@ -24,7 +28,7 @@ export const spec = {
2428
referer = bidderRequest.refererInfo.referer || '';
2529
}
2630
const ret = {
27-
url: `${this.orbidderHost}/bid`,
31+
url: `${spec.orbidderHost}/bid`,
2832
method: 'POST',
2933
data: {
3034
pageUrl: referer,
@@ -36,6 +40,7 @@ export const spec = {
3640
params: bidRequest.params
3741
}
3842
};
43+
spec.bidParams[bidRequest.bidId] = bidRequest.params;
3944
if (bidRequest && bidRequest.gdprConsent) {
4045
ret.data.gdprConsent = {
4146
consentString: bidRequest.gdprConsent.consentString,
@@ -68,9 +73,13 @@ export const spec = {
6873

6974
onBidWon(winObj) {
7075
const getRefererInfo = detectReferer(window);
71-
const refererInfo = getRefererInfo();
72-
winObj.pageUrl = refererInfo.referer;
73-
spec.ajaxCall(`${this.orbidderHost}/win`, JSON.stringify(winObj));
76+
77+
winObj.pageUrl = getRefererInfo().referer;
78+
if (spec.bidParams[winObj.adId]) {
79+
winObj.params = spec.bidParams[winObj.adId];
80+
}
81+
82+
spec.ajaxCall(`${spec.orbidderHost}/win`, JSON.stringify(winObj));
7483
},
7584

7685
ajaxCall(endpoint, data) {

modules/orbidderBidAdapter.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ var adUnits = [{
2121
},
2222
bids: [{
2323
bidder: 'orbidder'
24+
params: {
25+
accountId: "someAccount",
26+
placementId: "somePlace"
27+
}
2428
}]
2529
}];
2630
```

test/spec/modules/orbidderBidAdapter_spec.js

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@ import {newBidder} from 'src/adapters/bidderFactory';
44

55
describe('orbidderBidAdapter', () => {
66
const adapter = newBidder(spec);
7-
const bidRequest = {
7+
const defaultBidRequest = {
88
bidId: 'd66fa86787e0b0ca900a96eacfd5f0bb',
99
auctionId: 'ccc4c7cdfe11cfbd74065e6dd28413d8',
1010
transactionId: 'd58851660c0c4461e4aa06344fc9c0c6',
1111
adUnitCode: 'adunit-code',
1212
sizes: [[300, 250], [300, 600]],
1313
params: {
14-
'foo': 'bar'
14+
'accountId': 'string1',
15+
'placementId': 'string2'
1516
}
1617
};
1718

19+
const deepClone = function (val) {
20+
return JSON.parse(JSON.stringify(val));
21+
};
22+
1823
const buildRequest = function (buildRequest) {
1924
return spec.buildRequests(
2025
[buildRequest],
@@ -23,7 +28,7 @@ describe('orbidderBidAdapter', () => {
2328
referer: 'http://localhost:9876/'
2429
}
2530
})[0];
26-
}
31+
};
2732

2833
describe('inherited functions', () => {
2934
it('exists and is a function', () => {
@@ -33,18 +38,36 @@ describe('orbidderBidAdapter', () => {
3338

3439
describe('isBidRequestValid', () => {
3540
it('should return true when required params found', () => {
41+
expect(spec.isBidRequestValid(defaultBidRequest)).to.equal(true);
42+
});
43+
44+
it('accepts optional keyValues object', () => {
45+
const bidRequest = deepClone(defaultBidRequest);
46+
bidRequest.params.keyValues = {'key': 'value'};
3647
expect(spec.isBidRequestValid(bidRequest)).to.equal(true);
3748
});
3849

50+
it('performs type checking', () => {
51+
const bidRequest = deepClone(defaultBidRequest);
52+
bidRequest.params.accountId = 1; // supposed to be a string
53+
expect(spec.isBidRequestValid(bidRequest)).to.equal(false);
54+
});
55+
56+
it('doesn\'t accept malformed keyValues', () => {
57+
const bidRequest = deepClone(defaultBidRequest);
58+
bidRequest.params.keyValues = 'another not usable string';
59+
expect(spec.isBidRequestValid(bidRequest)).to.equal(false);
60+
});
61+
3962
it('should return false when required params are not passed', () => {
40-
let bidRequest = Object.assign({}, bidRequest);
63+
const bidRequest = deepClone(defaultBidRequest);
4164
delete bidRequest.params;
4265
expect(spec.isBidRequestValid(bidRequest)).to.equal(false);
4366
});
4467
});
4568

4669
describe('buildRequests', () => {
47-
const request = buildRequest(bidRequest);
70+
const request = buildRequest(defaultBidRequest);
4871

4972
it('sends bid request to endpoint via https using post', () => {
5073
expect(request.method).to.equal('POST');
@@ -54,24 +77,24 @@ describe('orbidderBidAdapter', () => {
5477

5578
it('sends correct bid parameters', () => {
5679
// we add one, because we add referer information from bidderRequest object
57-
expect(Object.keys(request.data).length).to.equal(Object.keys(bidRequest).length + 1);
80+
expect(Object.keys(request.data).length).to.equal(Object.keys(defaultBidRequest).length + 1);
5881
expect(request.data.pageUrl).to.equal('http://localhost:9876/');
5982
// expect(request.data.referrer).to.equal('');
60-
Object.keys(bidRequest).forEach((key) => {
61-
expect(bidRequest[key]).to.equal(request.data[key]);
83+
Object.keys(defaultBidRequest).forEach((key) => {
84+
expect(defaultBidRequest[key]).to.equal(request.data[key]);
6285
});
6386
});
6487

6588
it('handles empty gdpr object', () => {
66-
let bidRequest = Object.assign({}, bidRequest);
89+
const bidRequest = deepClone(defaultBidRequest);
6790
bidRequest.gdprConsent = {};
6891

6992
const request = buildRequest(bidRequest);
7093
expect(request.data.gdprConsent.consentRequired).to.be.equal(true);
7194
});
7295

7396
it('handles non-existent gdpr object', () => {
74-
let bidRequest = Object.assign({}, bidRequest);
97+
const bidRequest = deepClone(defaultBidRequest);
7598
bidRequest.gdprConsent = null;
7699

77100
const request = buildRequest(bidRequest);
@@ -80,7 +103,7 @@ describe('orbidderBidAdapter', () => {
80103

81104
it('handles properly filled gdpr object where gdpr applies', () => {
82105
const consentString = 'someWeirdString';
83-
const bidRequest = Object.assign({}, bidRequest);
106+
const bidRequest = deepClone(defaultBidRequest);
84107
bidRequest.gdprConsent = {
85108
gdprApplies: true,
86109
consentString: 'someWeirdString'
@@ -94,7 +117,7 @@ describe('orbidderBidAdapter', () => {
94117

95118
it('handles properly filled gdpr object where gdpr does not apply', () => {
96119
const consentString = 'someWeirdString';
97-
const bidRequest = Object.assign({}, bidRequest);
120+
const bidRequest = deepClone(defaultBidRequest);
98121
bidRequest.gdprConsent = {
99122
gdprApplies: false,
100123
consentString: 'someWeirdString'
@@ -110,6 +133,7 @@ describe('orbidderBidAdapter', () => {
110133
describe('onBidWon', () => {
111134
let ajaxStub;
112135
const winObj = {
136+
adId: 'testId',
113137
test: 1,
114138
pageUrl: 'www.someurl.de',
115139
referrer: 'www.somereferrer.de'

0 commit comments

Comments
 (0)