Skip to content

Commit

Permalink
RhythmOne Adapter - Added GDPR Support (prebid#2576)
Browse files Browse the repository at this point in the history
* RhythmOne Adapter - Added GDPR Support

* Updated GDPR unit test case

* Adapter version updated
  • Loading branch information
Rajeshk08 authored and dluxemburg committed Jul 17, 2018
1 parent 322ae1d commit 3e92a87
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
15 changes: 11 additions & 4 deletions modules/rhythmoneBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function RhythmOneBidAdapter() {
return true;
};

this.getUserSyncs = function (syncOptions) {
this.getUserSyncs = function (syncOptions, responses, gdprConsent) {
let slots = [];
let placementIds = [];

Expand Down Expand Up @@ -51,6 +51,10 @@ function RhythmOneBidAdapter() {
data.response_ms = Date.now() - loadStart;
data.placement_codes = slots.join(',');
data.bidder_version = version;
if (gdprConsent) {
data.gdpr_consent = gdprConsent.consentString;
data.gdpr = (typeof gdprConsent.gdprApplies === 'boolean') ? gdprConsent.gdprApplies : true;
}

for (let k in data) {
q.push(encodeURIComponent(k) + '=' + encodeURIComponent((typeof data[k] === 'object' ? JSON.stringify(data[k]) : data[k])));
Expand All @@ -76,10 +80,10 @@ function RhythmOneBidAdapter() {

let slotsToBids = {};
let that = this;
let version = '1.0.0.0';
let version = '1.0.1.0';
let loadStart = Date.now();

this.buildRequests = function (BRs) {
this.buildRequests = function (BRs, bidderRequest) {
let fallbackPlacementId = getFirstParam('placementId', BRs);
if (fallbackPlacementId === undefined || BRs.length < 1) {
return [];
Expand Down Expand Up @@ -198,7 +202,10 @@ function RhythmOneBidAdapter() {
p('h', heights);
p('floor', floors);
p('t', mediaTypes);

if (bidderRequest && bidderRequest.gdprConsent) {
p('gdpr_consent', bidderRequest.gdprConsent.consentString);
p('gdpr', (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') ? bidderRequest.gdprConsent.gdprApplies : true);
}
url += '&' + query.join('&') + '&';

return url;
Expand Down
38 changes: 38 additions & 0 deletions test/spec/modules/rhythmoneBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,30 @@ describe('rhythmone adapter tests', function () {
assert.equal(mangoRequest.length, 1);
});

it('should send GDPR Consent data to RhythmOne tag', () => {
let _consentString = 'testConsentString';
var request = z.buildRequests(
[
{
'bidder': 'rhythmone',
'params': {
'placementId': 'xyz',
'keywords': '',
'categories': [],
'trace': true,
'method': 'get',
'api': 'mango',
'endpoint': 'http://fakedomain.com?'
},
'adUnitCode': 'div-gpt-ad-1438287399331-0',
'sizes': [[300, 250]]
}
], {gdprConsent: {gdprApplies: 1, consentString: _consentString}}
);
assert.equal(getURLParam(request[0].url, 'gdpr'), 'true');
assert.equal(getURLParam(request[0].url, 'gdpr_consent'), 'testConsentString');
});

var bids = z.interpretResponse({
body: [
{
Expand All @@ -77,5 +101,19 @@ describe('rhythmone adapter tests', function () {
it('should register one bid', function() {
assert.equal(bids.length, 1);
});
function getURLParam(url, key) {
let val = '';
if (url.indexOf('?') > -1) {
let qs = url.substr(url.indexOf('?'));
let qsArr = qs.split('&');
for (let i = 0; i < qsArr.length; i++) {
if (qsArr[i].indexOf(key.toLowerCase() + '=') > -1) {
val = qsArr[i].split('=')[1]
break;
}
}
}
return val;
}
});
});

0 comments on commit 3e92a87

Please sign in to comment.