Skip to content

Commit

Permalink
adagioBidAdapter: add support for CCPA, COPPA
Browse files Browse the repository at this point in the history
  • Loading branch information
Clement3 authored and osazos committed Sep 15, 2020
1 parent 0bd72ab commit 4bb640e
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 8 deletions.
21 changes: 19 additions & 2 deletions modules/adagioBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import find from 'core-js-pure/features/array/find.js';
import * as utils from '../src/utils.js';
import { config } from '../src/config.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import { loadExternalScript } from '../src/adloader.js'
import JSEncrypt from 'jsencrypt/bin/jsencrypt.js';
Expand All @@ -9,7 +10,7 @@ import { getRefererInfo } from '../src/refererDetection.js';

export const BIDDER_CODE = 'adagio';
export const LOG_PREFIX = 'Adagio:';
export const VERSION = '2.3.0';
export const VERSION = '2.4.0';
export const FEATURES_VERSION = '1';
export const ENDPOINT = 'https://mp.4dex.io/prebid';
export const SUPPORTED_MEDIA_TYPES = ['banner'];
Expand Down Expand Up @@ -555,6 +556,16 @@ function _getGdprConsent(bidderRequest) {
return consent;
}

function _getCoppa() {
return {
required: config.getConfig('coppa') === true ? 1 : 0
};
}

function _getUspConsent(bidderRequest) {
return (utils.deepAccess(bidderRequest, 'uspConsent')) ? { uspConsent: bidderRequest.uspConsent } : false;
}

function _getSchain(bidRequest) {
if (utils.deepAccess(bidRequest, 'schain')) {
return bidRequest.schain;
Expand Down Expand Up @@ -643,6 +654,8 @@ export const spec = {
const site = internal.getSite(bidderRequest);
const pageviewId = internal.getPageviewId();
const gdprConsent = _getGdprConsent(bidderRequest) || {};
const uspConsent = _getUspConsent(bidderRequest) || {};
const coppa = _getCoppa();
const schain = _getSchain(validBidRequests[0]);
const adUnits = utils._map(validBidRequests, (bidRequest) => {
bidRequest.features = internal.getFeatures(bidRequest, bidderRequest);
Expand Down Expand Up @@ -672,7 +685,11 @@ export const spec = {
site: site,
pageviewId: pageviewId,
adUnits: groupedAdUnits[organizationId],
gdpr: gdprConsent,
regs: {
gdpr: gdprConsent,
coppa: coppa,
ccpa: uspConsent
},
schain: schain,
prebidVersion: '$prebid.version$',
adapterVersion: VERSION,
Expand Down
71 changes: 65 additions & 6 deletions test/spec/modules/adagioBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { expect } from 'chai';
import { _features, internal as adagio, adagioScriptFromLocalStorageCb, getAdagioScript, storage, spec, ENDPOINT, VERSION } from '../../../modules/adagioBidAdapter.js';
import { loadExternalScript } from '../../../src/adloader.js';
import * as utils from '../../../src/utils.js';
import { config } from 'src/config.js';

const BidRequestBuilder = function BidRequestBuilder(options) {
const defaults = {
Expand Down Expand Up @@ -285,7 +286,7 @@ describe('Adagio bid adapter', () => {
'site',
'pageviewId',
'adUnits',
'gdpr',
'regs',
'schain',
'prebidVersion',
'adapterVersion',
Expand Down Expand Up @@ -450,7 +451,7 @@ describe('Adagio bid adapter', () => {

const requests = spec.buildRequests([bid01], bidderRequest);

expect(requests[0].data.gdpr).to.deep.equal(expected);
expect(requests[0].data.regs.gdpr).to.deep.equal(expected);
});

it('send data.gdpr object to the server from TCF v.2 cmp', function() {
Expand All @@ -466,7 +467,7 @@ describe('Adagio bid adapter', () => {

const requests = spec.buildRequests([bid01], bidderRequest);

expect(requests[0].data.gdpr).to.deep.equal(expected);
expect(requests[0].data.regs.gdpr).to.deep.equal(expected);
});
});

Expand All @@ -485,7 +486,7 @@ describe('Adagio bid adapter', () => {

const requests = spec.buildRequests([bid01], bidderRequest);

expect(requests[0].data.gdpr).to.deep.equal(expected);
expect(requests[0].data.regs.gdpr).to.deep.equal(expected);
});

it('send data.gdpr object to the server from TCF v.2 cmp', function() {
Expand All @@ -501,7 +502,7 @@ describe('Adagio bid adapter', () => {

const requests = spec.buildRequests([bid01], bidderRequest);

expect(requests[0].data.gdpr).to.deep.equal(expected);
expect(requests[0].data.regs.gdpr).to.deep.equal(expected);
});
});

Expand All @@ -510,10 +511,68 @@ describe('Adagio bid adapter', () => {
const bidderRequest = new BidderRequestBuilder().build();
const requests = spec.buildRequests([bid01], bidderRequest);

expect(requests[0].data.gdpr).to.be.empty;
expect(requests[0].data.regs.gdpr).to.be.empty;
});
});
});

describe('with COPPA', function() {
const bid01 = new BidRequestBuilder().withParams().build();

it('should send the Coppa "required" flag set to "1" in the request', function () {
const bidderRequest = new BidderRequestBuilder().build();

sinon.stub(config, 'getConfig')
.withArgs('coppa')
.returns(true);

const requests = spec.buildRequests([bid01], bidderRequest);

expect(requests[0].data.regs.coppa.required).to.equal(1);

config.getConfig.restore();
});
});

describe('without COPPA', function() {
const bid01 = new BidRequestBuilder().withParams().build();

it('should send the Coppa "required" flag set to "0" in the request', function () {
const bidderRequest = new BidderRequestBuilder().build();

const requests = spec.buildRequests([bid01], bidderRequest);

expect(requests[0].data.regs.coppa.required).to.equal(0);
});
});

describe('with USPrivacy', function() {
const bid01 = new BidRequestBuilder().withParams().build();

const consent = 'Y11N'

it('should send the USPrivacy "ccpa.uspConsent" in the request', function () {
const bidderRequest = new BidderRequestBuilder({
uspConsent: consent
}).build();

const requests = spec.buildRequests([bid01], bidderRequest);

expect(requests[0].data.regs.ccpa.uspConsent).to.equal(consent);
});
});

describe('without USPrivacy', function() {
const bid01 = new BidRequestBuilder().withParams().build();

it('should have an empty "ccpa" field in the request', function () {
const bidderRequest = new BidderRequestBuilder().build();

const requests = spec.buildRequests([bid01], bidderRequest);

expect(requests[0].data.regs.ccpa).to.be.empty;
});
});
});

describe('interpretResponse()', function() {
Expand Down

0 comments on commit 4bb640e

Please sign in to comment.