Skip to content

Commit

Permalink
aardvark - ccpa support (#4775)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksatr authored and harpere committed Jan 26, 2020
1 parent 5e0b32d commit 516208c
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 17 deletions.
52 changes: 35 additions & 17 deletions modules/aardvarkBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const spec = {

isBidRequestValid: function(bid) {
return ((typeof bid.params.ai === 'string') && !!bid.params.ai.length &&
(typeof bid.params.sc === 'string') && !!bid.params.sc.length);
(typeof bid.params.sc === 'string') && !!bid.params.sc.length);
},

buildRequests: function(validBidRequests, bidderRequest) {
Expand Down Expand Up @@ -82,7 +82,7 @@ export const spec = {
});
}

if (bidderRequest && bidderRequest.gdprConsent) {
if (bidderRequest.gdprConsent) {
rMap.payload.gdpr = false;
if (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') {
rMap.payload.gdpr = bidderRequest.gdprConsent.gdprApplies;
Expand All @@ -96,11 +96,15 @@ export const spec = {
auctionCodes.push(b.params.ai);
}

if (bidderRequest.uspConsent) {
rMap.payload.us_privacy = bidderRequest.uspConsent
}

rMap.shortCodes.push(b.params.sc);
rMap.payload[b.params.sc] = b.bidId;

if ((typeof b.params.host === 'string') && b.params.host.length &&
(b.params.host !== rMap.endpoint)) {
(b.params.host !== rMap.endpoint)) {
rMap.endpoint = b.params.host;
}
});
Expand Down Expand Up @@ -166,28 +170,42 @@ export const spec = {
return bidResponses;
},

getUserSyncs: function(syncOptions, serverResponses, gdprConsent) {
getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent) {
const syncs = [];
var url = 'https://' + SYNC_ENDPOINT + '/cs';
const params = [];
var gdprApplies = false;
if (gdprConsent && (typeof gdprConsent.gdprApplies === 'boolean')) {
gdprApplies = gdprConsent.gdprApplies;
}

if (syncOptions.iframeEnabled) {
if (!hasSynced) {
hasSynced = true;
if (gdprApplies) {
url = url + '?g=1&c=' + encodeURIComponent(gdprConsent.consentString);
}
syncs.push({
type: 'iframe',
url: url
});
}
} else {
if (!syncOptions.iframeEnabled) {
utils.logWarn('Aardvark: Please enable iframe based user sync.');
return syncs;
}

if (hasSynced) {
return syncs;
}

hasSynced = true;
if (gdprApplies) {
params.push(['g', '1']);
params.push(['c', gdprConsent.consentString]);
}

if (uspConsent) {
params.push(['us_privacy', uspConsent]);
}

var queryStr = '';
if (params.length) {
queryStr = '?' + params.map(p => p[0] + '=' + encodeURIComponent(p[1])).join('&')
}

syncs.push({
type: 'iframe',
url: `https://${SYNC_ENDPOINT}/cs${queryStr}`
});
return syncs;
},

Expand Down
57 changes: 57 additions & 0 deletions test/spec/modules/aardvarkBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,54 @@ describe('aardvarkAdapterTest', function () {
});
});

describe('CCPA conformity', function () {
const bidRequests = [{
bidder: 'aardvark',
params: {
ai: 'xiby',
sc: 'TdAx',
},
adUnitCode: 'aaa',
transactionId: '1b8389fe-615c-482d-9f1a-177fb8f7d5b0',
sizes: [300, 250],
bidId: '1abgs362e0x48a8',
bidderRequestId: '70deaff71c281d',
auctionId: '5c66da22-426a-4bac-b153-77360bef5337'
}];

it('should transmit us_privacy data', function () {
const usp = '1NY-';
const bidderRequest = {
gdprConsent: {
consentString: 'awefasdfwefasdfasd',
gdprApplies: true
},
refererInfo: {
referer: 'http://example.com'
},
uspConsent: usp
};
const requests = spec.buildRequests(bidRequests, bidderRequest);
expect(requests.length).to.equal(1);
expect(requests[0].data.gdpr).to.equal(true);
expect(requests[0].data.consent).to.equal('awefasdfwefasdfasd');
expect(requests[0].data.us_privacy).to.equal(usp);
});

it('should not send us_privacy', function () {
const bidderRequest = {
refererInfo: {
referer: 'http://example.com'
}
};
const requests = spec.buildRequests(bidRequests, bidderRequest);
expect(requests.length).to.equal(1);
expect(requests[0].data.gdpr).to.be.undefined;
expect(requests[0].data.consent).to.be.undefined;
expect(requests[0].data.us_privacy).to.be.undefined;
});
});

describe('interpretResponse', function () {
it('should handle bid responses', function () {
const serverResponse = {
Expand Down Expand Up @@ -343,6 +391,15 @@ describe('aardvarkAdapterTest', function () {
expect(syncs[0].type).to.equal('iframe');
expect(syncs[0].url).to.equal('https://sync.rtk.io/cs?g=1&c=BOEFEAyOEFEAyAHABDENAI4AAAB9vABAASA');
});

it('should produce sync url with ccpa params', function () {
resetUserSync();

const syncs = spec.getUserSyncs(syncOptions, null, {}, '1YYN');
expect(syncs.length).to.equal(1);
expect(syncs[0].type).to.equal('iframe');
expect(syncs[0].url).to.equal('https://sync.rtk.io/cs?us_privacy=1YYN');
});
});

describe('reading window.top properties', function () {
Expand Down

0 comments on commit 516208c

Please sign in to comment.