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

Added CCPA support and GDPR compliance to Cedato adapter #4683

Merged
merged 2 commits into from
Jan 3, 2020
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
39 changes: 11 additions & 28 deletions modules/cedatoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { BANNER, VIDEO } from '../src/mediaTypes';

const BIDDER_CODE = 'cedato';
const BID_URL = 'https://h.cedatoplayer.com/hb';
const SYNC_URL = 'https://h.cedatoplayer.com/hb_usync?uid={UUID}';
const COOKIE_NAME = 'hb-cedato-id';
const UUID_LEN = 36;
const SYNC_URL = 'https://h.cedatoplayer.com/hb_usync';
const TTL = 10000;
const CURRENCY = 'USD';
const FIRST_PRICE = 1;
Expand All @@ -32,7 +30,6 @@ export const spec = {
const at = FIRST_PRICE;
const site = { id: params.player_id, domain: document.domain };
const device = { ua: navigator.userAgent };
const user = { id: getUserID() }
const currency = CURRENCY;
const tmax = bidderRequest.timeout;
const auctionId = bidderRequest.auctionId;
Expand All @@ -46,6 +43,7 @@ export const spec = {
const bidId = req.bidId;
const adUnitCode = req.adUnitCode;
const bidRequestsCount = req.bidRequestsCount;
const bidderWinsCount = req.bidderWinsCount;
const transactionId = req.transactionId;

return {
Expand All @@ -55,6 +53,7 @@ export const spec = {
adUnitCode,
bidfloor,
bidRequestsCount,
bidderWinsCount,
transactionId
};
});
Expand All @@ -64,7 +63,6 @@ export const spec = {
at,
site,
device,
user,
imp,
currency,
tmax,
Expand All @@ -75,6 +73,8 @@ export const spec = {

if (bidderRequest) {
payload.referer_info = bidderRequest.refererInfo;
payload.us_privacy = bidderRequest.uspConsent;

if (bidderRequest.gdprConsent) {
payload.gdpr_consent = {
consent_string: bidderRequest.gdprConsent.consentString,
Expand Down Expand Up @@ -108,12 +108,12 @@ export const spec = {
return bids;
},

getUserSyncs: function(syncOptions, resps, gdprConsent) {
getUserSyncs: function(syncOptions, resps, gdprConsent, uspConsent) {
const syncs = [];
if (syncOptions.iframeEnabled) {
syncs.push(getSync('iframe', gdprConsent));
syncs.push(getSync('iframe', gdprConsent, uspConsent));
} else if (syncOptions.pixelEnabled) {
syncs.push(getSync('image', gdprConsent));
syncs.push(getSync('image', gdprConsent, uspConsent));
}
return syncs;
}
Expand Down Expand Up @@ -186,10 +186,9 @@ function newBid(serverBid, bidderRequest) {
return bid;
}

const getSync = (type, gdprConsent) => {
const uuid = getUserID();
const getSync = (type, gdprConsent, uspConsent = '') => {
const syncUrl = SYNC_URL;
let params = '&type=' + type;
let params = '&type=' + type + '&us_privacy=' + uspConsent;
if (gdprConsent && typeof gdprConsent.consentString === 'string') {
if (typeof gdprConsent.gdprApplies === 'boolean') {
params += `&gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`;
Expand All @@ -199,26 +198,10 @@ const getSync = (type, gdprConsent) => {
}
return {
type: type,
url: syncUrl.replace('{UUID}', uuid) + params,
url: syncUrl + params,
};
}

const getUserID = () => {
const cookieName = COOKIE_NAME;
const uuidLen = UUID_LEN;

const i = document.cookie.indexOf(cookieName);

if (i === -1) {
const uuid = utils.generateUUID();
document.cookie = `${cookieName}=${uuid}; path=/`;
return uuid;
}

const j = i + cookieName.length + 1;
return document.cookie.substring(j, j + uuidLen);
};

const getFormats = arr => arr.map((s) => {
return { w: s[0], h: s[1] };
});
Expand Down
44 changes: 43 additions & 1 deletion test/spec/modules/cedatoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,35 @@ describe('the cedato adapter', function () {
expect(result).to.equal(false);
});
});

describe('buildRequests', function() {
var bid, bidRequestObj;

beforeEach(function() {
bid = getValidBidObject();
bidRequestObj = {refererInfo: {referer: 'prebid.js'}};
bidRequestObj = {
refererInfo: {referer: 'prebid.js'},
gdprConsent: {
consentString: 'test-string',
gdprApplies: true
},
uspConsent: '1NYN'
};
});

it('should build a very basic request', function() {
var request = spec.buildRequests([bid], bidRequestObj);
expect(request.method).to.equal('POST');
});

it('should pass gdpr and usp strings to server', function() {
var request = spec.buildRequests([bid], bidRequestObj);
var payload = JSON.parse(request.data);
expect(payload.gdpr_consent).to.not.be.undefined;
expect(payload.gdpr_consent.consent_string).to.equal(bidRequestObj.gdprConsent.consentString);
expect(payload.gdpr_consent.consent_required).to.equal(bidRequestObj.gdprConsent.gdprApplies);
expect(payload.us_privacy).to.equal(bidRequestObj.uspConsent);
});
});

describe('interpretResponse', function() {
Expand Down Expand Up @@ -88,4 +105,29 @@ describe('the cedato adapter', function () {
expect(responses).to.be.an('array').with.length(1);
});
});

describe('getUserSyncs', function() {
var bid;

beforeEach(function() {
bid = getValidBidObject();
});

it('should sync with iframe', function() {
var syncs = spec.getUserSyncs({ iframeEnabled: true }, null, {
consentString: '',
gdprApplies: true
});

expect(syncs).to.be.an('array').with.length(1);
expect(syncs[0].type).to.equal('iframe');
});

it('should sync with image', function() {
var syncs = spec.getUserSyncs({ pixelEnabled: true });

expect(syncs).to.be.an('array').with.length(1);
expect(syncs[0].type).to.equal('image');
});
});
});