Skip to content

Commit

Permalink
C1X Adapter GDPR Support (#2821)
Browse files Browse the repository at this point in the history
* C1X Adapter GDPR Support

* remove the redundant userSync

* fixed keyword spacing issue
  • Loading branch information
CathyHuangtw authored and mike-chowla committed Jul 24, 2018
1 parent 2fd552a commit 875ffba
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
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

0 comments on commit 875ffba

Please sign in to comment.