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

C1X Adapter GDPR Support #2821

Merged
merged 3 commits into from
Jul 24, 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
22 changes: 17 additions & 5 deletions modules/c1xBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const LOG_MSG = {

/**
* Adapter for requesting bids from C1X header tag server.
* v3.0 (c) C1X Inc., 2017
* v3.1 (c) C1X Inc., 2018
*/

export const c1xAdapter = {
Expand All @@ -29,9 +29,10 @@ export const c1xAdapter = {
return !!(bid.adUnitCode && siteId);
},

buildRequests: function(bidRequests) {
buildRequests: function(bidRequests, bidderRequest) {
let payload = {};
let tagObj = {};
let pixelUrl = '';
const adunits = bidRequests.length;
const rnd = new Date().getTime();
const c1xTags = bidRequests.map(bidToTag);
Expand All @@ -48,15 +49,26 @@ export const c1xAdapter = {
response: 'json',
compress: 'gzip'
}
Object.assign(payload, tagObj);

let payloadString = stringifyPayload(payload);
// for GDPR support
if (bidderRequest && bidderRequest.gdprConsent) {
payload['consent_string'] = bidderRequest.gdprConsent.consentString;
payload['consent_required'] = (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') ? bidderRequest.gdprConsent.gdprApplies.toString() : 'true'
;
}

if (pixelId) {
const pixelUrl = (useSSL ? 'https:' : 'http:') + PIXEL_ENDPOINT + pixelId;
pixelUrl = (useSSL ? 'https:' : 'http:') + PIXEL_ENDPOINT + pixelId;
if (payload.consent_required) {
pixelUrl += '&gdpr=' + (bidderRequest.gdprConsent.gdprApplies ? 1 : 0);
pixelUrl += '&consent=' + encodeURIComponent(bidderRequest.gdprConsent.consentString || '');
}
userSync.registerSync('image', BIDDER_CODE, pixelUrl);
}

Object.assign(payload, tagObj);

let payloadString = stringifyPayload(payload);
// ServerRequest object
return {
method: 'GET',
Expand Down
18 changes: 18 additions & 0 deletions test/spec/modules/c1xBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,24 @@ describe('C1XAdapter', () => {
const payloadObj = JSON.parse(originalPayload);
expect(payloadObj.pageurl).to.equal('http://c1exchange.com/');
});

it('should convert GDPR Consent to proper form and attach to request', () => {
let consentString = 'BOP2gFWOQIFovABABAENBGAAAAAAMw';
let bidderRequest = {
'bidderCode': 'c1x',
'gdprConsent': {
'consentString': consentString,
'gdprApplies': true
}
}
bidderRequest.bids = bidRequests;

const request = c1xAdapter.buildRequests(bidRequests, bidderRequest);
const originalPayload = parseRequest(request.data);
const payloadObj = JSON.parse(originalPayload);
expect(payloadObj['consent_string']).to.equal('BOP2gFWOQIFovABABAENBGAAAAAAMw');
expect(payloadObj['consent_required']).to.equal('true');
});
});

describe('interpretResponse', () => {
Expand Down