Skip to content

Commit f25bc65

Browse files
afsheenbbretg
authored andcommitted
ozone adapter - fixup for gdpr and device objects (prebid#3593)
* fixup for gdpr and device objects * v1.4.6 - clean up for unit test following changes submitted in 1.4.5 - removed 3 IF statements because the condition was already tested in the validation method. - added more tests to the spec file (check ozoneData, customData & lotameData are in the right place, and also NOT in the old location as well as some GDPR based unit tests) * explicitly added bidder name to debug logging statements
1 parent 41867ad commit f25bc65

File tree

2 files changed

+155
-53
lines changed

2 files changed

+155
-53
lines changed

modules/ozoneBidAdapter.js

+46-45
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const BIDDER_CODE = 'ozone';
77

88
const OZONEURI = 'https://elb.the-ozone-project.com/openrtb2/auction';
99
const OZONECOOKIESYNC = 'https://elb.the-ozone-project.com/static/load-cookie.html';
10-
const OZONEVERSION = '1.4.4';
10+
const OZONEVERSION = '1.4.7';
1111
export const spec = {
1212
code: BIDDER_CODE,
1313

@@ -18,72 +18,78 @@ export const spec = {
1818
*/
1919
isBidRequestValid(bid) {
2020
if (!(bid.params.hasOwnProperty('placementId'))) {
21-
utils.logInfo('OZONE BID ADAPTER VALIDATION FAILED : missing placementId : siteId, placementId and publisherId are REQUIRED');
21+
utils.logInfo('OZONE: OZONE BID ADAPTER VALIDATION FAILED : missing placementId : siteId, placementId and publisherId are REQUIRED');
2222
return false;
2323
}
2424
if (!(bid.params.placementId).toString().match(/^[0-9]{10}$/)) {
25-
utils.logInfo('OZONE BID ADAPTER VALIDATION FAILED : placementId must be exactly 10 numeric characters');
25+
utils.logInfo('OZONE: OZONE BID ADAPTER VALIDATION FAILED : placementId must be exactly 10 numeric characters');
2626
return false;
2727
}
2828
if (!(bid.params.hasOwnProperty('publisherId'))) {
29-
utils.logInfo('OZONE BID ADAPTER VALIDATION FAILED : missing publisherId : siteId, placementId and publisherId are REQUIRED');
29+
utils.logInfo('OZONE: OZONE BID ADAPTER VALIDATION FAILED : missing publisherId : siteId, placementId and publisherId are REQUIRED');
3030
return false;
3131
}
3232
if (!(bid.params.publisherId).toString().match(/^[a-zA-Z0-9\-]{12}$/)) {
33-
utils.logInfo('OZONE BID ADAPTER VALIDATION FAILED : publisherId must be exactly 12 alphanumieric characters including hyphens');
33+
utils.logInfo('OZONE: OZONE BID ADAPTER VALIDATION FAILED : publisherId must be exactly 12 alphanumieric characters including hyphens');
3434
return false;
3535
}
3636
if (!(bid.params.hasOwnProperty('siteId'))) {
37-
utils.logInfo('OZONE BID ADAPTER VALIDATION FAILED : missing siteId : siteId, placementId and publisherId are REQUIRED');
37+
utils.logInfo('OZONE: OZONE BID ADAPTER VALIDATION FAILED : missing siteId : siteId, placementId and publisherId are REQUIRED');
3838
return false;
3939
}
4040
if (!(bid.params.siteId).toString().match(/^[0-9]{10}$/)) {
41-
utils.logInfo('OZONE BID ADAPTER VALIDATION FAILED : siteId must be exactly 10 numeric characters');
41+
utils.logInfo('OZONE: OZONE BID ADAPTER VALIDATION FAILED : siteId must be exactly 10 numeric characters');
4242
return false;
4343
}
4444
if (bid.params.hasOwnProperty('customData')) {
4545
if (typeof bid.params.customData !== 'object') {
46-
utils.logInfo('OZONE BID ADAPTER VALIDATION FAILED : customData is not an object');
46+
utils.logInfo('OZONE: OZONE BID ADAPTER VALIDATION FAILED : customData is not an object');
4747
return false;
4848
}
4949
}
5050
if (bid.params.hasOwnProperty('customParams')) {
51-
utils.logInfo('OZONE BID ADAPTER VALIDATION FAILED : customParams should be renamed to customData');
51+
utils.logInfo('OZONE: OZONE BID ADAPTER VALIDATION FAILED : customParams should be renamed to customData');
5252
return false;
5353
}
5454
if (bid.params.hasOwnProperty('ozoneData')) {
5555
if (typeof bid.params.ozoneData !== 'object') {
56-
utils.logInfo('OZONE BID ADAPTER VALIDATION FAILED : ozoneData is not an object');
56+
utils.logInfo('OZONE: OZONE BID ADAPTER VALIDATION FAILED : ozoneData is not an object');
5757
return false;
5858
}
5959
}
6060
if (bid.params.hasOwnProperty('lotameData')) {
6161
if (typeof bid.params.lotameData !== 'object') {
62-
utils.logInfo('OZONE BID ADAPTER VALIDATION FAILED : lotameData is not an object');
62+
utils.logInfo('OZONE: OZONE BID ADAPTER VALIDATION FAILED : lotameData is not an object');
6363
return false;
6464
}
6565
}
6666
return true;
6767
},
6868
buildRequests(validBidRequests, bidderRequest) {
69-
utils.logInfo('ozone v' + OZONEVERSION + ' validBidRequests', validBidRequests, 'bidderRequest', bidderRequest);
70-
utils.logInfo('buildRequests setting auctionId', bidderRequest.auctionId);
69+
utils.logInfo('OZONE: ozone v' + OZONEVERSION + ' validBidRequests', validBidRequests, 'bidderRequest', bidderRequest);
70+
utils.logInfo('OZONE: buildRequests setting auctionId', bidderRequest.auctionId);
7171
let singleRequest = config.getConfig('ozone.singleRequest');
72+
7273
singleRequest = singleRequest !== false; // undefined & true will be true
73-
utils.logInfo('config ozone.singleRequest : ', singleRequest);
74+
utils.logInfo('OZONE: config ozone.singleRequest : ', singleRequest);
7475
let htmlParams = validBidRequests[0].params; // the html page config params will be included in each element
7576
let ozoneRequest = {}; // we only want to set specific properties on this, not validBidRequests[0].params
7677
// ozoneRequest['id'] = utils.generateUUID();
7778

7879
delete ozoneRequest.test; // don't allow test to be set in the config - ONLY use $_GET['pbjs_debug']
7980
if (bidderRequest.gdprConsent) {
81+
utils.logInfo('OZONE: ADDING GDPR info');
8082
ozoneRequest.regs = {};
8183
ozoneRequest.regs.ext = {};
8284
ozoneRequest.regs.ext.gdpr = bidderRequest.gdprConsent.gdprApplies === true ? 1 : 0;
8385
if (ozoneRequest.regs.ext.gdpr) {
84-
ozoneRequest.regs.ext.consent = bidderRequest.gdprConsent.consentString;
86+
ozoneRequest.user = {};
87+
ozoneRequest.user.ext = {'consent': bidderRequest.gdprConsent.consentString};
8588
}
89+
} else {
90+
utils.logInfo('OZONE: WILL NOT ADD GDPR info');
8691
}
92+
ozoneRequest.device = {'w': window.innerWidth, 'h': window.innerHeight};
8793
let tosendtags = validBidRequests.map(ozoneBidRequest => {
8894
var obj = {};
8995
obj.id = ozoneBidRequest.bidId; // this causes a failure if we change it to something else
@@ -95,25 +101,25 @@ export const spec = {
95101
/* NOTE - if there is sizes element in the config root then there will be a mediaTypes.banner element automatically generated for us, so this code is deprecated */
96102
if (!ozoneBidRequest.hasOwnProperty('mediaTypes')) {
97103
if (ozoneBidRequest.hasOwnProperty('sizes')) {
98-
utils.logInfo('no mediaTypes detected - will use the sizes array in the config root');
104+
utils.logInfo('OZONE: no mediaTypes detected - will use the sizes array in the config root');
99105
arrBannerSizes = ozoneBidRequest.sizes;
100106
} else {
101-
utils.logInfo('no mediaTypes detected, no sizes array in the config root either. Cannot set sizes for banner type');
107+
utils.logInfo('OZONE: no mediaTypes detected, no sizes array in the config root either. Cannot set sizes for banner type');
102108
}
103109
} else {
104110
if (ozoneBidRequest.mediaTypes.hasOwnProperty(BANNER)) {
105111
arrBannerSizes = ozoneBidRequest.mediaTypes[BANNER].sizes; /* Note - if there is a sizes element in the config root it will be pushed into here */
106-
utils.logInfo('setting banner size from the mediaTypes.banner element for bidId ' + obj.id + ': ', arrBannerSizes);
112+
utils.logInfo('OZONE: setting banner size from the mediaTypes.banner element for bidId ' + obj.id + ': ', arrBannerSizes);
107113
}
108114
// Video integration is not complete yet
109115
if (ozoneBidRequest.mediaTypes.hasOwnProperty(VIDEO)) {
110116
obj.video = ozoneBidRequest.mediaTypes[VIDEO];
111-
utils.logInfo('setting video object from the mediaTypes.video element: ' + obj.id + ':', obj.video);
117+
utils.logInfo('OZONE: setting video object from the mediaTypes.video element: ' + obj.id + ':', obj.video);
112118
}
113119
// Native integration is not complete yet
114120
if (ozoneBidRequest.mediaTypes.hasOwnProperty(NATIVE)) {
115121
obj.native = ozoneBidRequest.mediaTypes[NATIVE];
116-
utils.logInfo('setting native object from the mediaTypes.native element: ' + obj.id + ':', obj.native);
122+
utils.logInfo('OZONE: setting native object from the mediaTypes.native element: ' + obj.id + ':', obj.native);
117123
}
118124
}
119125
// build the banner request using banner sizes we found in either possible location:
@@ -127,15 +133,10 @@ export const spec = {
127133
})
128134
};
129135
}
130-
if (ozoneBidRequest.params.hasOwnProperty('placementId')) {
131-
obj.placementId = (ozoneBidRequest.params.placementId).toString();
132-
}
133-
if (ozoneBidRequest.params.hasOwnProperty('publisherId')) {
134-
obj.publisherId = (ozoneBidRequest.params.publisherId).toString();
135-
}
136-
if (ozoneBidRequest.params.hasOwnProperty('siteId')) {
137-
obj.siteId = (ozoneBidRequest.params.siteId).toString();
138-
}
136+
// these 3 MUST exist - we check them in the validation method
137+
obj.placementId = (ozoneBidRequest.params.placementId).toString();
138+
obj.publisherId = (ozoneBidRequest.params.publisherId).toString();
139+
obj.siteId = (ozoneBidRequest.params.siteId).toString();
139140
// build the imp['ext'] object
140141
obj.ext = {'prebid': {'storedrequest': {'id': (ozoneBidRequest.params.placementId).toString()}}, 'ozone': {}};
141142
obj.ext.ozone.adUnitCode = ozoneBidRequest.adUnitCode; // eg. 'mpu'
@@ -161,7 +162,7 @@ export const spec = {
161162
// utils.logInfo('_ozoneInternal is', _ozoneInternal);
162163
// return the single request object OR the array:
163164
if (singleRequest) {
164-
utils.logInfo('buildRequests starting to generate response for a single request');
165+
utils.logInfo('OZONE: buildRequests starting to generate response for a single request');
165166
ozoneRequest.id = bidderRequest.auctionId; // Unique ID of the bid request, provided by the exchange.
166167
ozoneRequest.auctionId = bidderRequest.auctionId; // not sure if this should be here?
167168
ozoneRequest.imp = tosendtags;
@@ -172,29 +173,29 @@ export const spec = {
172173
data: JSON.stringify(ozoneRequest),
173174
bidderRequest: bidderRequest
174175
};
175-
utils.logInfo('buildRequests ozoneRequest for single = ', ozoneRequest);
176-
utils.logInfo('buildRequests going to return for single: ', ret);
176+
utils.logInfo('OZONE: buildRequests ozoneRequest for single = ', ozoneRequest);
177+
utils.logInfo('OZONE: buildRequests going to return for single: ', ret);
177178
return ret;
178179
}
179180

180181
// not single request - pull apart the tosendtags array & return an array of objects each containing one element in the imp array.
181182
let arrRet = tosendtags.map(imp => {
182-
utils.logInfo('buildRequests starting to generate non-single response, working on imp : ', imp);
183+
utils.logInfo('OZONE: buildRequests starting to generate non-single response, working on imp : ', imp);
183184
let ozoneRequestSingle = Object.assign({}, ozoneRequest);
184185
imp.ext.ozone.pageAuctionId = bidderRequest['auctionId']; // make a note in the ext object of what the original auctionId was, in the bidderRequest object
185186
ozoneRequestSingle.id = imp.ext.ozone.transactionId; // Unique ID of the bid request, provided by the exchange.
186187
ozoneRequestSingle.auctionId = imp.ext.ozone.transactionId; // not sure if this should be here?
187188
ozoneRequestSingle.imp = [imp];
188189
ozoneRequestSingle.source = {'tid': imp.ext.ozone.transactionId};
189-
utils.logInfo('buildRequests ozoneRequestSingle (for non-single) = ', ozoneRequestSingle);
190+
utils.logInfo('OZONE: buildRequests ozoneRequestSingle (for non-single) = ', ozoneRequestSingle);
190191
return {
191192
method: 'POST',
192193
url: OZONEURI,
193194
data: JSON.stringify(ozoneRequestSingle),
194195
bidderRequest: bidderRequest
195196
};
196197
});
197-
utils.logInfo('buildRequests going to return for non-single: ', arrRet);
198+
utils.logInfo('OZONE: buildRequests going to return for non-single: ', arrRet);
198199
return arrRet;
199200
},
200201
/**
@@ -205,7 +206,7 @@ export const spec = {
205206
* @returns {*}
206207
*/
207208
interpretResponse(serverResponse, request) {
208-
utils.logInfo('ozone v' + OZONEVERSION + ' interpretResponse', serverResponse, request);
209+
utils.logInfo('OZONE: version' + OZONEVERSION + ' interpretResponse', serverResponse, request);
209210
serverResponse = serverResponse.body || {};
210211
if (serverResponse.seatbid) {
211212
if (utils.isArray(serverResponse.seatbid)) {
@@ -219,19 +220,19 @@ export const spec = {
219220
let {seat: winningSeat, bid: winningBid} = ozoneGetWinnerForRequestBid(thisBid, serverResponse.seatbid);
220221

221222
if (winningBid == null) {
222-
utils.logInfo('FAILED to get winning bid for bid : ', thisBid, 'will skip. Possibly a non-single request, which will be missing some bid IDs');
223+
utils.logInfo('OZONE: FAILED to get winning bid for bid : ', thisBid, 'will skip. Possibly a non-single request, which will be missing some bid IDs');
223224
continue;
224225
}
225226

226227
const {defaultWidth, defaultHeight} = defaultSize(arrRequestBids[i]);
227228
winningBid = ozoneAddStandardProperties(winningBid, defaultWidth, defaultHeight);
228229

229-
utils.logInfo('Going to add the adserverTargeting custom parameters for key: ', ozoneInternalKey);
230+
utils.logInfo('OZONE: Going to add the adserverTargeting custom parameters for key: ', ozoneInternalKey);
230231
let adserverTargeting = {};
231232
let allBidsForThisBidid = ozoneGetAllBidsForBidId(ozoneInternalKey, serverResponse.seatbid);
232233
// add all the winning & non-winning bids for this bidId:
233234
Object.keys(allBidsForThisBidid).forEach(function(bidderName, index, ar2) {
234-
utils.logInfo('inside allBidsForThisBidid:foreach', bidderName, index, ar2, allBidsForThisBidid);
235+
utils.logInfo('OZONE: inside allBidsForThisBidid:foreach', bidderName, index, ar2, allBidsForThisBidid);
235236
adserverTargeting['oz_' + bidderName] = bidderName;
236237
adserverTargeting['oz_' + bidderName + '_pb'] = String(allBidsForThisBidid[bidderName].price);
237238
adserverTargeting['oz_' + bidderName + '_crid'] = String(allBidsForThisBidid[bidderName].crid);
@@ -246,14 +247,14 @@ export const spec = {
246247
adserverTargeting['oz_response_id'] = String(serverResponse.id);
247248

248249
winningBid.adserverTargeting = adserverTargeting;
249-
utils.logInfo('winner is', winningBid);
250+
utils.logInfo('OZONE: winner is', winningBid);
250251
arrWinners.push(winningBid);
251-
utils.logInfo('arrWinners is', arrWinners);
252+
utils.logInfo('OZONE: arrWinners is', arrWinners);
252253
}
253254
let winnersClean = arrWinners.filter(w => {
254255
return (w.bidId); // will be cast to boolean
255256
});
256-
utils.logInfo('going to return winnersClean:', winnersClean);
257+
utils.logInfo('OZONE: going to return winnersClean:', winnersClean);
257258
return winnersClean;
258259
} else {
259260
return [];
@@ -326,7 +327,7 @@ export function ozoneGetWinnerForRequestBid(requestBid, serverResponseSeatBid) {
326327
* @returns {} = {ozone:{obj}, appnexus:{obj}, ... }
327328
*/
328329
export function ozoneGetAllBidsForBidId(matchBidId, serverResponseSeatBid) {
329-
utils.logInfo('ozoneGetAllBidsForBidId - starting, with: ', matchBidId, serverResponseSeatBid);
330+
utils.logInfo('OZONE: ozoneGetAllBidsForBidId - starting, with: ', matchBidId, serverResponseSeatBid);
330331
let objBids = {};
331332
for (let j = 0; j < serverResponseSeatBid.length; j++) {
332333
let theseBids = serverResponseSeatBid[j].bid;
@@ -338,7 +339,7 @@ export function ozoneGetAllBidsForBidId(matchBidId, serverResponseSeatBid) {
338339
}
339340
}
340341
}
341-
utils.logInfo('ozoneGetAllBidsForBidId - going to return: ', objBids);
342+
utils.logInfo('OZONE: ozoneGetAllBidsForBidId - going to return: ', objBids);
342343
return objBids;
343344
}
344345

@@ -379,4 +380,4 @@ export function getTestQuerystringValue() {
379380
}
380381

381382
registerBidder(spec);
382-
utils.logInfo('ozoneBidAdapter ended');
383+
utils.logInfo('OZONE: ozoneBidAdapter ended');

0 commit comments

Comments
 (0)