Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CleanMediaNet: Update adaptor code to meet Prebid.js v3.0 constraints #4602

Merged
merged 41 commits into from
Dec 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f32f6b4
Update adaptor code to meet Prebid.js v3.0 constraints
Dec 15, 2019
25878b9
Refactor and remove unused properties from bid response.
Dec 18, 2019
a580afa
Remove curly brackets from string to fix test
Dec 18, 2019
96e5612
Criteo decrease bid adapter size (#4518)
leonardlabat Dec 16, 2019
39937ef
Support for CCPA consent in Criteo adapter (#4604)
afewcc Dec 16, 2019
fa8ea86
Feat/rtbsolutions (#4556)
rtbsolutions Dec 16, 2019
0513a58
update several tests to let them work in ie11 (#4594)
jsnellbaker Dec 16, 2019
bf31f4f
some minor test fixes (#4611)
jsnellbaker Dec 16, 2019
e835b8f
Medianet: CCPA support added (#4573)
vedantseta Dec 16, 2019
da2e09d
Yieldmo prebid3.0 compliance, gdpr upadtes. remove openxoutstream bid…
HolzAndrew Dec 17, 2019
4f0cee2
Add CCPA support to Undertone adapter (#4576)
omerko Dec 17, 2019
3e9daae
small edits to fix undertone tests (#4616)
jsnellbaker Dec 17, 2019
3c961f2
PubMatic: sending transactionId in source.tid (#4588)
pm-harshad-mane Dec 17, 2019
6ed279c
Introduce Dailyhunt Bid Adapter (#4517)
montu1996 Dec 17, 2019
2098bb6
AstraOne: Fixed example in the documentation (#4590)
astraone-ssp Dec 17, 2019
591c79d
added CCPA support to sonobi bidder adapter (#4617)
JonGoSonobi Dec 17, 2019
8220419
Fixes for Prebid 3.0 (#4587)
bjorn-lw Dec 18, 2019
5ef87a3
Re-Add Readpeak adapter (#4593)
kurrestahlberg Dec 18, 2019
f0c5709
Trion bid adapter re-submit to comply with v3 (#4609)
grohm33 Dec 18, 2019
68adc2e
Sovrn ccpa support (#4592)
aprakash-sovrn Dec 18, 2019
c44cd40
fix a bug when the iframe locator is not present on page (#4621)
mkendall07 Dec 18, 2019
998e7e8
Added US Privacy support for TheMediaGrid Bid Adapter (#4606)
TheMediaGrid Dec 18, 2019
4bfa8dd
Districtm DMX adapter support for CCPA (#4560)
stevealliance Dec 18, 2019
59ef480
TripleLift: CCPA support (#4628)
davidwoodsandersen Dec 18, 2019
6f4e205
Consumable Bid Adapter: Add CCPA support (#4618)
jgrimes Dec 18, 2019
491be0e
Rubicon Analytics Adapter: convert to 3.0 (#4625)
msm0504 Dec 18, 2019
7f055a9
sovrn analytics adapter with 3.0 updates (#4620)
aprakash-sovrn Dec 18, 2019
acfec39
Gamoshi: Fix adaptor code to comply for Prebid.js v3.0 (#4601)
Dec 18, 2019
d2a25fc
Fidelity Media Bid Adapter. Prebid.js v3 support, CCPA support. (#4630)
onaydenov Dec 18, 2019
4265f18
re-submit bid adapter for AdUp Technology (#4603)
SteffenAnders Dec 18, 2019
b0d211e
EMX Digital 3.0 Compliance (#4624)
EMXDigital Dec 18, 2019
c48f586
remove unneeded console.log statement (#4639)
jsnellbaker Dec 18, 2019
85fe4a7
pbsBidAdapter: register response currency (#4638)
bretg Dec 18, 2019
9796064
OpenX adpater: adding CCPA support (#4584)
jimee02 Dec 18, 2019
a81cb71
Update Sharethrough bid adapter endpoint (#4578)
madma Dec 18, 2019
79291f7
Prebid 3 adbutler (#4612)
dharton Dec 18, 2019
90e188a
Prebid 3.1.0 Release
jsnellbaker Dec 18, 2019
8977735
increment pre version
jsnellbaker Dec 18, 2019
12a9b2c
Merge branch 'master' into cleanmedianet_prebid_v3
Dec 19, 2019
9aad057
Fix tests issue
Dec 19, 2019
76ae596
Merge remote-tracking branch 'origin/cleanmedianet_prebid_v3' into cl…
Dec 19, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
315 changes: 315 additions & 0 deletions modules/cleanmedianetBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,315 @@
import * as utils from '../src/utils';
import {registerBidder} from '../src/adapters/bidderFactory';
import {config} from '../src/config';
import {Renderer} from '../src/Renderer';
import {BANNER, VIDEO} from '../src/mediaTypes';

export const helper = {
getTopWindowDomain: function (url) {
const domainStart = url.indexOf('://') + '://'.length;
return url.substring(domainStart, url.indexOf('/', domainStart) < 0 ? url.length : url.indexOf('/', domainStart));
},
startsWith: function (str, search) {
return str.substr(0, search.length) === search;
},
getMediaType: function (bid) {
if (bid.ext) {
if (bid.ext.media_type) {
return bid.ext.media_type.toLowerCase();
} else if (bid.ext.vast_url) {
return VIDEO;
} else {
return BANNER;
}
}
return BANNER;
}
};

export const spec = {
code: 'cleanmedianet',
aliases: [],
supportedMediaTypes: [BANNER, VIDEO],

isBidRequestValid: function (bid) {
return (
!!bid.params.supplyPartnerId &&
typeof bid.params.supplyPartnerId === 'string' &&
(typeof bid.params.bidfloor === 'undefined' ||
typeof bid.params.bidfloor === 'number') &&
(typeof bid.params['adpos'] === 'undefined' ||
typeof bid.params['adpos'] === 'number') &&
(typeof bid.params['protocols'] === 'undefined' ||
Array.isArray(bid.params['protocols'])) &&
(typeof bid.params.instl === 'undefined' ||
bid.params.instl === 0 ||
bid.params.instl === 1)
);
},

buildRequests: function (validBidRequests, bidderRequest) {
return validBidRequests.map(bidRequest => {
const {
adUnitCode,
auctionId,
mediaTypes,
params,
sizes,
transactionId
} = bidRequest;
const baseEndpoint = 'https://bidder.cleanmediaads.com';
const rtbEndpoint =
`${baseEndpoint}/r/${
params.supplyPartnerId
}/bidr?rformat=open_rtb&reqformat=rtb_json&bidder=prebid` +
(params.query ? '&' + params.query : '');
let url =
config.getConfig('pageUrl') || bidderRequest.refererInfo.referer;

const rtbBidRequest = {
id: auctionId,
site: {
domain: helper.getTopWindowDomain(url),
page: url,
ref: bidderRequest.refererInfo.referer
},
device: {
ua: navigator.userAgent,
dnt: utils.getDNT() ? 1 : 0,
h: screen.height,
w: screen.width,
language: navigator.language
},
imp: [],
ext: {},
user: {
ext: {}
}
};

if (
bidderRequest.gdprConsent &&
bidderRequest.gdprConsent.consentString &&
bidderRequest.gdprConsent.gdprApplies
) {
rtbBidRequest.ext.gdpr_consent = {
consent_string: bidderRequest.gdprConsent.consentString,
consent_required: bidderRequest.gdprConsent.gdprApplies
};
rtbBidRequest.regs = {
ext: {
gdpr: bidderRequest.gdprConsent.gdprApplies === true ? 1 : 0
}
};
rtbBidRequest.user = {
ext: {
consent: bidderRequest.gdprConsent.consentString
}
}
}

const imp = {
id: transactionId,
instl: params.instl === 1 ? 1 : 0,
tagid: adUnitCode,
bidfloor: params.bidfloor || 0,
bidfloorcur: 'USD',
secure: 1
sa1omon marked this conversation as resolved.
Show resolved Hide resolved
};

const hasFavoredMediaType =
params.favoredMediaType &&
this.supportedMediaTypes.includes(params.favoredMediaType);

if (!mediaTypes || mediaTypes.banner) {
if (!hasFavoredMediaType || params.favoredMediaType === BANNER) {
const bannerImp = Object.assign({}, imp, {
banner: {
w: sizes.length ? sizes[0][0] : 300,
h: sizes.length ? sizes[0][1] : 250,
pos: params.pos || 0,
topframe: utils.inIframe() ? 0 : 1
}
});
rtbBidRequest.imp.push(bannerImp);
}
}

if (mediaTypes && mediaTypes.video) {
if (!hasFavoredMediaType || params.favoredMediaType === VIDEO) {
let videoImp = {
video: {
protocols: params.protocols || [1, 2, 3, 4, 5, 6],
pos: params.pos || 0,
ext: {context: mediaTypes.video.context}
}
};

let playerSize = mediaTypes.video.playerSize || sizes;
if (utils.isArray(playerSize[0])) {
videoImp.video.w = playerSize[0][0];
videoImp.video.h = playerSize[0][1];
} else if (utils.isNumber(playerSize[0])) {
videoImp.video.w = playerSize[0];
videoImp.video.h = playerSize[1];
} else {
videoImp.video.w = 300;
videoImp.video.h = 250;
}

videoImp = Object.assign({}, imp, videoImp);
rtbBidRequest.imp.push(videoImp);
}
}

if (rtbBidRequest.imp.length === 0) {
return;
}

return {
method: 'POST',
url: rtbEndpoint,
data: rtbBidRequest,
bidRequest
};
});
},

interpretResponse: function (serverResponse, bidRequest) {
const response = serverResponse && serverResponse.body;
if (!response) {
utils.logError('empty response');
return [];
}

const bids = response.seatbid.reduce(
(acc, seatBid) => acc.concat(seatBid.bid),
[]
);
let outBids = [];

bids.forEach(bid => {
const outBid = {
requestId: bidRequest.bidRequest.bidId,
cpm: bid.price,
width: bid.w,
height: bid.h,
ttl: 360,
creativeId: bid.crid || bid.adid,
netRevenue: true,
currency: bid.cur || response.cur,
mediaType: helper.getMediaType(bid)
};

if (
utils.deepAccess(
bidRequest.bidRequest,
'mediaTypes.' + outBid.mediaType
)
) {
if (outBid.mediaType === BANNER) {
outBids.push(Object.assign({}, outBid, {ad: bid.adm}));
} else if (outBid.mediaType === VIDEO) {
const context = utils.deepAccess(
bidRequest.bidRequest,
'mediaTypes.video.context'
);
outBids.push(
Object.assign({}, outBid, {
vastUrl: bid.ext.vast_url,
vastXml: bid.adm,
renderer:
context === 'outstream'
? newRenderer(bidRequest.bidRequest, bid)
: undefined
})
);
}
}
});
return outBids;
},

getUserSyncs: function (syncOptions, serverResponses, gdprConsent) {
const syncs = [];
const gdprApplies =
gdprConsent && typeof gdprConsent.gdprApplies === 'boolean'
? gdprConsent.gdprApplies
: false;
const suffix = gdprApplies
? 'gc=' + encodeURIComponent(gdprConsent.consentString)
: 'gc=missing';
serverResponses.forEach(resp => {
if (resp.body) {
const bidResponse = resp.body;
if (bidResponse.ext && Array.isArray(bidResponse.ext['utrk'])) {
bidResponse.ext['utrk'].forEach(pixel => {
const url =
pixel.url +
(pixel.url.indexOf('?') > 0 ? '&' + suffix : '?' + suffix);
return syncs.push({type: pixel.type, url});
});
}
if (Array.isArray(bidResponse.seatbid)) {
bidResponse.seatbid.forEach(seatBid => {
if (Array.isArray(seatBid.bid)) {
seatBid.bid.forEach(bid => {
if (bid.ext && Array.isArray(bid.ext['utrk'])) {
bid.ext['utrk'].forEach(pixel => {
const url =
pixel.url +
(pixel.url.indexOf('?') > 0
? '&' + suffix
: '?' + suffix);
return syncs.push({type: pixel.type, url});
});
}
});
}
});
}
}
});
return syncs;
}
};

function newRenderer(bidRequest, bid, rendererOptions = {}) {
const renderer = Renderer.install({
url:
(bidRequest.params && bidRequest.params.rendererUrl) ||
(bid.ext && bid.ext.renderer_url) ||
'https://s.wlplayer.com/video/latest/renderer.js',
config: rendererOptions,
loaded: false
});
try {
renderer.setRender(renderOutstream);
} catch (err) {
utils.logWarn('Prebid Error calling setRender on renderer', err);
}
return renderer;
}

function renderOutstream(bid) {
bid.renderer.push(() => {
const unitId = bid.adUnitCode + '/' + bid.adId;
window['GamoshiPlayer'].renderAd({
id: unitId,
debug: window.location.href.indexOf('pbjsDebug') >= 0,
placement: document.getElementById(bid.adUnitCode),
width: bid.width,
height: bid.height,
events: {
ALL_ADS_COMPLETED: () =>
window.setTimeout(() => {
window['GamoshiPlayer'].removeAd(unitId);
}, 300)
},
vastUrl: bid.vastUrl,
vastXml: bid.vastXml
});
});
}

registerBidder(spec);
Loading