Skip to content

Commit

Permalink
sspBC Bid Adapter: update to v4.8, bugfixes, & support for sending pa…
Browse files Browse the repository at this point in the history
…rams.publisherId (#6575)

* 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

* sspbc adapter: fix creating bid.crid, when not present in server response

* sspbc adapter: add publisher id to payload

* sspbc adapter: fix onecode issues (when bid.params is present, but incomplete)

* sspbc adapter: code cleanup

* sspbc adapter: ver up (4.8)

* sspbc-adapter: update doc

* [sspbc-adapter] update test settings

Co-authored-by: Wojciech Biały <wb@WojciechBialy.local>
  • Loading branch information
2 people authored and idettman committed May 21, 2021
1 parent 05e0031 commit 9b88acb
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 32 deletions.
77 changes: 52 additions & 25 deletions modules/sspBCBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import * as utils from '../src/utils.js';
import { ajax } from '../src/ajax.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
import strIncludes from 'core-js-pure/features/string/includes.js';

const BIDDER_CODE = 'sspBC';
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.7';
const BIDDER_VERSION = '4.8';
const W = window;
const { navigator } = W;
const oneCodeDetection = {};
Expand Down Expand Up @@ -151,11 +150,13 @@ function mapBanner(slot) {
}

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

const bidfloor = (slot.params && slot.params.bidFloor) ? parseFloat(slot.params.bidFloor) : undefined;
Expand Down Expand Up @@ -255,6 +256,7 @@ const spec = {
}

const siteId = setOnAny(validBidRequests, 'params.siteId');
const publisherId = setOnAny(validBidRequests, 'params.publisherId');
const page = setOnAny(validBidRequests, 'params.page') || bidderRequest.refererInfo.referer;
const domain = setOnAny(validBidRequests, 'params.domain') || utils.parseUrl(page).hostname;
const tmax = setOnAny(validBidRequests, 'params.tmax') ? parseInt(setOnAny(validBidRequests, 'params.tmax'), 10) : TMAX;
Expand All @@ -270,7 +272,13 @@ const spec = {

const payload = {
id: bidderRequest.auctionId,
site: { id: siteId, page, domain, ref },
site: {
id: siteId,
publisher: publisherId ? { id: publisherId } : undefined,
page,
domain,
ref
},
imp: validBidRequests.map(slot => mapImpression(slot)),
tmax,
user: {},
Expand All @@ -290,57 +298,76 @@ const spec = {
},

interpretResponse(serverResponse, request) {
const { bidderRequest } = request;
const response = serverResponse.body;
const bids = [];
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) {
/*
Match response to request, by comparing bid id's
'bidid-' prefix indicates oneCode (parameterless) request and response
*/
response.seatbid.forEach(seatbid => {
seat = seatbid.seat;
seatbid.bid.forEach(serverBid => {
const bidRequest = request.bidderRequest.bids.filter(b => {
const bidId = b.params ? b.params.id : 'bidid-' + b.bidId;
return bidId === serverBid.impid;
// get data from bid response
const { adomain, crid, impid, exp, ext, price, w, h } = serverBid;

const bidRequest = bidderRequest.bids.filter(b => {
const { bidId, params } = b;
const { id, siteId } = params || {};
const currentBidId = id && siteId ? id : 'bidid-' + bidId;
return currentBidId === impid;
})[0];
site.slot = bidRequest && bidRequest.params ? bidRequest.params.slotid : undefined;

if (serverBid.ext) {
// get data from linked bidRequest
const { bidId, params } = bidRequest || {};

// get slot id for current bid
site.slot = params && params.id;

if (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;
const { siteid, slotid } = ext;
site.id = siteid || site.id;
site.slot = slotid || site.slot;
}

if (bidRequest && site.id && !strIncludes(site.id, 'bidid')) {
// store site data for future notification
oneCodeDetection[bidRequest.bidId] = [site.id, site.slot];
if (bidRequest && site.id && !site.id.includes('bidid')) {
// found a matching request; add this bid

const bidFloor = (bidRequest.params && bidRequest.params.bidFloor) ? bidRequest.params.bidFloor : 0;
// store site data for future notification
oneCodeDetection[bidId] = [site.id, site.slot];

const bid = {
requestId: bidRequest.bidId,
creativeId: serverBid.crid || 'mcad_' + request.bidderRequest.auctionId + '_' + request.bidderRequest.params.id,
cpm: serverBid.price,
requestId: bidId,
creativeId: crid || 'mcad_' + bidderRequest.auctionId + '_' + site.slot,
cpm: price,
currency: response.cur,
ttl: serverBid.exp || 300,
width: serverBid.w,
height: serverBid.h,
ttl: exp || 300,
width: w,
height: h,
bidderCode: BIDDER_CODE,
mediaType: 'banner',
meta: {
advertiserDomains: serverBid.adomain,
advertiserDomains: adomain,
networkName: seat,
},
netRevenue: true,
ad: renderCreative(site, response.id, serverBid, seat, request.bidderRequest),
ad: renderCreative(site, response.id, serverBid, seat, bidderRequest),
};

if (bid.cpm > 0) {
if (bid.cpm >= bidFloor) {
// check bidFloor (if present in params)
const { bidFloor } = params || {};

if (!bidFloor || bid.cpm >= bidFloor) {
bids.push(bid);
} else {
utils.logWarn('Discarding bid due to bidFloor setting', bid.cpm, bidFloor);
Expand Down
13 changes: 6 additions & 7 deletions modules/sspBCBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ Required parameters:
Optional parameters:
- site id
- adslot id
- publisher id
- domain
- page
- tmax
- bidFloor
- test

# Test Parameters
```
Expand All @@ -29,18 +31,15 @@ var adUnits = [
code: 'banner-div',
mediaTypes: {
banner: {
sizes: [[300, 250], [300,600]]
sizes: [[300, 250]]
}
},
bids: [{
bidder: 'sspBC',
params: {
id: '006', // optional
siteId: '235911', // optional
domain: 'somesite.pl', // optional
page: 'somesite.pl/somepage.html', // optional
tmax: 250, // optional
bidFloor: 0.1 // optional
id: "006",
siteId: "235911",
test: 1
}
}]
}
Expand Down

0 comments on commit 9b88acb

Please sign in to comment.