Skip to content

Commit

Permalink
re-submit bid adapter for AdUp Technology (#4603)
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenAnders authored and msm0504 committed Dec 18, 2019
1 parent ad6719a commit 0d621e9
Show file tree
Hide file tree
Showing 3 changed files with 706 additions and 10 deletions.
189 changes: 189 additions & 0 deletions modules/aduptechBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
import { registerBidder } from '../src/adapters/bidderFactory';
import { BANNER } from '../src/mediaTypes'
import * as utils from '../src/utils';

export const BIDDER_CODE = 'aduptech';
export const PUBLISHER_PLACEHOLDER = '{PUBLISHER}';
export const ENDPOINT_URL = 'https://rtb.d.adup-tech.com/prebid/' + PUBLISHER_PLACEHOLDER + '_bid';
export const ENDPOINT_METHOD = 'POST';

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER],

/**
* Validate given bid request
*
* @param {*} bidRequest
* @returns {boolean}
*/
isBidRequestValid: (bidRequest) => {
if (!bidRequest) {
return false;
}

const sizes = extractSizesFromBidRequest(bidRequest);
if (!sizes || sizes.length === 0) {
return false;
}

const params = extractParamsFromBidRequest(bidRequest);
if (!params || !params.publisher || !params.placement) {
return false;
}

return true;
},

/**
* Build real bid requests
*
* @param {*} validBidRequests
* @param {*} bidderRequest
* @returns {*[]}
*/
buildRequests: (validBidRequests, bidderRequest) => {
const bidRequests = [];
const gdpr = extractGdprFromBidderRequest(bidderRequest);

validBidRequests.forEach((bidRequest) => {
bidRequests.push({
url: ENDPOINT_URL.replace(PUBLISHER_PLACEHOLDER, encodeURIComponent(bidRequest.params.publisher)),
method: ENDPOINT_METHOD,
data: {
bidId: bidRequest.bidId,
auctionId: bidRequest.auctionId,
transactionId: bidRequest.transactionId,
adUnitCode: bidRequest.adUnitCode,
pageUrl: extractTopWindowUrlFromBidRequest(bidRequest),
referrer: extractTopWindowReferrerFromBidRequest(bidRequest),
sizes: extractSizesFromBidRequest(bidRequest),
params: extractParamsFromBidRequest(bidRequest),
gdpr: gdpr
}
});
});

return bidRequests;
},

/**
* Handle bid response
*
* @param {*} response
* @returns {*[]}
*/
interpretResponse: (response) => {
const bidResponses = [];

if (!response.body || !response.body.bid || !response.body.creative) {
return bidResponses;
}

bidResponses.push({
requestId: response.body.bid.bidId,
cpm: response.body.bid.price,
netRevenue: response.body.bid.net,
currency: response.body.bid.currency,
ttl: response.body.bid.ttl,
creativeId: response.body.creative.id,
width: response.body.creative.width,
height: response.body.creative.height,
ad: response.body.creative.html
});

return bidResponses;
}
};

/**
* Extracts the possible ad unit sizes from given bid request
*
* @param {*} bidRequest
* @returns {number[]}
*/
export function extractSizesFromBidRequest(bidRequest) {
// since pbjs 3.0
if (bidRequest && utils.deepAccess(bidRequest, 'mediaTypes.banner.sizes')) {
return bidRequest.mediaTypes.banner.sizes;

// for backward compatibility
} else if (bidRequest && bidRequest.sizes) {
return bidRequest.sizes;

// fallback
} else {
return [];
}
}

/**
* Extracts the custom params from given bid request
*
* @param {*} bidRequest
* @returns {*}
*/
export function extractParamsFromBidRequest(bidRequest) {
if (bidRequest && bidRequest.params) {
return bidRequest.params
} else {
return null;
}
}

/**
* Extracts the GDPR information from given bidder request
*
* @param {*} bidderRequest
* @returns {*}
*/
export function extractGdprFromBidderRequest(bidderRequest) {
let gdpr = null;

if (bidderRequest && bidderRequest.gdprConsent) {
gdpr = {
consentString: bidderRequest.gdprConsent.consentString,
consentRequired: (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') ? bidderRequest.gdprConsent.gdprApplies : true
};
}

return gdpr;
}

/**
* Extracts the page url from given bid request or use the (top) window location as fallback
*
* @param {*} bidRequest
* @returns {string}
*/
export function extractTopWindowUrlFromBidRequest(bidRequest) {
if (bidRequest && utils.deepAccess(bidRequest, 'refererInfo.canonicalUrl')) {
return bidRequest.refererInfo.canonicalUrl;
}

try {
return window.top.location.href;
} catch (e) {
return window.location.href;
}
}

/**
* Extracts the referrer from given bid request or use the (top) document referrer as fallback
*
* @param {*} bidRequest
* @returns {string}
*/
export function extractTopWindowReferrerFromBidRequest(bidRequest) {
if (bidRequest && utils.deepAccess(bidRequest, 'refererInfo.referer')) {
return bidRequest.refererInfo.referer;
}

try {
return window.top.document.referrer;
} catch (e) {
return window.document.referrer;
}
}

registerBidder(spec);
25 changes: 15 additions & 10 deletions modules/aduptechBidAdapter.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
# Overview

```
Module Name: Ad Up Technology Bid Adapter
Module Name: AdUp Technology Bid Adapter
Module Type: Bidder Adapter
Maintainer: [email protected], [email protected]
Maintainers:
- [email protected]
- [email protected]
- [email protected]
```

# Description
Connects to AdUp Technology demand sources to fetch bids.
Please use ```aduptech``` as bidder code. Only banner formats are supported.

Connects to Ad Up Technology demand sources to fetch bids.
Please use ```aduptech``` as bidder code. Only banner formats are supported.

The Ad Up Technology Bidding adapter requires setup and approval before beginning.
For more information visit [www.adup-tech.com](http://www.adup-tech.com/en).
The AdUp Technology bidding adapter requires setup and approval before beginning.
For more information visit [www.adup-tech.com](https://www.adup-tech.com/en) or contact [[email protected]](mailto:[email protected]).

# Test Parameters
```
```js
var adUnits = [
{
code: 'banner',
sizes: [[300, 250], [300, 600]],
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600]],
}
},
bids: [{
bidder: 'aduptech',
params: {
Expand Down
Loading

0 comments on commit 0d621e9

Please sign in to comment.