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

NextRoll Bidder Adapter #4829

Merged
merged 39 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d21b24c
First implementation of the AdRoll adapter (#1)
juanbono Oct 26, 2019
c180513
Fix request and bid id (#5)
raz-adroll Nov 21, 2019
b1c2753
Send Zone ID (#6)
abijr Nov 25, 2019
afdd359
Add age check before fastbid eval (#7)
abijr Dec 5, 2019
907e21e
Add date check (#8)
abijr Dec 6, 2019
17af86c
Merge remote-tracking branch 'upstream/master'
Dec 10, 2019
a77c8c9
Fix bidRequest validation (#9)
abijr Jan 14, 2020
215b573
Merge branch 'master' of github.com:Prebid/Prebid.js
Jan 14, 2020
e2fb8fd
Fix deprecated function usage (#10)
abijr Jan 16, 2020
5162fb0
[SENG-2757] remove custom function from adapter (#11)
juanbono Jan 22, 2020
e02ec0d
Handle nextroll id (#12)
abijr Jan 22, 2020
761ddcc
Rename adroll -> nextroll (#14)
abijr Jan 24, 2020
1b6bf69
Merge branch 'master' of github.com:Prebid/Prebid.js
Jan 24, 2020
9b1bd91
Rename fastbid -> pubtag functions and variables (#15)
abijr Jan 27, 2020
962664c
Merge branch 'master' of github.com:Prebid/Prebid.js
Jan 31, 2020
2a0a48b
Merge branch 'master' of github.com:Prebid/Prebid.js
Feb 4, 2020
413838f
Improve coverage of tests
Feb 4, 2020
154e8e1
Add docs
Feb 5, 2020
2532b0f
Add docs
Feb 6, 2020
5a4e64f
Merge pull request #1 from AdRoll/old-master
abijr Feb 6, 2020
8b96684
Merge pull request #2 from AdRoll/improve-coverage
abijr Feb 6, 2020
fb38274
Improve sizes and add sellerid
Feb 6, 2020
820aae4
Merge remote-tracking branch 'origin/master' into add-docs
Feb 6, 2020
eda56ba
Merge pull request #3 from AdRoll/add-docs
abijr Feb 6, 2020
a9b93dd
Add maintainer email
Feb 6, 2020
ceb3659
Fix CI problem
Feb 6, 2020
ca6c531
Merge branch 'master' of github.com:Prebid/Prebid.js
Feb 6, 2020
1781951
Fix IE tests
Feb 6, 2020
620e6d0
Replace second instance of find
Feb 6, 2020
dfa8fec
Fix types used in the doc
Feb 7, 2020
c0410ae
Remove unused fields in spec
Feb 10, 2020
0a6f4a3
Merge branch 'master' of github.com:Prebid/Prebid.js
Feb 10, 2020
0019d5c
Add ccpa support
Feb 13, 2020
54f90f4
Merge branch 'master' of github.com:Prebid/Prebid.js
Feb 14, 2020
783001d
Remove external script usage
Feb 17, 2020
fa47c78
Remove IP field
Feb 18, 2020
af2a312
Remove pubtag key
Feb 19, 2020
2422b53
Rename imports; Remove getUserSync function; Remove unused code; Use …
raz-adroll Feb 25, 2020
9fbbbe2
Adress comments
abijr Feb 25, 2020
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
215 changes: 215 additions & 0 deletions modules/nextrollBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
import * as utils from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
import { parse as parseUrl } from '../src/url.js';

import find from 'core-js/library/fn/array/find.js';

const BIDDER_CODE = 'nextroll';
const BIDDER_ENDPOINT = 'https://d.adroll.com/bid/prebid/';
const ADAPTER_VERSION = 4;

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

/**
* Determines whether or not the given bid request is valid.
*
* @param {BidRequest} bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bidRequest) {
return bidRequest !== undefined && !!bidRequest.params && !!bidRequest.bidId;
},

/**
* Make a server request from the list of BidRequests.
*
* @param {validBidRequests[]} - an array of bids
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (validBidRequests, bidderRequest) {
let topLocation = parseUrl(utils.deepAccess(bidderRequest, 'refererInfo.referer'));
let consent = hasCCPAConsent(bidderRequest);
return validBidRequests.map((bidRequest, index) => {
return {
method: 'POST',
options: {
withCredentials: consent,
},
url: BIDDER_ENDPOINT,
data: {
id: bidRequest.bidId,
imp: {
id: bidRequest.bidId,
bidfloor: utils.getBidIdParameter('bidfloor', bidRequest.params),
banner: {
format: _getSizes(bidRequest)
},
ext: {
zone: {
id: utils.getBidIdParameter('zoneId', bidRequest.params)
},
nextroll: {
adapter_version: ADAPTER_VERSION
}
}
},

user: _getUser(validBidRequests),
site: _getSite(bidRequest, topLocation),
seller: _getSeller(bidRequest),
device: _getDevice(bidRequest),
}
}
})
},

/**
* Unpack the response from the server into a list of bids.
*
* @param {ServerResponse} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequest) {
if (!serverResponse.body) {
return [];
} else {
let response = serverResponse.body
let bids = response.seatbid.reduce((acc, seatbid) => acc.concat(seatbid.bid), []);
return bids.map((bid) => _buildResponse(response, bid));
}
}
}

function _getUser(requests) {
let id = utils.deepAccess(requests, '0.userId.nextroll');
if (id === undefined) {
return
}

return {
ext: {
eid: [{
'source': 'nextroll',
id
}]
}
}
}

function _buildResponse(bidResponse, bid) {
const adm = utils.replaceAuctionPrice(bid.adm, bid.price);
return {
requestId: bidResponse.id,
cpm: bid.price,
width: bid.w,
height: bid.h,
creativeId: bid.crid,
dealId: bidResponse.dealId,
currency: 'USD',
netRevenue: true,
ttl: 300,
ad: adm
}
}

function _getSite(bidRequest, topLocation) {
return {
page: topLocation.href,
domain: topLocation.hostname,
publisher: {
id: utils.getBidIdParameter('publisherId', bidRequest.params)
}
}
}

function _getSeller(bidRequest) {
return {
id: utils.getBidIdParameter('sellerId', bidRequest.params)
}
}

function _getSizes(bidRequest) {
return bidRequest.sizes.filter(_isValidSize).map(size => {
return {
w: size[0],
h: size[1]
}
})
}

function _isValidSize(size) {
const isNumber = x => typeof x === 'number';
return (size.length === 2 && isNumber(size[0]) && isNumber(size[1]));
}

function _getDevice(_bidRequest) {
return {
ua: navigator.userAgent,
language: navigator['language'],
os: _getOs(navigator.userAgent.toLowerCase()),
osv: _getOsVersion(navigator.userAgent)
}
}

function _getOs(userAgent) {
const osTable = {
'android': /android/i,
'ios': /iphone|ipad/i,
'mac': /mac/i,
'linux': /linux/i,
'windows': /windows/i
};

return find(Object.keys(osTable), os => {
if (userAgent.match(osTable[os])) {
return os;
}
}) || 'etc';
}

function _getOsVersion(userAgent) {
let clientStrings = [
{ s: 'Android', r: /Android/ },
{ s: 'iOS', r: /(iPhone|iPad|iPod)/ },
{ s: 'Mac OS X', r: /Mac OS X/ },
{ s: 'Mac OS', r: /(MacPPC|MacIntel|Mac_PowerPC|Macintosh)/ },
{ s: 'Linux', r: /(Linux|X11)/ },
{ s: 'Windows 10', r: /(Windows 10.0|Windows NT 10.0)/ },
{ s: 'Windows 8.1', r: /(Windows 8.1|Windows NT 6.3)/ },
{ s: 'Windows 8', r: /(Windows 8|Windows NT 6.2)/ },
{ s: 'Windows 7', r: /(Windows 7|Windows NT 6.1)/ },
{ s: 'Windows Vista', r: /Windows NT 6.0/ },
{ s: 'Windows Server 2003', r: /Windows NT 5.2/ },
{ s: 'Windows XP', r: /(Windows NT 5.1|Windows XP)/ },
{ s: 'UNIX', r: /UNIX/ },
{ s: 'Search Bot', r: /(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/ }
];
let cs = find(clientStrings, cs => cs.r.test(userAgent));
return cs ? cs.s : 'unknown';
}

export function hasCCPAConsent(bidderRequest) {
if (typeof bidderRequest.uspConsent !== 'string') {
return true;
}
const usps = bidderRequest.uspConsent;
const version = usps[0];

// If we don't support the consent string, assume no-consent.
if (version !== '1' || usps.length < 3) {
return false;
}

const notice = usps[1];
const optOut = usps[2];

if (notice === 'N' || optOut === 'Y') {
return false;
}
return true;
}

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

```
Module Name: NextRoll Bid Adapter
Module Type: Bidder Adapter
Maintainer: prebid@nextroll.com
```

# Description

Module that connects to NextRoll's bidders.
The NextRoll bid adapter supports Banner format only.

# Test Parameters
``` javascript
var adUnits = [
{
code: 'div-1',
mediatypes: {
banner: {sizes: [[300, 250], [160, 600]]}
},
bids: [{
bidder: 'nextroll',
params: {
bidfloor: 1,
zoneId: "13144370",
publisherId: "publisherid",
sellerId: "sellerid"
}
}]
},
{
code: 'div-2',
mediatypes: {
banner: {
sizes: [[728, 90], [970, 250]]
}
},
bids: [{
bidder: 'nextroll',
params: {
bidfloor: 2.3,
zoneId: "13144370",
publisherId: "publisherid",
sellerId: "sellerid"
}
}]
}
]
```
Loading