Skip to content

Rich Audience Bidder Adapter #3518

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

Merged
merged 5 commits into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
138 changes: 138 additions & 0 deletions modules/richAudienceBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import {registerBidder} from '../src/adapters/bidderFactory';
import {config} from '../src/config';
import {BANNER, VIDEO} from '../src/mediaTypes';
import * as utils from '../src/utils';

const BIDDER_CODE = 'richaudience';

export const spec = {
code: BIDDER_CODE,
aliases: ['ra'],
supportedMediaTypes: [BANNER, VIDEO],

/***
* Determines whether or not the given bid request is valid
*
* @param {bidRequest} bid The bid params to validate.
* @returns {boolean} True if this is a valid bid, and false otherwise
*/
isBidRequestValid: function (bid) {
return !!(bid.params && bid.params.pid && bid.params.supplyType);
},
/***
* Build a server request from the list of valid BidRequests
* @param {validBidRequests} is an array of the valid bids
* @param {bidderRequest} bidder request object
* @returns {ServerRequest} Info describing the request to the server
*/
buildRequests: function (validBidRequests, bidderRequest) {
return validBidRequests.map(bid => {
var payload = {
bidfloor: bid.params.bidfloor,
ifa: bid.params.ifa,
pid: bid.params.pid,
supplyType: bid.params.supplyType,
currencyCode: config.getConfig('currency.adServerCurrency'),
auctionId: bid.auctionId,
bidId: bid.bidId,
BidRequestsCount: bid.bidRequestsCount,
bidder: bid.bidder,
bidderRequestId: bid.bidderRequestId,
tagId: bid.adUnitCode,
sizes: bid.sizes.map(size => ({
w: size[0],
h: size[1],
})),
referer: (typeof bidderRequest.refererInfo.referer != 'undefined' ? encodeURIComponent(bidderRequest.refererInfo.referer) : null),
numIframes: (typeof bidderRequest.refererInfo.numIframes != 'undefined' ? bidderRequest.refererInfo.numIframes : null),
transactionId: bid.transactionId,
timeout: config.getConfig('bidderTimeout'),
};

if (bidderRequest && bidderRequest.gdprConsent) {
payload.gdpr_consent = bidderRequest.gdprConsent.consentString;
payload.gdpr = bidderRequest.gdprConsent.gdprApplies; // we're handling the undefined case server side
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks for mentioning server side handling :)

} else {
payload.gdpr_consent = '';
payload.gdpr = null;
}

var payloadString = JSON.stringify(payload);

var endpoint = 'https://shb.richaudience.com/hb/';

return {
method: 'POST',
url: endpoint,
data: payloadString,
};
});
},
/***
* Read the response from the server and build a list of bids
* @param {serverResponse} Response from the server.
* @param {bidRequest} Bid request object
* @returns {bidResponses} Array of bids which were nested inside the server
*/
interpretResponse: function (serverResponse, bidRequest) {
const bidResponses = [];

var response = serverResponse.body;

try {
if (response) {
var bidResponse = {
requestId: JSON.parse(bidRequest.data).bidId,
cpm: response.cpm,
width: response.width,
height: response.height,
creativeId: response.creative_id,
mediaType: response.media_type,
netRevenue: response.netRevenue,
currency: response.currency,
ttl: response.ttl,
};

if (response.media_type === 'video') {
bidResponse.vastXml = response.vastXML;
} else {
bidResponse.ad = response.adm
}

bidResponses.push(bidResponse);
}
} catch (error) {
utils.logError('Error while parsing smart server response', error);
}
return bidResponses
},
/***
* User Syncs
*
* @param {syncOptions} Publisher prebid configuration
* @param {serverResponses} Response from the server
* @returns {Array}
*/
getUserSyncs: function (syncOptions, serverResponses) {
Copy link
Collaborator

@robertrmartinez robertrmartinez Feb 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can pass in a gdprConsent param which you can use to send consent data if needed.

I see you use the serverResponses object to achieve the same, but in the else case you could utilize this gdprConsent data if wanted.

I am unsure how RichAudience wants to handle this but though I would let you know.

Example of adapter using this: https://github.com/prebid/Prebid.js/blob/master/modules/rubiconBidAdapter.js#L464

const syncs = [];

var rand = Math.floor(Math.random() * 9999999999);
var syncUrl = '';

if (serverResponses.length > 0) {
syncUrl = 'https://sync.richaudience.com/dcf3528a0b8aa83634892d50e91c306e/?ord=' + rand + '&pubconsent=' + serverResponses[0].body.consentString + '&euconsent=' + serverResponses[0].body.consentString;
} else {
syncUrl = 'https://sync.richaudience.com/dcf3528a0b8aa83634892d50e91c306e/?ord=' + rand;
}

if (syncOptions.iframeEnabled) {
syncs.push({
type: 'iframe',
url: syncUrl
});
}
return syncs
},
};

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

```
Module Name: Rich Audience Bidder Adapter
Module Type: Bidder Adapter
Maintainer: [email protected]
```

# Description

Connects to Rich Audience Marketplace for bids. This adapter supports Display and Video.

The Rich Audience adapter requires setup and approval from the Rich Audience team.
Please reach out to your account manager for more information.

# Test Parameters

## Web
```
var adUnits = [
{
code: 'test-div1',
sizes: [[300, 250],[300, 600]]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a comma after sizes declaration!

bids: [{
bidder: 'richaudience',
params: {
"pid":"ADb1f40rmi",
"supplyType":"site",
"bidfloor":0.70,
}
}]
},
{
code: 'test-div2',
sizes: [[728, 90],[970, 250]]
bids: [{
bidder: 'richaudience',
params: {
"pid":"ADb1f40rmo",
"supplyType":"site",
"bidfloor":0.40,
}
}]
}
];
```

## In-app
```
var adUnits = [
{
code: 'test-div1',
sizes: [[300, 250],[300, 600]]
bids: [{
bidder: 'richaudience',
params: {
"pid":"ADb1f40rmi",
"supplyType":"app",
"ifa":"AAAAAAAAA-BBBB-CCCC-1111-222222220000",
"bidfloor":0.70,
}
}]
},
{
code: 'test-div2',
sizes: [[728, 90],[970, 250]]
},
bids: [{
bidder: 'richaudience',
params: {
"pid":"ADb1f40rmo",
"supplyType":"app",
"ifa":"AAAAAAAAA-BBBB-CCCC-1111-222222220000",
"bidfloor":0.40,
}
}]
}
];
```

# Configuration
Add the following code to enable user syncing. By default, Prebid.js version 0.34.0+ turns off user syncing through iframes.
Rich Audience strongly recommends enabling user syncing through iframes. Be sure to call `pbjs.setConfig()` only once.

```javascript
pbjs.setConfig({
userSync: {
iframeEnabled: true
}
});
```
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading