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

2.44.x-Legacy: Added CCPA support and GDPR compliance to Cedato adapter #4686

Merged
merged 1 commit 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
41 changes: 12 additions & 29 deletions modules/cedatoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import { registerBidder } from '../src/adapters/bidderFactory';
import { BANNER, VIDEO } from '../src/mediaTypes';

const BIDDER_CODE = 'cedato';
const BID_URL = '//h.cedatoplayer.com/hb';
const SYNC_URL = '//h.cedatoplayer.com/hb_usync?uid={UUID}';
const COOKIE_NAME = 'hb-cedato-id';
const UUID_LEN = 36;
const BID_URL = 'https://h.cedatoplayer.com/hb';
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
46 changes: 44 additions & 2 deletions 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 All @@ -68,7 +85,7 @@ describe('the cedato adapter', function () {
adomain: 'cedato.com',
uuid: bid.bidId,
crid: '1450133326',
adm: "<div id=\"cedato-unit\"></div>\n<script src=\"https://p.cedatoplayer.com/zplayer.js?p=952030718&cb=874433&d=localhost\" type=\"text/javascript\"></script>\n<img src='//h.cedatoplayer.com/hbwon?cb=874433&p=0.1&pi=952030718&w=300&h=250&s=952030718&d=localhost&u=a4657bf1-c373-4676-b79a-0d9de0129e38&ab=2' width=\"1\" height=\"1\"/>\n",
adm: "<div id=\"cedato-unit\"></div>\n<script src=\"https://p.cedatoplayer.com/zplayer.js?p=952030718&cb=874433&d=localhost\" type=\"text/javascript\"></script>\n<img src='https://h.cedatoplayer.com/hbwon?cb=874433&p=0.1&pi=952030718&w=300&h=250&s=952030718&d=localhost&u=a4657bf1-c373-4676-b79a-0d9de0129e38&ab=2' width=\"1\" height=\"1\"/>\n",
h: 250,
w: 300,
price: '0.1'
Expand All @@ -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');
});
});
});