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

RhythmOne Adapter - Added GDPR Support #2576

Merged
merged 3 commits into from
May 22, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
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;
}
});
});