Skip to content

Commit

Permalink
Support for CCPA
Browse files Browse the repository at this point in the history
  • Loading branch information
pm-shashank-jain committed Jan 15, 2020
1 parent 3613f95 commit 3d75e1b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
11 changes: 10 additions & 1 deletion modules/pubmaticServerBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ export const spec = {
};
}

// CCPA
if (bidderRequest && bidderRequest.uspConsent) {
utils.deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent);
}

payload.device.geo = payload.user.geo;
payload.site.page = conf.kadpageurl || payload.site.page;
payload.site.domain = utils.getTopWindowHostName();
Expand Down Expand Up @@ -459,7 +464,7 @@ export const spec = {
/**
* Register User Sync.
*/
getUserSyncs: (syncOptions, serverResponses, gdprConsent) => {
getUserSyncs: (syncOptions, serverResponses, gdprConsent, uspConsent) => {
let urls = [];
var bidders = config.getConfig('userSync.enabledBidders');
var UUID = utils.getUniqueIdentifierStr();
Expand All @@ -472,6 +477,10 @@ export const spec = {
data['gdpr'] = gdprConsent.gdprApplies ? 1 : 0;
data['gdpr_consent'] = encodeURIComponent(gdprConsent.consentString || '');
}
// CCPA
if (uspConsent) {
data['us_privacy'] = encodeURIComponent(uspConsent);
}

ajax.ajax(COOKIE_SYNC, cookieSyncCallBack, JSON.stringify(data), {
withCredentials: true
Expand Down
51 changes: 51 additions & 0 deletions test/spec/modules/pubmaticServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,57 @@ describe('PubMaticServer adapter', () => {
expect(data.imp[0].banner.format[0].w).to.equal(300); // width from 1st element of sizes array
expect(data.imp[0].banner.format[0].h).to.equal(250); // height from 1st element of sizes array
});

it('Request params check with USP/CCPA Consent', () => {
let bidRequest = {
uspConsent: '1NYN'
};
let request = spec.buildRequests(bidRequests, bidRequest);
let data = JSON.parse(request.data);
expect(data.regs.ext.us_privacy).to.equal('1NYN');// USP/CCPAs
expect(data.at).to.equal(1); // auction type
expect(data.cur[0]).to.equal('USD'); // currency
expect(data.site.domain).to.be.a('string'); // domain should be set
expect(data.site.page).to.equal(bidRequests[0].params.kadpageurl); // forced pageURL
expect(data.site.publisher.id).to.equal(bidRequests[0].params.publisherId); // publisher Id
expect(data.ext.wrapper.wv).to.equal(constants.REPO_AND_VERSION); // Wrapper Version
expect(data.ext.wrapper.wp).to.equal('pbjs'); // Prebid TransactionId
expect(data.ext.wrapper.wiid).to.equal(bidRequests[0].params.wiid); // OpenWrap: Wrapper Impression ID
expect(data.user.yob).to.equal(parseInt(bidRequests[0].params.yob)); // YOB
expect(data.user.gender).to.equal(bidRequests[0].params.gender); // Gender
expect(data.device.geo.lat).to.equal(parseFloat(bidRequests[0].params.lat)); // Latitude
expect(data.device.geo.lon).to.equal(parseFloat(bidRequests[0].params.lon)); // Lognitude
expect(data.user.geo.lat).to.equal(parseFloat(bidRequests[0].params.lat)); // Latitude
expect(data.user.geo.lon).to.equal(parseFloat(bidRequests[0].params.lon)); // Lognitude
expect(data.ext.wrapper.profileid).to.equal(parseInt(bidRequests[0].params.profId)); // OpenWrap: Wrapper Profile ID
expect(data.ext.wrapper.versionid).to.equal(parseInt(bidRequests[0].params.verId)); // OpenWrap: Wrapper Profile Version ID
expect(data.ext.wrapper.sumry_disable).to.equal(0); // OpenWrap: Summary Disable flag
expect(data.ext.wrapper.ssauction).to.equal(0); // OpenWrap: Server Side Auction flag
expect(data.imp[0].id).to.equal(bidRequests[0].bidId); // Prebid bid id is passed as id
expect(data.imp[0].bidfloor).to.equal(parseFloat(bidRequests[0].params.kadfloor)); // kadfloor
expect(data.imp[0].tagid).to.equal(bidRequests[0].params.adUnitId); // tagid
expect(data.imp[0].banner.format[0].w).to.equal(300); // width from 1st element of sizes array
expect(data.imp[0].banner.format[0].h).to.equal(250); // height from 1st element of sizes array
expect(data.imp[0].banner.format[1].w).to.equal(300); // width
expect(data.imp[0].banner.format[1].h).to.equal(600); // height
expect(data.imp[0].ext.bidder.pubmatic.pmZoneId).to.equal(bidRequests[0].params.pmzoneid.split(',').slice(0, 50).map(id => id.trim()).join()); // pmzoneid
// TODO: Need to figure why this failing
// expect(data.imp[0].ext.adunit).to.equal(bidRequests[0].params.adUnitId); // adUnitId
expect(data.imp[0].ext.wrapper.div).to.equal(bidRequests[0].params.divId); // div

// when sizes array has only 1 element
bidRequests[0].sizes = [[300, 250]];
request = spec.buildRequests(bidRequests, bidRequest);
data = JSON.parse(request.data);

expect(data.imp[0].banner.format[0].w).to.equal(300); // width from 1st element of sizes array
expect(data.imp[0].banner.format[0].h).to.equal(250); // height from 1st element of sizes array

// second request without USP/CCPA
let request2 = spec.buildRequests(bidRequests, {});
let data2 = JSON.parse(request2.data);
expect(data2.regs).to.equal(undefined);// USP/CCPAs
});
});

describe('Response checking', () => {
Expand Down

0 comments on commit 3d75e1b

Please sign in to comment.