Skip to content

Rubicon Adapter GDPR Update for gdprApplies flag #2456

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 6 commits into from
Apr 27, 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
25 changes: 15 additions & 10 deletions modules/rubiconBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ export const spec = {

page_url = bidRequest.params.secure ? page_url.replace(/^http:/i, 'https:') : page_url;

// GDPR reference, for use by 'banner' and 'video'
const gdprConsent = bidderRequest.gdprConsent;

if (spec.hasVideoMediaType(bidRequest)) {
let params = bidRequest.params;
let size = parseSizes(bidRequest);
Expand Down Expand Up @@ -178,9 +181,12 @@ export const spec = {

data.slots.push(slotData);

if (bidderRequest && bidderRequest.gdprConsent) {
data.gdpr = bidderRequest.gdprConsent.gdprApplies ? 1 : 0;
data.gdpr_consent = bidderRequest.gdprConsent.consentString;
if (gdprConsent) {
// add 'gdpr' only if 'gdprApplies' is defined
if (typeof gdprConsent.gdprApplies === 'boolean') {
data.gdpr = Number(gdprConsent.gdprApplies);
}
data.gdpr_consent = gdprConsent.consentString;
}

return {
Expand Down Expand Up @@ -228,13 +234,12 @@ 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 (gdprConsent) {
// add 'gdpr' only if 'gdprApplies' is defined
if (typeof gdprConsent.gdprApplies === 'boolean') {
data.push('gdpr', Number(gdprConsent.gdprApplies));
}
data.push('gdpr_consent', gdprConsent.consentString);
}

if (visitor !== null && typeof visitor === 'object') {
Expand Down
109 changes: 42 additions & 67 deletions test/spec/modules/rubiconBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,24 @@ describe('the rubicon adapter', () => {
let sandbox,
bidderRequest;

function addConsentManagement() {
bidderRequest.gdprConsent = {
'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==',
'gdprApplies': true
/**
* @param {boolean} [gdprApplies]
*/
function createGdprBidderRequest(gdprApplies) {
if (typeof gdprApplies === 'boolean') {
bidderRequest.gdprConsent = {
'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==',
'gdprApplies': gdprApplies
};
} else {
bidderRequest.gdprConsent = {
'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A=='
};
}
}

function createVideoBidderRequest() {
addConsentManagement();
createGdprBidderRequest(true);

let bid = bidderRequest.bids[0];
bid.mediaTypes = {
Expand All @@ -46,7 +55,7 @@ describe('the rubicon adapter', () => {
}

function createLegacyVideoBidderRequest() {
addConsentManagement();
createGdprBidderRequest(true);

let bid = bidderRequest.bids[0];
// Legacy property (Prebid <1.0)
Expand Down Expand Up @@ -535,77 +544,43 @@ describe('the rubicon adapter', () => {
});
});

it('should send GDPR params when enabled', () => {
addConsentManagement();
describe('GDPR consent config', () => {
it('should send "gdpr" and "gdpr_consent", when gdprConsent defines consentString and gdprApplies', () => {
createGdprBidderRequest(true);
let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
let data = parseQuery(request.data);

sandbox.stub(config, 'getConfig').callsFake((key) => {
var config = {
consentManagement: {
cmp: 'iab',
waitForConsentTimeout: 4000,
lookUpFailureResolution: 'cancel'
}
};
return config[key];
expect(data['gdpr']).to.equal('1');
expect(data['gdpr_consent']).to.equal('BOJ/P2HOJ/P2HABABMAAAAAZ+A==');
});

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 send only "gdpr_consent", when gdprConsent defines only consentString', () => {
createGdprBidderRequest();
let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
let data = parseQuery(request.data);

it('should not send GDPR params if not enabled', () => {
sandbox.stub(config, 'getConfig').callsFake((key) => {
var config = {};
return config[key];
expect(data['gdpr_consent']).to.equal('BOJ/P2HOJ/P2HABABMAAAAAZ+A==');
expect(data['gdpr']).to.equal(undefined);
});

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 defined', () => {
let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
let data = parseQuery(request.data);

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];
expect(data['gdpr']).to.equal(undefined);
expect(data['gdpr_consent']).to.equal(undefined);
});

let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
let data = parseQuery(request.data);
let expectedQuery = {
'gdpr': undefined,
'gdpr_consent': undefined
};
it('should set "gdpr" value as 1 or 0, using "gdprApplies" value of either true/false', () => {
createGdprBidderRequest(true);
let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
let data = parseQuery(request.data);
expect(data['gdpr']).to.equal('1');

// 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);
createGdprBidderRequest(false);
[request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
data = parseQuery(request.data);
expect(data['gdpr']).to.equal('0');
});
});
});
Expand Down