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

DfpAdServerVideo: Pass GDPR Consent Data #6143

Merged
merged 2 commits into from
Jan 8, 2021
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
16 changes: 15 additions & 1 deletion modules/dfpAdServerVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { deepAccess, isEmpty, logError, parseSizesInput, formatQS, parseUrl, bui
import { config } from '../src/config.js';
import { getHook, submodule } from '../src/hook.js';
import { auctionManager } from '../src/auctionManager.js';
import { uspDataHandler } from '../src/adapterManager.js';
import { gdprDataHandler, uspDataHandler } from '../src/adapterManager.js';
import events from '../src/events.js';
import CONSTANTS from '../src/constants.json';

Expand Down Expand Up @@ -101,6 +101,13 @@ export function buildDfpVideoUrl(options) {
const descriptionUrl = getDescriptionUrl(bid, options, 'params');
if (descriptionUrl) { queryParams.description_url = descriptionUrl; }

const gdprConsent = gdprDataHandler.getConsentData();
if (gdprConsent) {
if (typeof gdprConsent.gdprApplies === 'boolean') { queryParams.gdpr = Number(gdprConsent.gdprApplies); }
if (gdprConsent.consentString) { queryParams.gdpr_consent = gdprConsent.consentString; }
if (gdprConsent.addtlConsent) { queryParams.addtl_consent = gdprConsent.addtlConsent; }
}

const uspConsent = uspDataHandler.getConsentData();
if (uspConsent) { queryParams.us_privacy = uspConsent; }

Expand Down Expand Up @@ -187,6 +194,13 @@ export function buildAdpodVideoUrl({code, params, callback} = {}) {
{ cust_params: encodedCustomParams }
);

const gdprConsent = gdprDataHandler.getConsentData();
if (gdprConsent) {
if (typeof gdprConsent.gdprApplies === 'boolean') { queryParams.gdpr = Number(gdprConsent.gdprApplies); }
if (gdprConsent.consentString) { queryParams.gdpr_consent = gdprConsent.consentString; }
if (gdprConsent.addtlConsent) { queryParams.addtl_consent = gdprConsent.addtlConsent; }
}

const uspConsent = uspDataHandler.getConsentData();
if (uspConsent) { queryParams.us_privacy = uspConsent; }

Expand Down
84 changes: 83 additions & 1 deletion test/spec/modules/dfpAdServerVideo_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as utils from 'src/utils.js';
import { config } from 'src/config.js';
import { targeting } from 'src/targeting.js';
import { auctionManager } from 'src/auctionManager.js';
import { uspDataHandler } from 'src/adapterManager.js';
import { gdprDataHandler, uspDataHandler } from 'src/adapterManager.js';
import * as adpod from 'modules/adpod.js';
import { server } from 'test/mocks/xhr.js';

Expand Down Expand Up @@ -154,6 +154,78 @@ describe('The DFP video support module', function () {
expect(queryObject.us_privacy).to.equal(undefined);
});

it('should include the GDPR keys when GDPR Consent is available', function () {
let gdprDataHandlerStub = sinon.stub(gdprDataHandler, 'getConsentData');
gdprDataHandlerStub.returns({
gdprApplies: true,
consentString: 'consent',
addtlConsent: 'moreConsent'
});

const bidCopy = utils.deepClone(bid);
bidCopy.adserverTargeting = Object.assign(bidCopy.adserverTargeting, {
hb_adid: 'ad_id',
});

const url = parse(buildDfpVideoUrl({
adUnit: adUnit,
bid: bidCopy,
params: {
'iu': 'my/adUnit'
}
}));
const queryObject = utils.parseQS(url.query);
expect(queryObject.gdpr).to.equal('1');
expect(queryObject.gdpr_consent).to.equal('consent');
expect(queryObject.addtl_consent).to.equal('moreConsent');
gdprDataHandlerStub.restore();
});

it('should not include the GDPR keys when GDPR Consent is not available', function () {
const bidCopy = utils.deepClone(bid);
bidCopy.adserverTargeting = Object.assign(bidCopy.adserverTargeting, {
hb_adid: 'ad_id',
});

const url = parse(buildDfpVideoUrl({
adUnit: adUnit,
bid: bidCopy,
params: {
'iu': 'my/adUnit'
}
}));
const queryObject = utils.parseQS(url.query);
expect(queryObject.gdpr).to.equal(undefined);
expect(queryObject.gdpr_consent).to.equal(undefined);
expect(queryObject.addtl_consent).to.equal(undefined);
});

it('should only include the GDPR keys for GDPR Consent fields with values', function () {
let gdprDataHandlerStub = sinon.stub(gdprDataHandler, 'getConsentData');
gdprDataHandlerStub.returns({
gdprApplies: true,
consentString: 'consent',
});

const bidCopy = utils.deepClone(bid);
bidCopy.adserverTargeting = Object.assign(bidCopy.adserverTargeting, {
hb_adid: 'ad_id',
});

const url = parse(buildDfpVideoUrl({
adUnit: adUnit,
bid: bidCopy,
params: {
'iu': 'my/adUnit'
}
}));
const queryObject = utils.parseQS(url.query);
expect(queryObject.gdpr).to.equal('1');
expect(queryObject.gdpr_consent).to.equal('consent');
expect(queryObject.addtl_consent).to.equal(undefined);
gdprDataHandlerStub.restore();
});

describe('special targeting unit test', function () {
const allTargetingData = {
'hb_format': 'video',
Expand Down Expand Up @@ -391,6 +463,12 @@ describe('The DFP video support module', function () {
amStub.returns(getBidsReceived());
let uspDataHandlerStub = sinon.stub(uspDataHandler, 'getConsentData');
uspDataHandlerStub.returns('1YYY');
let gdprDataHandlerStub = sinon.stub(gdprDataHandler, 'getConsentData');
gdprDataHandlerStub.returns({
gdprApplies: true,
consentString: 'consent',
addtlConsent: 'moreConsent'
});
let url;
parse(buildAdpodVideoUrl({
code: 'adUnitCode-1',
Expand Down Expand Up @@ -422,11 +500,15 @@ describe('The DFP video support module', function () {
expect(queryParams).to.have.property('url');
expect(queryParams).to.have.property('cust_params');
expect(queryParams).to.have.property('us_privacy', '1YYY');
expect(queryParams).to.have.property('gdpr', '1');
expect(queryParams).to.have.property('gdpr_consent', 'consent');
expect(queryParams).to.have.property('addtl_consent', 'moreConsent');

const custParams = utils.parseQS(decodeURIComponent(queryParams.cust_params));
expect(custParams).to.have.property('hb_cache_id', '123');
expect(custParams).to.have.property('hb_pb_cat_dur', '15.00_395_15s,15.00_406_30s,10.00_395_15s');
uspDataHandlerStub.restore();
gdprDataHandlerStub.restore();
}
});

Expand Down