Skip to content

Commit

Permalink
Sspbc Bid Adapter: multiple updates (#6118)
Browse files Browse the repository at this point in the history
* add sspbc adapter

* tests for sspbc adapter

* sspBC adapter v4.5: set correct creativeId, add adomain to bid.meta, set test mode in adexchange, read site SN from bid response

* sspBC adapter v4.5: set meta.advertiserDomains, update test to expect bid.meta

* sspBC Adapter: add ajax tests (test ad with & without gdpr)

* sspBC Adapter: remove ajax tests

* Update adapter to v4.6

Update adapter to v4.6
- add notification endpoint
- send bidWon and onTimeout notifications
- send CMP version to user sync endpoint

* Remove console logs for notification events

* Change payload data in onTimeout event

* Update tests for sspBC adapter

Update tests for sspBC adapter: 
- add onBidWon test
- add onTimeout test
- alter getUserSyncs test

* Update sspBC adapter to v4.7; enable oneCodeId mode; change module name to ensure combatibility with prebid.org downloader

* sspBc adapter: Bug fixes in v4.7 - change notification format, fix oneCode detection data, convert slot number to int

Co-authored-by: Wojciech Biały <wb@WojciechBialy.local>
  • Loading branch information
wojciech-bialy-wpm and Wojciech Biały authored Dec 21, 2020
1 parent 2f05506 commit 5d2ccb2
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 77 deletions.
140 changes: 83 additions & 57 deletions modules/sspBCAdapter.js → modules/sspBCBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,58 @@ const BIDDER_URL = 'https://ssp.wp.pl/bidder/';
const SYNC_URL = 'https://ssp.wp.pl/bidder/usersync';
const NOTIFY_URL = 'https://ssp.wp.pl/bidder/notify';
const TMAX = 450;
const BIDDER_VERSION = '4.6';
const BIDDER_VERSION = '4.7';
const W = window;
const { navigator } = W;
const oneCodeDetection = {};
var consentApiVersion;

/**
* Get bid parameters for notification
* @param {*} bidData - bid (bidWon), or array of bids (timeout)
*/
const getNotificationPayload = bidData => {
if (bidData) {
const bids = utils.isArray(bidData) ? bidData : [bidData];
if (bids.length > 0) {
const result = {
requestId: undefined,
siteId: [],
adUnit: [],
slotId: [],
}
bids.forEach(bid => {
let params = utils.isArray(bid.params) ? bid.params[0] : bid.params;
params = params || {};

// check for stored detection
if (oneCodeDetection[bid.requestId]) {
params.siteId = oneCodeDetection[bid.requestId][0];
params.id = oneCodeDetection[bid.requestId][1];
}

if (params.siteId) {
result.siteId.push(params.siteId);
}
if (params.id) {
result.slotId.push(params.id);
}
if (bid.cpm) {
const meta = bid.meta || {};
result.cpm = bid.cpm;
result.creativeId = bid.creativeId;
result.adomain = meta.advertiserDomains && meta.advertiserDomains[0];
result.networkName = meta.networkName;
}
result.adUnit.push(bid.adUnitCode)
result.requestId = bid.auctionId || result.requestId;
result.timeout = bid.timeout || result.timeout;
})
return result;
}
}
}

const cookieSupport = () => {
const isSafari = /^((?!chrome|android|crios|fxios).)*safari/i.test(navigator.userAgent);
const useCookies = navigator.cookieEnabled || !!document.cookie.length;
Expand Down Expand Up @@ -104,13 +151,13 @@ function mapBanner(slot) {

function mapImpression(slot) {
const imp = {
id: slot.params.id,
id: (slot.params && slot.params.id) ? slot.params.id : 'bidid-' + slot.bidId,
banner: mapBanner(slot),
/* native: mapNative(slot), */
tagid: slot.params.id,
tagid: slot.adUnitCode,
};

const bidfloor = parseFloat(slot.params.bidfloor);
const bidfloor = (slot.params && slot.params.bidFloor) ? parseFloat(slot.params.bidFloor) : undefined;

if (bidfloor) {
imp.bidfloor = bidfloor;
Expand Down Expand Up @@ -170,6 +217,7 @@ function renderCreative(site, auctionId, bid, seat, request) {
</style>
<script>
window.rekid = ${site.id};
window.slot = ${parseInt(site.slot, 10)};
window.wp_sn = "${site.sn}";
window.mcad = JSON.parse(decodeURI(atob("${mcbase}")));
window.gdpr = ${JSON.stringify(request.gdprConsent)};
Expand Down Expand Up @@ -197,11 +245,8 @@ const spec = {
aliases: [],
supportedMediaTypes: [BANNER],
isBidRequestValid(bid) {
if (bid.params && bid.params.siteId && bid.params.id) {
return true;
}

return false;
// as per OneCode integration, bids without params are valid
return true;
},
buildRequests(validBidRequests, bidderRequest) {
if ((!validBidRequests) || (validBidRequests.length < 1)) {
Expand Down Expand Up @@ -246,42 +291,39 @@ const spec = {
interpretResponse(serverResponse, request) {
const response = serverResponse.body;
const bids = [];
let site = JSON.parse(request.data).site; // get page and referer data from request
const site = JSON.parse(request.data).site; // get page and referer data from request
site.sn = response.sn || 'mc_adapter'; // WPM site name (wp_sn)
let seat;

if (response.seatbid !== undefined) {
response.seatbid.forEach(seatbid => {
seat = seatbid.seat;
seatbid.bid.forEach(serverBid => {
const bidRequest = request.bidderRequest.bids.filter(b => b.params.id === serverBid.impid)[0];

if (bidRequest) {
const bidFloor = bidRequest.params.bidFloor || 0;
const bidCpm = bidRequest.params.flatCpm;

if (!serverBid.gam && bidRequest.params.gam) {
// build GAM config
serverBid.gam = JSON.stringify({
placement: bidRequest.params.gam,
multiplier: 1,
floor: bidRequest.params.gamFloor,
ceil: 100,
namedSizes: ['fluid'],
div: 'div-gpt-ad-x01',
targeting: {
OAS_retarg: '0',
PREBID_ON: '1',
DFPHASH: '',
emptygaf: '0',
},
});
}
const bidRequest = request.bidderRequest.bids.filter(b => {
const bidId = b.params ? b.params.id : 'bidid-' + b.bidId;
return bidId === serverBid.impid;
})[0];
site.slot = bidRequest && bidRequest.params ? bidRequest.params.slotid : undefined;

if (serverBid.ext) {
/*
bid response might include ext object containing siteId / slotId, as detected by OneCode
update site / slot data in this case
*/
site.id = serverBid.ext.siteid || site.id;
site.slot = serverBid.ext.slotid || site.slot;
}

if (bidRequest && site.id && !site.id.includes('bidid')) {
// store site data for future notification
oneCodeDetection[bidRequest.bidId] = [site.id, site.slot];

const bidFloor = (bidRequest.params && bidRequest.params.bidFloor) ? bidRequest.params.bidFloor : 0;

const bid = {
requestId: bidRequest.bidId,
creativeId: serverBid.crid || 'mcad_' + request.bidderRequest.auctionId + '_' + request.bidderRequest.params.id,
cpm: bidCpm || serverBid.price,
cpm: serverBid.price,
currency: response.cur,
ttl: serverBid.exp || 300,
width: serverBid.w,
Expand All @@ -304,7 +346,7 @@ const spec = {
}
}
} else {
utils.logWarn('Discarding response - no matching request', serverBid.impid);
utils.logWarn('Discarding response - no matching request / site id', serverBid.impid);
}
});
});
Expand All @@ -323,34 +365,18 @@ const spec = {
},

onTimeout(timeoutData) {
var adSlots = [];
const bid = timeoutData && timeoutData[0];
if (bid) {
timeoutData.forEach(bid => { adSlots.push(bid.params[0] && bid.params[0].id) })
const payload = {
event: 'timeout',
requestId: bid.auctionId,
siteId: bid.params ? [bid.params[0].siteId] : [],
slotId: adSlots,
timeout: bid.timeout,
}
const payload = getNotificationPayload(timeoutData);
if (payload) {
payload.event = 'timeout';
sendNotification(payload);
return payload;
}
},

onBidWon(bid) {
if (bid && bid.auctionId) {
const payload = {
event: 'bidWon',
requestId: bid.auctionId,
siteId: bid.params ? [bid.params[0].siteId] : [],
slotId: bid.params ? [bid.params[0].id] : [],
cpm: bid.cpm,
creativeId: bid.creativeId,
adomain: (bid.meta && bid.meta.advertiserDomains) ? bid.meta.advertiserDomains[0] : '',
networkName: (bid.meta && bid.meta.networkName) ? bid.meta.networkName : '',
}
const payload = getNotificationPayload(bid);
if (payload) {
payload.event = 'bidWon';
sendNotification(payload);
return payload;
}
Expand Down
16 changes: 12 additions & 4 deletions modules/sspBCAdapter.md → modules/sspBCBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ Module that connects to Wirtualna Polska Media header bidding endpoint to fetch
Only banner format is supported.
Supported currencies: USD, EUR, PLN


Required parameters:
- none

Optional parameters:
- site id
- adslot id
- domain
- page
- tmax
- bidFloor

# Test Parameters
```
Expand All @@ -28,11 +35,12 @@ var adUnits = [
bids: [{
bidder: 'sspBC',
params: {
id: '006', // required
siteId: '235911', // required
id: '006', // optional
siteId: '235911', // optional
domain: 'somesite.pl', // optional
page: 'somesite.pl/somepage.html', // optional
tmax: 250 // optional
tmax: 250, // optional
bidFloor: 0.1 // optional
}
}]
}
Expand Down
Loading

0 comments on commit 5d2ccb2

Please sign in to comment.