Skip to content

Commit

Permalink
ozone adapter 2.1 - bug fix for multi bids + GDPR parameter handling (p…
Browse files Browse the repository at this point in the history
…rebid#3916)

* bug fix for multi bids + GDPR parameter handling

* Updated spec files and adapter files to remove references to ozoneData and more stringent GDPR checks.
  • Loading branch information
afsheenb authored and sa1omon committed Nov 28, 2019
1 parent 61abac3 commit f3d0580
Show file tree
Hide file tree
Showing 3 changed files with 304 additions and 69 deletions.
67 changes: 49 additions & 18 deletions modules/ozoneBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { Renderer } from '../src/Renderer'
const BIDDER_CODE = 'ozone';

const OZONEURI = 'https://elb.the-ozone-project.com/openrtb2/auction';
const OZONE_RENDERER_URL = 'https://prebid.the-ozone-project.com/ozone-renderer.js'

const OZONECOOKIESYNC = 'https://elb.the-ozone-project.com/static/load-cookie.html';
const OZONEVERSION = '2.0.0';
const OZONE_RENDERER_URL = 'https://prebid.the-ozone-project.com/ozone-renderer.js';

const OZONEVERSION = '2.1.1';

export const spec = {
code: BIDDER_CODE,
Expand Down Expand Up @@ -57,12 +57,6 @@ export const spec = {
utils.logInfo('OZONE: OZONE BID ADAPTER VALIDATION FAILED : customParams should be renamed to customData');
return false;
}
if (bid.params.hasOwnProperty('ozoneData')) {
if (typeof bid.params.ozoneData !== 'object') {
utils.logInfo('OZONE: OZONE BID ADAPTER VALIDATION FAILED : ozoneData is not an object');
return false;
}
}
if (bid.params.hasOwnProperty('lotameData')) {
if (typeof bid.params.lotameData !== 'object') {
utils.logInfo('OZONE: OZONE BID ADAPTER VALIDATION FAILED : lotameData is not an object');
Expand Down Expand Up @@ -90,18 +84,35 @@ export const spec = {
let htmlParams = validBidRequests[0].params; // the html page config params will be included in each element
let ozoneRequest = {}; // we only want to set specific properties on this, not validBidRequests[0].params
delete ozoneRequest.test; // don't allow test to be set in the config - ONLY use $_GET['pbjs_debug']
if (bidderRequest.gdprConsent) {

if (bidderRequest && bidderRequest.gdprConsent) {
utils.logInfo('OZONE: ADDING GDPR info');
ozoneRequest.regs = {};
ozoneRequest.regs.ext = {};
ozoneRequest.regs.ext.gdpr = bidderRequest.gdprConsent.gdprApplies === true ? 1 : 0;
ozoneRequest.regs.ext.gdpr = bidderRequest.gdprConsent.gdprApplies ? 1 : 0;
if (ozoneRequest.regs.ext.gdpr) {
ozoneRequest.user = {};
ozoneRequest.user.ext = {'consent': bidderRequest.gdprConsent.consentString};
ozoneRequest.user = ozoneRequest.user || {};
if (
bidderRequest.gdprConsent.vendorData &&
bidderRequest.gdprConsent.vendorData.vendorConsents &&
typeof bidderRequest.gdprConsent.consentString !== 'undefined'
) {
utils.logInfo('OZONE: found all info we need for GDPR - will add info to request object');
ozoneRequest.user.ext = {'consent': bidderRequest.gdprConsent.consentString};
// are we able to make this request?
let vendorConsents = bidderRequest.gdprConsent.vendorData.vendorConsents;
let boolGdprConsentForOzone = vendorConsents[524];
let arrGdprConsents = toFlatArray(bidderRequest.gdprConsent.vendorData.purposeConsents);
ozoneRequest.regs.ext.oz_con = boolGdprConsentForOzone ? 1 : 0;
ozoneRequest.regs.ext.gap = arrGdprConsents;
}
} else {
utils.logInfo('OZONE: **** Failed to find required info for GDPR for request object, even though bidderRequest.gdprConsent is TRUE ****');
}
} else {
utils.logInfo('OZONE: WILL NOT ADD GDPR info');
utils.logInfo('OZONE: WILL NOT ADD GDPR info; no bidderRequest.gdprConsent object was present.');
}

ozoneRequest.device = {'w': window.innerWidth, 'h': window.innerHeight};
let tosendtags = validBidRequests.map(ozoneBidRequest => {
var obj = {};
Expand Down Expand Up @@ -157,9 +168,6 @@ export const spec = {
if (ozoneBidRequest.params.hasOwnProperty('customData')) {
obj.ext.ozone.customData = ozoneBidRequest.params.customData;
}
if (ozoneBidRequest.params.hasOwnProperty('ozoneData')) {
obj.ext.ozone.ozoneData = ozoneBidRequest.params.ozoneData;
}
if (ozoneBidRequest.params.hasOwnProperty('lotameData')) {
obj.ext.ozone.lotameData = ozoneBidRequest.params.lotameData;
}
Expand Down Expand Up @@ -226,8 +234,8 @@ export const spec = {
serverResponse.seatbid = injectAdIdsIntoAllBidResponses(serverResponse.seatbid); // we now make sure that each bid in the bidresponse has a unique (within page) adId attribute.
for (let i = 0; i < serverResponse.seatbid.length; i++) {
let sb = serverResponse.seatbid[i];
const {defaultWidth, defaultHeight} = defaultSize(request.bidderRequest.bids[i]);
for (let j = 0; j < sb.bid.length; j++) {
const {defaultWidth, defaultHeight} = defaultSize(request.bidderRequest.bids[j]); // there should be the same number of bids as requests, so index [j] should always exist.
let thisBid = ozoneAddStandardProperties(sb.bid[j], defaultWidth, defaultHeight);

// from https://github.com/prebid/Prebid.js/pull/1082
Expand Down Expand Up @@ -310,6 +318,13 @@ export function checkDeepArray(Arr) {
}
}
export function defaultSize(thebidObj) {
if (!thebidObj) {
utils.logInfo('defaultSize received empty bid obj! going to return fixed default size');
return {
'defaultHeight': 250,
'defaultWidth': 300
};
}
const {sizes} = thebidObj;
const returnObject = {};
returnObject.defaultWidth = checkDeepArray(sizes)[0];
Expand Down Expand Up @@ -499,5 +514,21 @@ function outstreamRender(bid) {
window.ozoneVideo.outstreamRender(bid);
}

/**
* convert {1: true,
2: true,
3: true,
4: true,
5: true}
to : [1,2,3,4,5]
* @param obj
*/
function toFlatArray(obj) {
let ret = [];
Object.keys(obj).forEach(function(key) { if (obj[key]) { ret.push(parseInt(key)); } });
utils.logInfo('toFlatArray:', obj, 'returning', ret);
return ret;
}

registerBidder(spec);
utils.logInfo('OZONE: ozoneBidAdapter ended');
6 changes: 2 additions & 4 deletions modules/ozoneBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ adUnits = [{
publisherId: 'OZONENUK0001', /* an ID to identify the publisher account - required */
siteId: '4204204201', /* An ID used to identify a site within a publisher account - required */
placementId: '0420420421', /* an ID used to identify the piece of inventory - required - for appnexus test use 13144370. */
customData": [{"settings": {}, "targeting": {"key": "value", "key2": ["value1", "value2"],}}] /* optional array with 'targeting' placeholder for passing publisher specific key-values for targeting. */
ozoneData: {"key1": "value1", "key2": "value2"}, /* optional JSON placeholder for for passing ozone project key-values for targeting. */
customData: [{"settings": {}, "targeting": {"key": "value", "key2": ["value1", "value2"]}}],/* optional array with 'targeting' placeholder for passing publisher specific key-values for targeting. */
lotameData: {"key1": "value1", "key2": "value2"} /* optional JSON placeholder for passing Lotame DMP data */
}
}]
Expand Down Expand Up @@ -65,8 +64,7 @@ adUnits = [{
siteId: '4204204201', /* An ID used to identify a site within a publisher account - required */
customData: [{"settings": {}, "targeting": { "key": "value", "key2": ["value1", "value2"]}}]
placementId: '0440440442', /* an ID used to identify the piece of inventory - required - for unruly test use 0440440442. */
customData": [{"settings": {}, "targeting": {"key": "value", "key2": ["value1", "value2"],}}] /* optional array with 'targeting' placeholder for passing publisher specific key-values for targeting. */
ozoneData: {"key1": "value1", "key2": "value2"}, /* optional JSON placeholder for for passing ozone project key-values for targeting. */
customData: [{"settings": {}, "targeting": {"key": "value", "key2": ["value1", "value2"]}}],/* optional array with 'targeting' placeholder for passing publisher specific key-values for targeting. */
lotameData: {"key1": "value1", "key2": "value2"}, /* optional JSON placeholder for passing Lotame DMP data */
video: {
skippable: true, /* optional */
Expand Down
Loading

0 comments on commit f3d0580

Please sign in to comment.