Skip to content

Commit ef606ad

Browse files
telariaEngolafbuitelaar
authored andcommitted
Modified the Telaria Bid Adapter to use bid.mediaTypes.video.playerSize instead of bid.sizes (prebid#3377)
* Added telaria bid adapter * more documentation * Added more test cases. And improved some code in the adapter * Removed the check for optional params, they are handled in the server. Also updated certain param names used in the test spec. * added some spaces to fix CircleCI tests * added some spaces to fix CircleCI tests * fixed code indentation in /spec/AnalyticsAdapter_spec.js which causing the CircleCI tests to fail. * Reverted the changes * merged with prebid master. * creative Id is required when we build a response but our server doesn't always have the crid, so using a sentinel value when we don't have the crid. * - removed an un used method - Removed the package-lock file. * merging to master * updated telaria bid adapter to use player size provided by the bid.mediaTypes.video.playerSize instead of bid.sizes. prebid#3331 * - removed the requirement for having player size - updated the test spec to reflect the above change - removed changes to the package-lock.json file. * added a param to the ad call url to let us know that the request is coming via hb. * to lower casing the bidder code.
1 parent 90bd1c0 commit ef606ad

File tree

2 files changed

+87
-55
lines changed

2 files changed

+87
-55
lines changed

modules/telariaBidAdapter.js

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as utils from 'src/utils';
22
import * as bidfactory from 'src/bidfactory';
33
import {registerBidder} from 'src/adapters/bidderFactory';
4-
import {config} from 'src/config';
54
import {VIDEO} from '../src/mediaTypes';
65
import {STATUS} from 'src/constants';
76

@@ -24,17 +23,18 @@ export const spec = {
2423
/**
2524
* Make a server request from the list of BidRequests.
2625
* @param validBidRequests list of valid bid requests that have passed isBidRequestValid check
26+
* @param bidderRequest
2727
* @returns {Array} of url objects
2828
*/
29-
buildRequests: function (validBidRequests) {
29+
buildRequests: function (validBidRequests, bidderRequest) {
3030
let requests = [];
3131

3232
validBidRequests.forEach(bid => {
33-
let url = generateUrl(bid);
33+
let url = generateUrl(bid, bidderRequest);
3434
if (url) {
3535
requests.push({
3636
method: 'GET',
37-
url: generateUrl(bid),
37+
url: generateUrl(bid, bidderRequest),
3838
bidId: bid.bidId,
3939
vastUrl: url.split('&fmt=json')[0]
4040
});
@@ -84,7 +84,7 @@ export const spec = {
8484
utils.logError(errorMessage);
8585
} else if (bidResult.seatbid && bidResult.seatbid.length > 0) {
8686
bidResult.seatbid[0].bid.forEach(tag => {
87-
bids.push(createBid(STATUS.GOOD, bidderRequest, tag, width, height, bidResult.seatbid[0].seat));
87+
bids.push(createBid(STATUS.GOOD, bidderRequest, tag, width, height, bidResult.seatbid[0].seat.toLowerCase()));
8888
});
8989
}
9090

@@ -112,28 +112,36 @@ export const spec = {
112112
* Generates the url based on the parameters given. Sizes, supplyCode & adCode are required.
113113
* The format is: [L,W] or [[L1,W1],...]
114114
* @param bid
115+
* @param bidderRequest
115116
* @returns {string}
116117
*/
117-
function generateUrl(bid) {
118-
let width, height;
119-
if (!bid.sizes) {
120-
return '';
118+
function generateUrl(bid, bidderRequest) {
119+
let playerSize = (bid.mediaTypes && bid.mediaTypes.video && bid.mediaTypes.video.playerSize);
120+
if (!playerSize) {
121+
utils.logWarn('Although player size isn\'t required it is highly recommended');
121122
}
122123

123-
if (utils.isArray(bid.sizes) && (bid.sizes.length === 2) && (!isNaN(bid.sizes[0]) && !isNaN(bid.sizes[1]))) {
124-
width = bid.sizes[0];
125-
height = bid.sizes[1];
126-
} else if (typeof bid.sizes === 'object') {
127-
// take the primary (first) size from the array
128-
width = bid.sizes[0][0];
129-
height = bid.sizes[0][1];
124+
let width, height;
125+
if (playerSize) {
126+
if (utils.isArray(playerSize) && (playerSize.length === 2) && (!isNaN(playerSize[0]) && !isNaN(playerSize[1]))) {
127+
width = playerSize[0];
128+
height = playerSize[1];
129+
} else if (typeof playerSize === 'object') {
130+
width = playerSize[0][0];
131+
height = playerSize[0][1];
132+
}
130133
}
131-
if (width && height && bid.params.supplyCode && bid.params.adCode) {
134+
135+
if (bid.params.supplyCode && bid.params.adCode) {
132136
let scheme = ((document.location.protocol === 'https:') ? 'https' : 'http') + '://';
133137
let url = scheme + bid.params.supplyCode + ENDPOINT + '?adCode=' + bid.params.adCode;
134138

135-
url += ('&playerWidth=' + width);
136-
url += ('&playerHeight=' + height);
139+
if (width) {
140+
url += ('&playerWidth=' + width);
141+
}
142+
if (height) {
143+
url += ('&playerHeight=' + height);
144+
}
137145

138146
for (let key in bid.params) {
139147
if (bid.params.hasOwnProperty(key) && bid.params[key]) {
@@ -145,8 +153,8 @@ function generateUrl(bid) {
145153
url += ('&srcPageUrl=' + encodeURIComponent(document.location.href));
146154
}
147155

148-
url += ('&transactionId=' + bid.transactionId);
149-
url += ('&referrer=' + config.getConfig('pageUrl') || utils.getTopWindowUrl());
156+
url += ('&transactionId=' + bid.transactionId + '&hb=1');
157+
url += ('&referrer=' + encodeURIComponent(bidderRequest.refererInfo.referer));
150158

151159
return (url + '&fmt=json');
152160
}

test/spec/modules/telariaBidAdapter_spec.js

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ const SUPPLY_CODE = 'ssp-demo-rm6rh';
88
const SIZES = [640, 480];
99
const REQUEST = {
1010
'code': 'video1',
11-
'sizes': [640, 480],
11+
'mediaTypes': {
12+
'video': {
13+
'playerSize': [[640, 480]],
14+
'context': 'instream'
15+
}
16+
},
1217
'mediaType': 'video',
1318
'bids': [{
1419
'bidder': 'tremor',
@@ -19,6 +24,12 @@ const REQUEST = {
1924
}]
2025
};
2126

27+
const BIDDER_REQUEST = {
28+
'refererInfo': {
29+
'referer': 'www.test.com'
30+
}
31+
};
32+
2233
const RESPONSE = {
2334
'cur': 'USD',
2435
'id': '3dba13e35f3d42f998bc7e65fd871889',
@@ -34,26 +45,26 @@ const RESPONSE = {
3445
}]
3546
};
3647

37-
describe('TelariaAdapter', function () {
48+
describe('TelariaAdapter', () => {
3849
const adapter = newBidder(spec);
3950

40-
describe('inherited functions', function () {
41-
it('exists and is a function', function () {
51+
describe('inherited functions', () => {
52+
it('exists and is a function', () => {
4253
expect(adapter.callBids).to.exist.and.to.be.a('function');
4354
});
4455
});
4556

46-
describe('isBidRequestValid', function () {
57+
describe('isBidRequestValid', () => {
4758
let bid = REQUEST.bids[0];
4859

49-
it('should return true when required params found', function () {
60+
it('should return true when required params found', () => {
5061
let tempBid = bid;
5162
tempBid.params.adCode = 'ssp-!demo!-lufip';
5263
tempBid.params.supplyCode = 'ssp-demo-rm6rh';
5364
expect(spec.isBidRequestValid(bid)).to.equal(true);
5465
});
5566

56-
it('should return true when required params found', function () {
67+
it('should return true when required params found', () => {
5768
let tempBid = bid;
5869
delete tempBid.params;
5970
tempBid.params = {
@@ -64,35 +75,40 @@ describe('TelariaAdapter', function () {
6475
expect(spec.isBidRequestValid(tempBid)).to.equal(true);
6576
});
6677

67-
it('should return false when required params are not passed', function () {
78+
it('should return false when required params are not passed', () => {
6879
let tempBid = bid;
6980
tempBid.params = {};
7081
expect(spec.isBidRequestValid(tempBid)).to.equal(false);
7182
});
7283
});
7384

74-
describe('buildRequests', function () {
85+
describe('buildRequests', () => {
7586
const stub = [{
87+
mediaTypes: {
88+
video: {
89+
playerSize: [[640, 480]],
90+
context: 'instream'
91+
}
92+
},
7693
bidder: 'tremor',
77-
sizes: [[300, 250], [300, 600]],
7894
params: {
7995
supplyCode: 'ssp-demo-rm6rh',
8096
adCode: 'ssp-!demo!-lufip',
8197
videoId: 'MyCoolVideo'
8298
}
8399
}];
84100

85-
it('exists and is a function', function () {
101+
it('exists and is a function', () => {
86102
expect(spec.buildRequests).to.exist.and.to.be.a('function');
87103
});
88104

89-
it('requires supply code, ad code and sizes to make a request', function () {
90-
const tempRequest = spec.buildRequests(stub);
105+
it('requires supply code & ad code to make a request', () => {
106+
const tempRequest = spec.buildRequests(stub, BIDDER_REQUEST);
91107
expect(tempRequest.length).to.equal(1);
92108
});
93109

94-
it('generates an array of requests with 4 params, method, url, bidId and vastUrl', function () {
95-
const tempRequest = spec.buildRequests(stub);
110+
it('generates an array of requests with 4 params, method, url, bidId and vastUrl', () => {
111+
const tempRequest = spec.buildRequests(stub, BIDDER_REQUEST);
96112

97113
expect(tempRequest.length).to.equal(1);
98114
expect(tempRequest[0].method).to.equal('GET');
@@ -101,77 +117,85 @@ describe('TelariaAdapter', function () {
101117
expect(tempRequest[0].vastUrl).to.exist;
102118
});
103119

104-
it('requires sizes to make a request', function () {
120+
it('doesn\'t require player size but is highly recommended', () => {
105121
let tempBid = stub;
106-
tempBid[0].sizes = null;
107-
const tempRequest = spec.buildRequests(tempBid);
122+
tempBid[0].mediaTypes.video.playerSize = null;
123+
const tempRequest = spec.buildRequests(tempBid, BIDDER_REQUEST);
108124

109-
expect(tempRequest.length).to.equal(0);
125+
expect(tempRequest.length).to.equal(1);
110126
});
111127

112-
it('generates a valid request with sizes as an array of two elements', function () {
128+
it('generates a valid request with sizes as an array of two elements', () => {
113129
let tempBid = stub;
114-
tempBid[0].sizes = [640, 480];
115-
expect(spec.buildRequests(tempBid).length).to.equal(1);
130+
tempBid[0].mediaTypes.video.playerSize = [640, 480];
131+
tempBid[0].params.adCode = 'ssp-!demo!-lufip';
132+
tempBid[0].params.supplyCode = 'ssp-demo-rm6rh';
133+
let builtRequests = spec.buildRequests(tempBid, BIDDER_REQUEST);
134+
expect(builtRequests.length).to.equal(1);
116135
});
117136

118-
it('requires ad code and supply code to make a request', function () {
137+
it('requires ad code and supply code to make a request', () => {
119138
let tempBid = stub;
120139
tempBid[0].params.adCode = null;
121140
tempBid[0].params.supplyCode = null;
122141

123-
const tempRequest = spec.buildRequests(tempBid);
142+
const tempRequest = spec.buildRequests(tempBid, BIDDER_REQUEST);
124143

125144
expect(tempRequest.length).to.equal(0);
126145
});
127146
});
128147

129-
describe('interpretResponse', function () {
148+
describe('interpretResponse', () => {
130149
const responseStub = RESPONSE;
131150
const stub = [{
151+
mediaTypes: {
152+
video: {
153+
playerSize: [[640, 480]],
154+
context: 'instream'
155+
}
156+
},
132157
bidder: 'tremor',
133-
sizes: [[300, 250], [300, 600]],
134158
params: {
135159
supplyCode: 'ssp-demo-rm6rh',
136160
adCode: 'ssp-!demo!-lufip',
137161
videoId: 'MyCoolVideo'
138162
}
139163
}];
140164

141-
it('should get correct bid response', function () {
165+
it('should get correct bid response', () => {
142166
let expectedResponseKeys = ['bidderCode', 'width', 'height', 'statusMessage', 'adId', 'mediaType', 'source',
143167
'getStatusCode', 'getSize', 'requestId', 'cpm', 'creativeId', 'vastXml',
144168
'vastUrl', 'currency', 'netRevenue', 'ttl', 'ad'];
145169

146-
let bidRequest = spec.buildRequests(stub)[0];
170+
let bidRequest = spec.buildRequests(stub, BIDDER_REQUEST)[0];
147171
bidRequest.bidId = '1234';
148172
let result = spec.interpretResponse({body: responseStub}, bidRequest);
149173
expect(Object.keys(result[0])).to.have.members(expectedResponseKeys);
150174
});
151175

152-
it('handles nobid responses', function () {
176+
it('handles nobid responses', () => {
153177
let tempResponse = responseStub;
154178
tempResponse.seatbid = [];
155179

156-
let bidRequest = spec.buildRequests(stub)[0];
180+
let bidRequest = spec.buildRequests(stub, BIDDER_REQUEST)[0];
157181
bidRequest.bidId = '1234';
158182

159183
let result = spec.interpretResponse({body: tempResponse}, bidRequest);
160184
expect(result.length).to.equal(0);
161185
});
162186

163-
it('handles invalid responses', function () {
187+
it('handles invalid responses', () => {
164188
let result = spec.interpretResponse(null, {bbidderCode: 'telaria'});
165189
expect(result.length).to.equal(0);
166190
});
167191

168-
it('handles error responses', function () {
192+
it('handles error responses', () => {
169193
let result = spec.interpretResponse({body: {error: 'Invalid request'}}, {bbidderCode: 'telaria'});
170194
expect(result.length).to.equal(0);
171195
});
172196
});
173197

174-
describe('getUserSyncs', function () {
198+
describe('getUserSyncs', () => {
175199
const responses = [{body: RESPONSE}];
176200
responses[0].body.ext = {
177201
telaria: {
@@ -182,7 +206,7 @@ describe('TelariaAdapter', function () {
182206
}
183207
};
184208

185-
it('should get the correct number of sync urls', function () {
209+
it('should get the correct number of sync urls', () => {
186210
let urls = spec.getUserSyncs({pixelEnabled: true}, responses);
187211
expect(urls.length).to.equal(2);
188212
});

0 commit comments

Comments
 (0)