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

Update Dspx adapter #5277

Merged
merged 5 commits into from
Jun 3, 2020
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
86 changes: 69 additions & 17 deletions modules/dspxBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,82 @@
import * as utils from '../src/utils.js';
import {config} from '../src/config.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';

const BIDDER_CODE = 'dspx';
const ENDPOINT_URL = 'https://buyer.dspx.tv/request/';
const ENDPOINT_URL_DEV = 'https://dcbuyer.dspx.tv/request/';
const DEFAULT_VAST_FORMAT = 'vast2';

export const spec = {
code: BIDDER_CODE,
aliases: ['dspx'],
supportedMediaTypes: [BANNER, VIDEO],
isBidRequestValid: function(bid) {
return !!(bid.params.placement);
},
buildRequests: function(validBidRequests, bidderRequest) {
return validBidRequests.map(bidRequest => {
const params = bidRequest.params;

const videoData = utils.deepAccess(bidRequest, 'mediaTypes.video') || {};
const sizes = utils.parseSizesInput(videoData.playerSize || bidRequest.sizes)[0];
const [width, height] = sizes.split('x');

const placementId = params.placement;
const rnd = Math.floor(Math.random() * 99999999999);
const referrer = encodeURIComponent(bidderRequest.refererInfo.referer);
const referrer = bidderRequest.refererInfo.referer;
const bidId = bidRequest.bidId;
const isDev = params.devMode || false;

let bannerSizes = utils.parseSizesInput(utils.deepAccess(bidRequest, 'mediaTypes.banner.sizes') || bidRequest.sizes);
let [width, height] = bannerSizes[0].split('x');

let endpoint = isDev ? ENDPOINT_URL_DEV : ENDPOINT_URL;
let payload = {};

if (isVideoRequest(bidRequest)) {
let vastFormat = params.vastFormat || DEFAULT_VAST_FORMAT;
payload = {
_f: vastFormat,
alternative: 'prebid_js',
inventory_item_id: placementId,
srw: width,
srh: height,
idt: 100,
rnd: rnd,
ref: referrer,
bid_id: bidId,
};
} else {
payload = {
_f: 'html',
alternative: 'prebid_js',
inventory_item_id: placementId,
srw: width,
srh: height,
idt: 100,
rnd: rnd,
ref: referrer,
bid_id: bidId,
};
}

const payload = {
_f: 'html',
alternative: 'prebid_js',
inventory_item_id: placementId,
srw: width,
srh: height,
idt: 100,
rnd: rnd,
ref: referrer,
bid_id: bidId,
};
if (params.pfilter !== undefined) {
payload.pfilter = params.pfilter;
}

if (bidderRequest && bidderRequest.gdprConsent) {
if (payload.pfilter !== undefined) {
if (!payload.pfilter.gdpr_consent) {
payload.pfilter.gdpr_consent = bidderRequest.gdprConsent.consentString;
payload.pfilter.gdpr = bidderRequest.gdprConsent.gdprApplies;
}
} else {
payload.pfilter = {
'gdpr_consent': bidderRequest.gdprConsent.consentString,
'gdpr': bidderRequest.gdprConsent.gdprApplies
};
}
}

if (params.bcat !== undefined) {
payload.bcat = params.bcat;
}
Expand Down Expand Up @@ -75,9 +112,14 @@ export const spec = {
currency: currency,
netRevenue: netRevenue,
type: response.type,
ttl: config.getConfig('_bidderTimeout'),
ad: response.adTag
ttl: config.getConfig('_bidderTimeout')
};
if (response.vastXml) {
bidResponse.vastXml = response.vastXml;
bidResponse.mediaType = 'video';
} else {
bidResponse.ad = response.adTag;
}
bidResponses.push(bidResponse);
}
return bidResponses;
Expand All @@ -99,4 +141,14 @@ function objectToQueryString(obj, prefix) {
return str.join('&');
}

/**
* Check if it's a video bid request
*
* @param {BidRequest} bid - Bid request generated from ad slots
* @returns {boolean} True if it's a video bid
*/
function isVideoRequest(bid) {
return bid.mediaType === 'video' || !!utils.deepAccess(bid, 'mediaTypes.video');
}

registerBidder(spec);
65 changes: 28 additions & 37 deletions modules/dspxBidAdapter.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Overview

```
Module Name: Dspx Bidder Adapter
Module Name: DSPx Bidder Adapter
Module Type: Bidder Adapter
Maintainer: prebid@dspx.tv
```

# Description

Dspx adapter for Prebid.js 3.0
DSPx adapter for Prebid.

# Test Parameters
```
Expand All @@ -20,55 +20,46 @@ Dspx adapter for Prebid.js 3.0
sizes: [
[300, 250],
[300, 600],
], // a display size
]
}
},
bids: [
{
bidder: "dspx",
params: {
placement: '101',
devMode: true, // if true: library uses dev server for tests
pfilter: {
floorprice: 1000000, // EUR * 1,000,000
private_auction: 1, // Is private auction? 0 - no, 1 - yes
deals: [
"666-9315-d58a7f9a-bdb9-4450-a3a2-046ba8ab2489;3;25000000;dspx-tv",// DEAL_ID;at;bidfloor;wseat1,wseat2;wadomain1,wadomain2"
"666-9315-d58a7f9a-bdb9-4450-a6a2-046ba8ab2489;3;25000000;dspx-tv",// DEAL_ID;at;bidfloor;wseat1,wseat2;wadomain1,wadomain2"
],
geo: { // set client geo info manually (empty for auto detect)
lat: 52.52437, // Latitude from -90.0 to +90.0, where negative is south.
lon: 13.41053, // Longitude from -180.0 to +180.0, where negative is west
type: 1, // Source of location data: 1 - GPS/Location Services, 2 - IP Address, 3 - User provided (e.g. registration form)
country: 'DE', // Region of a country using FIPS 10-4 notation
region: 'DE-BE', // Region code using ISO-3166-2; 2-letter state code if USA.
regionfips104: 'GM', // Region of a country using FIPS 10-4 notation
city: 'BER', // City using United Nations Code for Trade and Transport Locations
zip: '10115' // Zip or postal code.
}
placement: '101', // [required] info available from your contact with DSPx team
/*
bcat: "IAB2,IAB4", // [optional] list of blocked advertiser categories (IAB), comma separated
*/
/*
pfilter: { // [optional]
// [optional] only required if a deal is negotiated
deals: [ // [optional]
"123-4567-d58a7f9a-..."// DEAL_ID from DSPx contact
],
private_auction: 1 // [optional] 0 - no, 1 - yes
// usually managed on DSPx side
floorprice: 1000000 // input min_cpm_micros, CPM in EUR * 1000000
},
bcat: "IAB2,IAB4", // List of Blocked Categories (IAB) - comma separated
dvt: "desktop|smartphone|tv|tablet" // DeVice Type (autodetect if not exists)
*/
}
}
]
},{
code: 'test-div',
},
{
code: 'video1',
mediaTypes: {
banner: {
sizes: [[320, 50]], // a mobile size
video: {
playerSize: [640, 480],
context: 'instream'
}
},
bids: [
{
bidder: "dspx",
params: {
placement: 101
}
bids: [{
bidder: 'dspx',
params: {
placement: '106'
}
]
}]
}
];
```

Required param field is only `placement`.
Loading