Skip to content

Commit c2734a7

Browse files
richaudiencerobertrmartinez
authored andcommitted
Rich Audience Bidder Adapter (#3518)
* Rich Audience Bidder Adapter * Rich Audience Bidder Adapter * Rich Audience Bidder Adapter * Changes in UserSyncs * Changes in package-lock.json
1 parent 069d5f7 commit c2734a7

File tree

3 files changed

+574
-0
lines changed

3 files changed

+574
-0
lines changed

modules/richAudienceBidAdapter.js

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import {registerBidder} from '../src/adapters/bidderFactory';
2+
import {config} from '../src/config';
3+
import {BANNER, VIDEO} from '../src/mediaTypes';
4+
import * as utils from '../src/utils';
5+
6+
const BIDDER_CODE = 'richaudience';
7+
8+
export const spec = {
9+
code: BIDDER_CODE,
10+
aliases: ['ra'],
11+
supportedMediaTypes: [BANNER, VIDEO],
12+
13+
/***
14+
* Determines whether or not the given bid request is valid
15+
*
16+
* @param {bidRequest} bid The bid params to validate.
17+
* @returns {boolean} True if this is a valid bid, and false otherwise
18+
*/
19+
isBidRequestValid: function (bid) {
20+
return !!(bid.params && bid.params.pid && bid.params.supplyType);
21+
},
22+
/***
23+
* Build a server request from the list of valid BidRequests
24+
* @param {validBidRequests} is an array of the valid bids
25+
* @param {bidderRequest} bidder request object
26+
* @returns {ServerRequest} Info describing the request to the server
27+
*/
28+
buildRequests: function (validBidRequests, bidderRequest) {
29+
return validBidRequests.map(bid => {
30+
var payload = {
31+
bidfloor: bid.params.bidfloor,
32+
ifa: bid.params.ifa,
33+
pid: bid.params.pid,
34+
supplyType: bid.params.supplyType,
35+
currencyCode: config.getConfig('currency.adServerCurrency'),
36+
auctionId: bid.auctionId,
37+
bidId: bid.bidId,
38+
BidRequestsCount: bid.bidRequestsCount,
39+
bidder: bid.bidder,
40+
bidderRequestId: bid.bidderRequestId,
41+
tagId: bid.adUnitCode,
42+
sizes: bid.sizes.map(size => ({
43+
w: size[0],
44+
h: size[1],
45+
})),
46+
referer: (typeof bidderRequest.refererInfo.referer != 'undefined' ? encodeURIComponent(bidderRequest.refererInfo.referer) : null),
47+
numIframes: (typeof bidderRequest.refererInfo.numIframes != 'undefined' ? bidderRequest.refererInfo.numIframes : null),
48+
transactionId: bid.transactionId,
49+
timeout: config.getConfig('bidderTimeout'),
50+
};
51+
52+
if (bidderRequest && bidderRequest.gdprConsent) {
53+
payload.gdpr_consent = bidderRequest.gdprConsent.consentString;
54+
payload.gdpr = bidderRequest.gdprConsent.gdprApplies; // we're handling the undefined case server side
55+
} else {
56+
payload.gdpr_consent = '';
57+
payload.gdpr = null;
58+
}
59+
60+
var payloadString = JSON.stringify(payload);
61+
62+
var endpoint = 'https://shb.richaudience.com/hb/';
63+
64+
return {
65+
method: 'POST',
66+
url: endpoint,
67+
data: payloadString,
68+
};
69+
});
70+
},
71+
/***
72+
* Read the response from the server and build a list of bids
73+
* @param {serverResponse} Response from the server.
74+
* @param {bidRequest} Bid request object
75+
* @returns {bidResponses} Array of bids which were nested inside the server
76+
*/
77+
interpretResponse: function (serverResponse, bidRequest) {
78+
const bidResponses = [];
79+
80+
var response = serverResponse.body;
81+
82+
try {
83+
if (response) {
84+
var bidResponse = {
85+
requestId: JSON.parse(bidRequest.data).bidId,
86+
cpm: response.cpm,
87+
width: response.width,
88+
height: response.height,
89+
creativeId: response.creative_id,
90+
mediaType: response.media_type,
91+
netRevenue: response.netRevenue,
92+
currency: response.currency,
93+
ttl: response.ttl,
94+
};
95+
96+
if (response.media_type === 'video') {
97+
bidResponse.vastXml = response.vastXML;
98+
} else {
99+
bidResponse.ad = response.adm
100+
}
101+
102+
bidResponses.push(bidResponse);
103+
}
104+
} catch (error) {
105+
utils.logError('Error while parsing Rich Audience response', error);
106+
}
107+
return bidResponses
108+
},
109+
/***
110+
* User Syncs
111+
*
112+
* @param {syncOptions} Publisher prebid configuration
113+
* @param {serverResponses} Response from the server
114+
* @param {gdprConsent} GPDR consent object
115+
* @returns {Array}
116+
*/
117+
getUserSyncs: function (syncOptions, serverResponses, gdprConsent) {
118+
const syncs = [];
119+
120+
var rand = Math.floor(Math.random() * 9999999999);
121+
var syncUrl = '';
122+
123+
if (gdprConsent && typeof gdprConsent.consentString === 'string') {
124+
syncUrl = 'https://sync.richaudience.com/dcf3528a0b8aa83634892d50e91c306e/?ord=' + rand + '&pubconsent=' + gdprConsent.consentString + '&euconsent=' + gdprConsent.consentString;
125+
} else {
126+
syncUrl = 'https://sync.richaudience.com/dcf3528a0b8aa83634892d50e91c306e/?ord=' + rand;
127+
}
128+
129+
if (syncOptions.iframeEnabled) {
130+
syncs.push({
131+
type: 'iframe',
132+
url: syncUrl
133+
});
134+
}
135+
return syncs
136+
},
137+
};
138+
139+
registerBidder(spec);

modules/richAudienceBidAdapter.md

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Overview
2+
3+
```
4+
Module Name: Rich Audience Bidder Adapter
5+
Module Type: Bidder Adapter
6+
Maintainer: [email protected]
7+
```
8+
9+
# Description
10+
11+
Connects to Rich Audience Marketplace for bids. This adapter supports Display and Video.
12+
13+
The Rich Audience adapter requires setup and approval from the Rich Audience team.
14+
Please reach out to your account manager for more information.
15+
16+
# Test Parameters
17+
18+
## Web
19+
```
20+
var adUnits = [
21+
{
22+
code: 'test-div1',
23+
sizes: [[300, 250],[300, 600]],
24+
bids: [{
25+
bidder: 'richaudience',
26+
params: {
27+
"pid":"ADb1f40rmi",
28+
"supplyType":"site",
29+
"bidfloor":0.70,
30+
}
31+
}]
32+
},
33+
{
34+
code: 'test-div2',
35+
sizes: [[728, 90],[970, 250]],
36+
bids: [{
37+
bidder: 'richaudience',
38+
params: {
39+
"pid":"ADb1f40rmo",
40+
"supplyType":"site",
41+
"bidfloor":0.40,
42+
}
43+
}]
44+
}
45+
];
46+
```
47+
48+
## In-app
49+
```
50+
var adUnits = [
51+
{
52+
code: 'test-div1',
53+
sizes: [[300, 250],[300, 600]],
54+
bids: [{
55+
bidder: 'richaudience',
56+
params: {
57+
"pid":"ADb1f40rmi",
58+
"supplyType":"app",
59+
"ifa":"AAAAAAAAA-BBBB-CCCC-1111-222222220000",
60+
"bidfloor":0.70,
61+
}
62+
}]
63+
},
64+
{
65+
code: 'test-div2',
66+
sizes: [[728, 90],[970, 250]],
67+
},
68+
bids: [{
69+
bidder: 'richaudience',
70+
params: {
71+
"pid":"ADb1f40rmo",
72+
"supplyType":"app",
73+
"ifa":"AAAAAAAAA-BBBB-CCCC-1111-222222220000",
74+
"bidfloor":0.40,
75+
}
76+
}]
77+
}
78+
];
79+
```
80+
81+
# Configuration
82+
Add the following code to enable user syncing. By default, Prebid.js version 0.34.0+ turns off user syncing through iframes.
83+
Rich Audience strongly recommends enabling user syncing through iframes. Be sure to call `pbjs.setConfig()` only once.
84+
85+
```javascript
86+
pbjs.setConfig({
87+
userSync: {
88+
iframeEnabled: true
89+
}
90+
});
91+
```

0 commit comments

Comments
 (0)