Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit dcd2789

Browse files
cs83DmitriChrisHuie
authored
Smartico Bid Adapter: add adomain for Prebid 5.0 (prebid#7115)
* Adding smartico adapter * bug prebid#6486 fix, added maintainer email * bug prebid#6486 fix, modified test parameters * bug prebid#6486 fix, modified test parameters #2 * prebid#6486 applied review related updates & fixes * prebid#6486 applied review related updates & fixes #2 * prebid#6486 applied review related updates & fixes #3 * samrtico adapter bug fix * smartico adapter unit test update after bug fixing * smartico adapter bug fix #2 * smartico adapter bug fix #3 * fix linting errors Co-authored-by: Dmitri <[email protected]> Co-authored-by: Chris Huie <[email protected]>
1 parent f150d71 commit dcd2789

File tree

2 files changed

+243
-0
lines changed

2 files changed

+243
-0
lines changed

modules/smarticoBidAdapter.js

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import { registerBidder } from '../src/adapters/bidderFactory.js';
2+
import { BANNER } from '../src/mediaTypes.js';
3+
import find from 'core-js-pure/features/array/find.js';
4+
5+
const SMARTICO_CONFIG = {
6+
bidRequestUrl: 'https://trmads.eu/preBidRequest',
7+
widgetUrl: 'https://trmads.eu/get',
8+
method: 'POST'
9+
}
10+
11+
const BIDDER_CODE = 'smartico';
12+
13+
export const spec = {
14+
code: BIDDER_CODE,
15+
supportedMediaTypes: [BANNER],
16+
isBidRequestValid: function (bid) {
17+
return !!(bid && bid.params && bid.params.token && bid.params.placementId);
18+
},
19+
buildRequests: function (validBidRequests, bidderRequest) {
20+
var i
21+
var j
22+
var bid
23+
var bidParam
24+
var bidParams = []
25+
var sizes
26+
var frameWidth = Math.round(window.screen.width)
27+
var frameHeight = Math.round(window.screen.height)
28+
for (i = 0; i < validBidRequests.length; i++) {
29+
bid = validBidRequests[i]
30+
if (bid.sizes) {
31+
sizes = bid.sizes
32+
} else if (typeof (BANNER) != 'undefined' && bid.mediaTypes && bid.mediaTypes[BANNER] && bid.mediaTypes[BANNER].sizes) {
33+
sizes = bid.mediaTypes[BANNER].sizes
34+
} else if (frameWidth && frameHeight) {
35+
sizes = [[frameWidth, frameHeight]]
36+
} else {
37+
sizes = []
38+
}
39+
for (j = 0; j < sizes.length; j++) {
40+
bidParam = {
41+
token: bid.params.token || '',
42+
bidId: bid.bidId,
43+
'banner-format-width': sizes[j][0],
44+
'banner-format-height': sizes[j][1]
45+
}
46+
if (bid.params.bannerFormat) {
47+
bidParam['banner-format'] = bid.params.bannerFormat
48+
}
49+
if (bid.params.language) {
50+
bidParam.language = bid.params.language
51+
}
52+
if (bid.params.region) {
53+
bidParam.region = bid.params.region
54+
}
55+
if (bid.params.regions && (bid.params.regions instanceof String || (bid.params.regions instanceof Array && bid.params.regions.length))) {
56+
bidParam.regions = bid.params.regions
57+
if (bidParam.regions instanceof Array) {
58+
bidParam.regions = bidParam.regions.join(',')
59+
}
60+
}
61+
bidParams.push(bidParam)
62+
}
63+
}
64+
65+
var ServerRequestObjects = {
66+
method: SMARTICO_CONFIG.method,
67+
url: SMARTICO_CONFIG.bidRequestUrl,
68+
bids: validBidRequests,
69+
data: {bidParams: bidParams, auctionId: bidderRequest.auctionId}
70+
}
71+
return ServerRequestObjects;
72+
},
73+
interpretResponse: function (serverResponse, bidRequest) {
74+
var i
75+
var bid
76+
var bidObject
77+
var url
78+
var html
79+
var ad
80+
var ads
81+
var token
82+
var language
83+
var scriptId
84+
var bidResponses = []
85+
ads = serverResponse.body
86+
for (i = 0; i < ads.length; i++) {
87+
ad = ads[i]
88+
bid = find(bidRequest.bids, bid => bid.bidId === ad.bidId)
89+
if (bid) {
90+
token = bid.params.token || ''
91+
92+
language = bid.params.language || SMARTICO_CONFIG.language || ''
93+
94+
scriptId = encodeURIComponent('smartico-widget-' + bid.params.placementId + '-' + i)
95+
96+
url = SMARTICO_CONFIG.widgetUrl + '?token=' + encodeURIComponent(token) + '&auction-id=' + encodeURIComponent(bid.auctionId) + '&from-auction-buffer=1&own_session=1&ad=' + encodeURIComponent(ad.id) + '&scriptid=' + scriptId + (ad.bannerFormatAlias ? '&banner-format=' + encodeURIComponent(ad.bannerFormatAlias) : '') + (language ? '&language=' + encodeURIComponent(language) : '')
97+
98+
html = '<script id="' + scriptId + '" async defer type="text/javascript" src="' + url + '"><\/script>'
99+
100+
bidObject = {
101+
requestId: bid.bidId,
102+
cpm: ad.cpm,
103+
width: parseInt(ad.bannerFormatWidth),
104+
height: parseInt(ad.bannerFormatHeight),
105+
creativeId: ad.id,
106+
netRevenue: !!ad.netRevenue,
107+
currency: ad.currency,
108+
ttl: ad.ttl,
109+
ad: html
110+
}
111+
bidResponses.push(bidObject);
112+
}
113+
}
114+
return bidResponses;
115+
}
116+
}
117+
registerBidder(spec)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import {expect} from 'chai';
2+
import {spec} from 'modules/smarticoBidAdapter.js';
3+
import {newBidder} from 'src/adapters/bidderFactory.js';
4+
5+
describe('smarticoBidAdapter', function () {
6+
const adapter = newBidder(spec);
7+
let bid = {
8+
adUnitCode: 'adunit-code',
9+
auctionId: '5kaj89l8-3456-2s56-c455-4g6h78jsdfgf',
10+
bidRequestsCount: 1,
11+
bidder: 'smartico',
12+
bidderRequestId: '24081afs940568',
13+
bidderRequestsCount: 1,
14+
bidderWinsCount: 0,
15+
bidId: '22499d052045',
16+
mediaTypes: {banner: {sizes: [[300, 250]]}},
17+
params: {
18+
token: 'FNVzUGZn9ebpIOoheh3kEJ2GQ6H6IyMH39sHXaya',
19+
placementId: 'testPlacementId'
20+
},
21+
sizes: [
22+
[300, 250]
23+
],
24+
transactionId: '34562345-4dg7-46g7-4sg6-45gdsdj8fd56'
25+
}
26+
let bidderRequests = {
27+
auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917',
28+
auctionStart: 1579746300522,
29+
bidderCode: 'myBidderCode',
30+
bidderRequestId: '15246a574e859f',
31+
bids: [bid],
32+
refererInfo: {
33+
canonicalUrl: '',
34+
numIframes: 0,
35+
reachedTop: true
36+
}
37+
}
38+
describe('isBidRequestValid', function () {
39+
it('should return true where required params found', function () {
40+
expect(spec.isBidRequestValid(bid)).to.equal(true);
41+
});
42+
});
43+
describe('buildRequests', function () {
44+
let bidRequests = [ bid ];
45+
let request = spec.buildRequests(bidRequests, bidderRequests);
46+
it('sends bid request via POST', function () {
47+
expect(request.method).to.equal('POST');
48+
});
49+
it('must contain token', function() {
50+
expect(request.data.bidParams[0].token).to.equal('FNVzUGZn9ebpIOoheh3kEJ2GQ6H6IyMH39sHXaya');
51+
});
52+
it('must contain auctionId', function() {
53+
expect(request.data.auctionId).to.exist.and.to.be.a('string')
54+
});
55+
it('must contain valid width and height', function() {
56+
expect(request.data.bidParams[0]['banner-format-width']).to.exist.and.to.be.a('number')
57+
expect(request.data.bidParams[0]['banner-format-height']).to.exist.and.to.be.a('number')
58+
});
59+
});
60+
61+
describe('interpretResponse', function () {
62+
let bidRequest = {
63+
method: 'POST',
64+
url: 'https://trmads.eu/preBidRequest',
65+
bids: [bid],
66+
data: [{
67+
token: 'FNVzUGZn9ebpIOoheh3kEJ2GQ6H6IyMH39sHXaya',
68+
bidId: '22499d052045',
69+
'banner-format-width': 300,
70+
'banner-format-height': 250,
71+
placementId: 'testPlacementId',
72+
}]
73+
};
74+
let serverResponse = {
75+
body: [{
76+
bidId: '22499d052045',
77+
id: 987654,
78+
cpm: 10,
79+
netRevenue: 0,
80+
currency: 'EUR',
81+
ttl: 30,
82+
bannerFormatWidth: 300,
83+
bannerFormatHeight: 250,
84+
bannerFormatAlias: 'medium_rectangle'
85+
}]
86+
};
87+
let expectedResponse = [{
88+
requestId: bid.bidId,
89+
cpm: 10,
90+
width: 300,
91+
height: 250,
92+
creativeId: 987654,
93+
currency: 'EUR',
94+
netRevenue: false, // gross
95+
ttl: 30,
96+
ad: '<script id="smartico-widget-testPlacementId-0" async defer type="text/javascript" src="https://trmads.eu/get?token=FNVzUGZn9ebpIOoheh3kEJ2GQ6H6IyMH39sHXaya&auction-id=5kaj89l8-3456-2s56-c455-4g6h78jsdfgf&from-auction-buffer=1&own_session=1&ad=987654&scriptid=smartico-widget-testPlacementId-0&banner-format=medium_rectangle"><\/script>'}];
97+
let result = spec.interpretResponse(serverResponse, bidRequest);
98+
it('should contain correct creativeId', function () {
99+
expect(result[0].creativeId).to.equal(expectedResponse[0].creativeId)
100+
});
101+
it('should contain correct cpm', function () {
102+
expect(result[0].cpm).to.equal(expectedResponse[0].cpm)
103+
});
104+
it('should contain correct width', function () {
105+
expect(result[0].width).to.equal(expectedResponse[0].width)
106+
});
107+
it('should contain correct height', function () {
108+
expect(result[0].height).to.equal(expectedResponse[0].height)
109+
});
110+
it('should contain correct requestId', function () {
111+
expect(result[0].requestId).to.equal(expectedResponse[0].requestId)
112+
});
113+
it('should contain correct ttl', function () {
114+
expect(result[0].ttl).to.equal(expectedResponse[0].ttl)
115+
});
116+
it('should contain correct netRevenue', function () {
117+
expect(result[0].netRevenue).to.equal(expectedResponse[0].netRevenue)
118+
});
119+
it('should contain correct netRevenue', function () {
120+
expect(result[0].currency).to.equal(expectedResponse[0].currency)
121+
});
122+
it('should contain correct ad content', function () {
123+
expect(result[0].ad).to.equal(expectedResponse[0].ad)
124+
});
125+
});
126+
});

0 commit comments

Comments
 (0)