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

Rubicon adapter GDPR support #2406

Merged
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: 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