Skip to content

Commit 8efc3be

Browse files
adtech-colombiasubhashish.singh
and
subhashish.singh
authored
Colombia Bid Adapter : initial release (#11478)
* new Colombia bid Adapter implementation * new Colombia bid Adapter implementation * new Colombia bid Adapter implementation * new Colombia bid Adapter implementation- 'lint' errored Fixed * new Colombia bid Adapter implementation- Resolved test case issue * new Colombia bid Adapter implementation- Resolved test case issue * new Colombia bid Adapter implementation- Resolved test case issue --------- Co-authored-by: subhashish.singh <[email protected]>
1 parent 8c4955b commit 8efc3be

File tree

4 files changed

+294
-1
lines changed

4 files changed

+294
-1
lines changed

modules/colombiaBidAdapter.js

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import * as utils from '../src/utils.js';
2+
import {config} from '../src/config.js';
3+
import {registerBidder} from '../src/adapters/bidderFactory.js';
4+
import { BANNER } from '../src/mediaTypes.js';
5+
const BIDDER_CODE = 'colombia';
6+
const ENDPOINT_URL = 'https://ade.clmbtech.com/cde/prebid.htm';
7+
const HOST_NAME = document.location.protocol + '//' + window.location.host;
8+
9+
export const spec = {
10+
code: BIDDER_CODE,
11+
aliases: ['clmb'],
12+
supportedMediaTypes: [BANNER],
13+
isBidRequestValid: function(bid) {
14+
return !!(bid.params.placementId);
15+
},
16+
buildRequests: function(validBidRequests, bidderRequest) {
17+
if (validBidRequests.length === 0) {
18+
return [];
19+
}
20+
let payloadArr = []
21+
let ctr = 1;
22+
validBidRequests = validBidRequests.map(bidRequest => {
23+
const params = bidRequest.params;
24+
const sizes = utils.parseSizesInput(bidRequest.sizes)[0];
25+
const width = sizes.split('x')[0];
26+
const height = sizes.split('x')[1];
27+
const placementId = params.placementId;
28+
const cb = Math.floor(Math.random() * 99999999999);
29+
const bidId = bidRequest.bidId;
30+
const referrer = (bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.referer) ? bidderRequest.refererInfo.referer : '';
31+
let mediaTypes = {}
32+
let payload = {
33+
v: 'hb1',
34+
p: placementId,
35+
pos: '~' + ctr,
36+
w: width,
37+
h: height,
38+
cb: cb,
39+
r: referrer,
40+
uid: bidId,
41+
t: 'i',
42+
d: HOST_NAME,
43+
fpc: params.fpc,
44+
_u: window.location.href,
45+
mediaTypes: Object.assign({}, mediaTypes, bidRequest.mediaTypes)
46+
};
47+
if (params.keywords) payload.keywords = params.keywords;
48+
if (params.category) payload.cat = params.category;
49+
if (params.pageType) payload.pgt = params.pageType;
50+
if (params.incognito) payload.ic = params.incognito;
51+
if (params.dsmi) payload.smi = params.dsmi;
52+
if (params.optout) payload.out = params.optout;
53+
if (bidRequest && bidRequest.hasOwnProperty('ortb2Imp') && bidRequest.ortb2Imp.hasOwnProperty('ext')) {
54+
payload.ext = bidRequest.ortb2Imp.ext;
55+
if (bidRequest.ortb2Imp.ext.hasOwnProperty('gpid')) payload.pubAdCode = bidRequest.ortb2Imp.ext.gpid.split('#')[0];
56+
}
57+
payloadArr.push(payload);
58+
ctr++;
59+
});
60+
return [{
61+
method: 'POST',
62+
url: ENDPOINT_URL,
63+
data: payloadArr,
64+
}]
65+
},
66+
interpretResponse: function(serverResponse, bidRequest) {
67+
const bidResponses = [];
68+
const res = serverResponse.body || serverResponse;
69+
if (!res || res.length === 0) {
70+
return bidResponses;
71+
}
72+
try {
73+
res.forEach(response => {
74+
const crid = response.creativeId || 0;
75+
const width = response.width || 0;
76+
const height = response.height || 0;
77+
let cpm = response.cpm || 0;
78+
if (cpm <= 0) {
79+
return bidResponses;
80+
}
81+
if (width !== 0 && height !== 0 && cpm !== 0 && crid !== 0) {
82+
const dealId = response.dealid || '';
83+
const currency = response.currency || 'USD';
84+
const netRevenue = (response.netRevenue === undefined) ? true : response.netRevenue;
85+
const bidResponse = {
86+
requestId: response.requestId,
87+
cpm: cpm.toFixed(2),
88+
width: response.width,
89+
height: response.height,
90+
creativeId: crid,
91+
dealId: dealId,
92+
currency: currency,
93+
netRevenue: netRevenue,
94+
ttl: config.getConfig('_bidderTimeout') || 300,
95+
referrer: bidRequest.data.r,
96+
ad: response.ad
97+
};
98+
bidResponses.push(bidResponse);
99+
}
100+
});
101+
} catch (error) {
102+
utils.logError(error);
103+
}
104+
return bidResponses;
105+
}
106+
}
107+
registerBidder(spec);

modules/colombiaBidAdapter.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Overview
2+
3+
```
4+
Module Name: COLOMBIA Bidder Adapter
5+
Module Type: Bidder Adapter
6+
Maintainer: [email protected]
7+
```
8+
9+
# Description
10+
11+
Connect to COLOMBIA for bids.
12+
13+
COLOMBIA adapter requires setup and approval from the COLOMBIA team. Please reach out to your account team or [email protected] for more information.
14+
15+
# Test Parameters
16+
```
17+
var adUnits = [{
18+
code: 'test-ad-div',
19+
mediaTypes: {
20+
banner: {
21+
sizes: [[300, 250],[728,90],[320,50]]
22+
}
23+
},
24+
bids: [{
25+
bidder: 'colombia',
26+
params: {
27+
placementId: '540799'
28+
}
29+
}]
30+
}];
31+
```

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import { expect } from 'chai';
2+
import { spec } from 'modules/colombiaBidAdapter';
3+
import { newBidder } from 'src/adapters/bidderFactory';
4+
5+
const HOST_NAME = document.location.protocol + '//' + window.location.host;
6+
const ENDPOINT = 'https://ade.clmbtech.com/cde/prebid.htm';
7+
8+
describe('colombiaBidAdapter', function() {
9+
const adapter = newBidder(spec);
10+
11+
describe('isBidRequestValid', function () {
12+
let bid = {
13+
'bidder': 'colombia',
14+
'params': {
15+
placementId: '307466'
16+
},
17+
'adUnitCode': 'adunit-code',
18+
'sizes': [
19+
[300, 250]
20+
],
21+
'bidId': '23beaa6af6cdde',
22+
'bidderRequestId': '19c0c1efdf37e7',
23+
'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1',
24+
};
25+
26+
it('should return true when required params found', function () {
27+
expect(spec.isBidRequestValid(bid)).to.equal(true);
28+
});
29+
30+
it('should return false when placementId not passed correctly', function () {
31+
bid.params.placementId = '';
32+
expect(spec.isBidRequestValid(bid)).to.equal(false);
33+
});
34+
35+
it('should return false when require params are not passed', function () {
36+
let bid = Object.assign({}, bid);
37+
bid.params = {};
38+
expect(spec.isBidRequestValid(bid)).to.equal(false);
39+
});
40+
});
41+
42+
describe('buildRequests', function () {
43+
let bidRequests = [
44+
{
45+
'bidder': 'colombia',
46+
'params': {
47+
placementId: '307466'
48+
},
49+
'adUnitCode': 'adunit-code1',
50+
'sizes': [
51+
[300, 250]
52+
],
53+
'bidId': '23beaa6af6cdde',
54+
'bidderRequestId': '19c0c1efdf37e7',
55+
'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1',
56+
},
57+
{
58+
'bidder': 'colombia',
59+
'params': {
60+
placementId: '307466'
61+
},
62+
'adUnitCode': 'adunit-code2',
63+
'sizes': [
64+
[300, 250]
65+
],
66+
'bidId': '382091349b149f"',
67+
'bidderRequestId': '"1f9c98192de2511"',
68+
'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1',
69+
}
70+
];
71+
let bidderRequest = {
72+
refererInfo: {
73+
numIframes: 0,
74+
reachedTop: true,
75+
referer: 'http://example.com',
76+
stack: ['http://example.com']
77+
}
78+
};
79+
80+
const request = spec.buildRequests(bidRequests);
81+
it('sends bid request to our endpoint via POST', function () {
82+
expect(request[0].method).to.equal('POST');
83+
});
84+
85+
it('attaches source and version to endpoint URL as query params', function () {
86+
expect(request[0].url).to.equal(ENDPOINT);
87+
});
88+
});
89+
90+
describe('interpretResponse', function () {
91+
let bidRequest = [
92+
{
93+
'method': 'POST',
94+
'url': 'https://ade.clmbtech.com/cde/prebid.htm',
95+
'data': {
96+
'v': 'hb1',
97+
'p': '307466',
98+
'w': '300',
99+
'h': '250',
100+
'cb': 12892917383,
101+
'r': 'http%3A%2F%2Flocalhost%3A9876%2F%3Fid%3D74552836',
102+
'uid': '23beaa6af6cdde',
103+
't': 'i',
104+
}
105+
}
106+
];
107+
108+
let serverResponse = [{
109+
'ad': '<div>This is test case for colombia adapter</div> ',
110+
'cpm': 3.14,
111+
'creativeId': '6b958110-612c-4b03-b6a9-7436c9f746dc-1sk24',
112+
'currency': 'USD',
113+
'requestId': '23beaa6af6cdde',
114+
'width': 728,
115+
'height': 90,
116+
'netRevenue': true,
117+
'ttl': 600,
118+
'dealid': '',
119+
'referrer': 'http%3A%2F%2Flocalhost%3A9876%2F%3Fid%3D74552836'
120+
}];
121+
122+
it('should get the correct bid response', function () {
123+
let expectedResponse = [{
124+
'requestId': '23beaa6af6cdde',
125+
'cpm': 3.14,
126+
'width': 728,
127+
'height': 90,
128+
'creativeId': '6b958110-612c-4b03-b6a9-7436c9f746dc-1sk24',
129+
'dealId': '',
130+
'currency': 'USD',
131+
'netRevenue': true,
132+
'ttl': 300,
133+
'referrer': 'http%3A%2F%2Flocalhost%3A9876%2F%3Fid%3D74552836',
134+
'ad': '<div>This is test case for colombia adapter</div>'
135+
}];
136+
let result = spec.interpretResponse(serverResponse, bidRequest[0]);
137+
expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0]));
138+
});
139+
140+
it('handles empty bid response', function () {
141+
let response = {
142+
body: {
143+
'uid': '23beaa6af6cdde',
144+
'height': 0,
145+
'creativeId': '',
146+
'statusMessage': 'Bid returned empty or error response',
147+
'width': 0,
148+
'cpm': 0
149+
}
150+
};
151+
let result = spec.interpretResponse(response, bidRequest[0]);
152+
expect(result.length).to.equal(0);
153+
});
154+
});
155+
});

0 commit comments

Comments
 (0)