Skip to content

Commit

Permalink
Rubicon adapter GDPR support (#2406)
Browse files Browse the repository at this point in the history
* Merged gdpr tests for banner bid requests

* Renamed the gdprConsent.consentRequired to gdprConsent.gdprApplies. Changed containing object used to access gdprConsent values (bidRequest -> bidderRequest)
  • Loading branch information
idettman authored and jsnellbaker committed Apr 24, 2018
1 parent d94404c commit 34f34d8
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 15 deletions.
15 changes: 12 additions & 3 deletions modules/rubiconBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ export const spec = {

data.slots.push(slotData);

if (bidderRequest && bidRequest.gdprConsent) {
data.gdpr = bidRequest.gdprConsent.consentRequired ? 1 : 0;
data.gdpr_consent = bidRequest.gdprConsent.consentString;
if (bidderRequest && bidderRequest.gdprConsent) {
data.gdpr = bidderRequest.gdprConsent.gdprApplies ? 1 : 0;
data.gdpr_consent = bidderRequest.gdprConsent.consentString;
}

return {
Expand Down Expand Up @@ -228,6 +228,15 @@ export const spec = {
'tk_user_key', userId
];

// add GDPR properties if enabled
if (config.getConfig('consentManagement') &&
bidderRequest && bidderRequest.gdprConsent && typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') {
data.push(
'gdpr', bidderRequest.gdprConsent.gdprApplies ? 1 : 0,
'gdpr_consent', bidderRequest.gdprConsent.consentString
);
}

if (visitor !== null && typeof visitor === 'object') {
utils._each(visitor, (item, key) => data.push(`tg_v.${key}`, item));
}
Expand Down
97 changes: 85 additions & 12 deletions test/spec/modules/rubiconBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@ describe('the rubicon adapter', () => {
let sandbox,
bidderRequest;

function addConsentManagement() {
bidderRequest.gdprConsent = {
'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==',
'gdprApplies': true
}
}

function createVideoBidderRequest() {
let bid = bidderRequest.bids[0];
addConsentManagement();

let bid = bidderRequest.bids[0];
bid.mediaTypes = {
video: {
context: 'instream'
}
};

bid.gdprConsent = {
'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==',
'consentRequired': true
};

bid.params.video = {
'language': 'en',
'p_aso.video.ext.skip': true,
Expand All @@ -44,14 +46,11 @@ describe('the rubicon adapter', () => {
}

function createLegacyVideoBidderRequest() {
let bid = bidderRequest.bids[0];
addConsentManagement();

let bid = bidderRequest.bids[0];
// Legacy property (Prebid <1.0)
bid.mediaType = 'video';
bid.gdprConsent = {
'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==',
'consentRequired': true
};
bid.params.video = {
'language': 'en',
'p_aso.video.ext.skip': true,
Expand Down Expand Up @@ -535,6 +534,80 @@ describe('the rubicon adapter', () => {
expect(window.DigiTrust.getUser.calledOnce).to.equal(true);
});
});

it('should send GDPR params when enabled', () => {
addConsentManagement();

sandbox.stub(config, 'getConfig').callsFake((key) => {
var config = {
consentManagement: {
cmp: 'iab',
waitForConsentTimeout: 4000,
lookUpFailureResolution: 'cancel'
}
};
return config[key];
});

let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
let data = parseQuery(request.data);
let expectedQuery = {
'gdpr': '1',
'gdpr_consent': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A=='
};

// test that all values above are both present and correct
Object.keys(expectedQuery).forEach(key => {
let value = expectedQuery[key];
expect(data[key]).to.equal(value);
});
});

it('should not send GDPR params if not enabled', () => {
sandbox.stub(config, 'getConfig').callsFake((key) => {
var config = {};
return config[key];
});

let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
let data = parseQuery(request.data);
let expectedQuery = {
'gdpr': undefined,
'gdpr_consent': undefined
};

// test that all values above are both present and correct
Object.keys(expectedQuery).forEach(key => {
let value = expectedQuery[key];
expect(data[key]).to.equal(value);
});
});

it('should not send GDPR params if gdprConsent is not set in config', () => {
sandbox.stub(config, 'getConfig').callsFake((key) => {
var config = {
consentManagement: {
cmp: 'iab',
waitForConsentTimeout: 4000,
lookUpFailureResolution: 'cancel'
}
};
return config[key];
});

let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
let data = parseQuery(request.data);
let expectedQuery = {
'gdpr': undefined,
'gdpr_consent': undefined
};

// test that all values above are both present and correct
Object.keys(expectedQuery).forEach(key => {
let value = expectedQuery[key];
expect(data[key]).to.equal(value);
});
});
});

describe('for video requests', () => {
Expand Down

0 comments on commit 34f34d8

Please sign in to comment.