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

Init BeOp prebid Adapter #1

Merged
merged 8 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
144 changes: 144 additions & 0 deletions modules/beopBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import * as utils from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
const BIDDER_CODE = 'beop';
const ENDPOINT_URL = 'https://s.beop.io/bid';
const TCF_VENDOR_ID = 666;

const validIdRegExp = /^[0-9a-fA-F]{24}$/

export const spec = {
code: BIDDER_CODE,
gvlid: TCF_VENDOR_ID,
aliases: ['bp'],
/**
* Test if the bid request is valid.
*
* @param {bid} : The Bid params
* @return boolean true if the bid request is valid (aka contains a valid accountId or networkId and is open for BANNER), false otherwise.
*/
isBidRequestValid: function(bid) {
const id = bid.params.accountId || bid.params.networkId;
if (id == null) {
return false
}
if (!validIdRegExp.test(id)) {
return false
}
return bid.mediaTypes.banner != null;
},
/**
* Create a BeOp server request from a list of BidRequest
*
* @param {validBidRequests[], ...} : The array of validated bidRequests
* @param {... , bidderRequest} : Common params for each bidRequests
* @return ServerRequest Info describing the request to the BeOp's server
*/
buildRequests: function(validBidRequests, bidderRequest) {
const slots = validBidRequests.map(beOpRequestSlotsMaker);
let pageUrl = utils.deepAccess(bidderRequest, 'refererInfo.canonicalUrl') || config.getConfig('pageUrl') || utils.deepAccess(window, 'location.href');
let fpd = config.getLegacyFpd(config.getConfig('ortb2')) || {site: {keywords: []}};
let gdpr = bidderRequest.gdprConsent;
let firstSlot = slots[0];

let payloadObject = {
at: new Date().toString(),
nid: firstSlot.nid,
nptnid: firstSlot.nptnid,
pid: firstSlot.pid,
url: pageUrl,
lang: (window.navigator.language || window.navigator.languages[0]),
kwds: fpd.site.keywords,
dbg: false,
slts: slots,
is_amp: utils.deepAccess(bidderRequest, 'referrerInfo.isAmp'),
tc_string: (gdpr && gdpr.gdprApplies) ? gdpr.consentString : '',
};
const payloadString = JSON.stringify(payloadObject);
return {
method: 'POST',
url: ENDPOINT_URL,
data: payloadString
}
},
interpretResponse: function(serverResponse, request) {
if (serverResponse && serverResponse.body && utils.isArray(serverResponse.body.bids) && serverResponse.body.bids.length > 0) {
return serverResponse.body.bids;
}
return [];
},
onTimeout: function(timeoutData) {
if (timeoutData === null || timeoutData === undefined || Object.keys(timeoutData).length === 0) {
return;
}

let trackingParams = buildTrackingParams(timeoutData, 'timeout', timeoutData.timeout);

utils.logWarn(BIDDER_CODE + ': timed out request');
utils.triggerPixel(utils.buildUrl({
protocol: 'https',
hostname: 't.beop.io',
pathname: '/bid',
search: trackingParams
}));
},
onBidWon: function(bid) {
if (bid === null || bid === undefined || Object.keys(bid).length === 0) {
return;
}
let trackingParams = buildTrackingParams(bid, 'won', bid.cpm);

utils.logInfo(BIDDER_CODE + ': won request');
utils.triggerPixel(utils.buildUrl({
protocol: 'https',
hostname: 't.beop.io',
pathname: '/bid',
search: trackingParams
}));
},
onSetTargeting: function(bid) {}
}

function buildTrackingParams(data, info, value) {
return {
pid: data.params.accountId,
nid: data.params.networkId,
nptnid: data.params.networkPatnerId,
bid: data.bidId,
sl_n: data.adUnitCode,
aid: data.auctionId,
se_ca: 'bid',
se_ac: info,
se_va: value
};
}

function beOpRequestSlotsMaker(bid) {
const bannerReq = utils.deepAccess(bid, 'mediaTypes.banner');
const bannerSizes = bannerReq.sizes;
const publisherCurrency = utils.getValue(bid.params, 'currency') || 'EUR';
let floor;
if (typeof bid.getFloor === 'function') {
const floorInfo = bid.getFloor({currency: publisherCurrency, mediaType: 'banner', size: [1, 1]});
if (typeof floorInfo === 'object' && floorInfo.currency === publisherCurrency && !isNaN(parseFloat(floorInfo.floor))) {
floor = parseFloat(floorInfo.floor);
}
}
return {
sizes: utils.isArray(bannerSizes) ? utils.isArray(bannerSizes) : bid.sizes,
flr: floor,
pid: utils.getValue(bid.params, 'accountId'),
nid: utils.getValue(bid.params, 'networkId'),
nptnid: utils.getValue(bid.params, 'networkPatnerId'),
bid: utils.getBidIdParameter('bidId', bid),
brid: utils.getBidIdParameter('bidderRequestId', bid),
name: utils.getBidIdParameter('adUnitCode', bid),
aid: utils.getBidIdParameter('auctionId', bid),
tid: utils.getBidIdParameter('transactionId', bid),
brc: utils.getBidIdParameter('bidRequestsCount', bid),
bdrc: utils.getBidIdParameter('bidderRequestCount', bid),
bwc: utils.getBidIdParameter('bidderWinsCount', bid),
}
}

registerBidder(spec);
47 changes: 47 additions & 0 deletions modules/beopBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Overview

**Module Name** : BeOp Bidder Adapter
**Module Type** : Bidder Adapter
**Maintainer** : tech@beop.io

# Description

Module that connects to BeOp's demand sources

# Test Parameters
```
var adUnits = [
{
code: 'in-article',
mediaTypes: {
banner: {
sizes: [[300, 250]], // a display size
}
},
bids: [
{
bidder: "example",
params: {
placement: '12345'
}
}
]
},{
code: 'bellow-article',
mediaTypes: {
banner: {
sizes: [[320, 50]], // a mobile size
}
},
bids: [
{
bidder: "example",
params: {
placement: 67890
}
}
]
}
];
```

Loading