Skip to content

SharedId & PubcommonId: CCPA and COPPA support #6632

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

Merged
merged 5 commits into from
May 3, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
26 changes: 23 additions & 3 deletions modules/pubCommonIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as utils from '../src/utils.js';
import {submodule} from '../src/hook.js';
import {getStorageManager} from '../src/storageManager.js';
import {ajax} from '../src/ajax.js';
import { uspDataHandler, coppaDataHandler } from '../src/adapterManager.js';

const PUB_COMMON_ID = 'PublisherCommonId';
const MODULE_NAME = 'pubCommonId';
Expand Down Expand Up @@ -142,9 +143,18 @@ function handleResponse(pubcid, callback, config) {
* @return {string}
*/
function sharedIdUrl(consentData) {
if (!consentData || typeof consentData.gdprApplies !== 'boolean' || !consentData.gdprApplies) return SHAREDID_URL;

return `${SHAREDID_URL}?gdpr=1&gdpr_consent=${consentData.consentString}`
const usPrivacyString = uspDataHandler.getConsentData();
let sharedIdUrl = SHAREDID_URL;
if (usPrivacyString && typeof usPrivacyString === 'string') {
sharedIdUrl = `${SHAREDID_URL}?us_privacy=${usPrivacyString}`;
}
if (!consentData || typeof consentData.gdprApplies !== 'boolean' || !consentData.gdprApplies) return sharedIdUrl;
if (usPrivacyString) {
sharedIdUrl = `${sharedIdUrl}&gdpr=1&gdpr_consent=${consentData.consentString}`
return sharedIdUrl;
}
sharedIdUrl = `${SHAREDID_URL}?gdpr=1&gdpr_consent=${consentData.consentString}`;
return sharedIdUrl
}

/**
Expand Down Expand Up @@ -223,6 +233,11 @@ export const pubCommonIdSubmodule = {
* @returns {IdResponse}
*/
getId: function (config = {}, consentData, storedId) {
const coppa = coppaDataHandler.getCoppa();
if (coppa) {
utils.logInfo('PubCommonId: coppa not provided, exiting PubCommonId');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this say "coppa not supported" or "IDs not provided for coppa requests"? to me, this message sounds like "coppa config wasn't provided, so we're existing"

return;
}
const {params: {create = true, pixelUrl, enableSharedId = SHAREDID_DEFAULT_STATE} = {}} = config;
let newId = storedId;
if (!newId) {
Expand Down Expand Up @@ -263,6 +278,11 @@ export const pubCommonIdSubmodule = {
* @returns {IdResponse|undefined}
*/
extendId: function(config = {}, consentData, storedId) {
const coppa = coppaDataHandler.getCoppa();
if (coppa) {
utils.logInfo('PubCommonId: coppa not provided, exiting PubCommonId');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above

return;
}
const {params: {extend = false, pixelUrl, enableSharedId = SHAREDID_DEFAULT_STATE} = {}} = config;

if (extend) {
Expand Down
26 changes: 23 additions & 3 deletions modules/sharedIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import * as utils from '../src/utils.js'
import {ajax} from '../src/ajax.js';
import {submodule} from '../src/hook.js';
import { uspDataHandler, coppaDataHandler } from '../src/adapterManager.js';

const MODULE_NAME = 'sharedId';
const ID_SVC = 'https://id.sharedid.org/id';
Expand Down Expand Up @@ -282,9 +283,18 @@ function detectPrng(root) {
* @return {string}
*/
function sharedIdUrl(consentData) {
if (!consentData || typeof consentData.gdprApplies !== 'boolean' || !consentData.gdprApplies) return ID_SVC;

return `${ID_SVC}?gdpr=1&gdpr_consent=${consentData.consentString}`
const usPrivacyString = uspDataHandler.getConsentData();
let sharedIdUrl = ID_SVC;
if (usPrivacyString) {
sharedIdUrl = `${ID_SVC}?us_privacy=${usPrivacyString}`;
}
if (!consentData || typeof consentData.gdprApplies !== 'boolean' || !consentData.gdprApplies) return sharedIdUrl;
if (usPrivacyString) {
sharedIdUrl = `${sharedIdUrl}&gdpr=1&gdpr_consent=${consentData.consentString}`
return sharedIdUrl;
}
sharedIdUrl = `${ID_SVC}?gdpr=1&gdpr_consent=${consentData.consentString}`;
return sharedIdUrl
}

/** @type {Submodule} */
Expand Down Expand Up @@ -318,6 +328,11 @@ export const sharedIdSubmodule = {
* @returns {sharedId}
*/
getId(config, consentData) {
const coppa = coppaDataHandler.getCoppa();
if (coppa) {
utils.logInfo('SharedId: coppa not provided, exiting SharedId');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

return;
}
const resp = function (callback) {
utils.logInfo('SharedId: Sharedid doesnt exists, new cookie creation');
ajax(sharedIdUrl(consentData), idGenerationCallback(callback), undefined, {method: 'GET', withCredentials: true});
Expand All @@ -333,6 +348,11 @@ export const sharedIdSubmodule = {
* @returns {{callback: *}}
*/
extendId(config, consentData, storedId) {
const coppa = coppaDataHandler.getCoppa();
if (coppa) {
utils.logInfo('SharedId: coppa not provided, exiting SharedId');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

return;
}
const configParams = (config && config.params) || {};
utils.logInfo('SharedId: Existing shared id ' + storedId.id);
const resp = function (callback) {
Expand Down
22 changes: 11 additions & 11 deletions modules/userId/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@
*/

/**
* @typedef {Object} RefreshUserIdsOptions
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this whole file just seems like whitespace changes now...can you just revert them all since there's no functional change?

* @property {(string[]|undefined)} submoduleNames - submodules to refresh
*/
* @typedef {Object} RefreshUserIdsOptions
* @property {(string[]|undefined)} submoduleNames - submodules to refresh
*/

import find from 'core-js-pure/features/array/find.js';
import { config } from '../../src/config.js';
Expand Down Expand Up @@ -225,7 +225,7 @@ function setPrebidServerEidPermissions(initializedSubmodules) {
}

/**
/**
/**
* @param {SubmoduleStorage} storage
* @param {String|undefined} key optional key of the value
* @returns {string}
Expand Down Expand Up @@ -341,10 +341,10 @@ function hasGDPRConsent(consentData) {
}

/**
* Find the root domain
* @param {string|undefined} fullDomain
* @return {string}
*/
* Find the root domain
* @param {string|undefined} fullDomain
* @return {string}
*/
export function findRootDomain(fullDomain = window.location.hostname) {
if (!coreStorage.cookiesAreEnabled()) {
return fullDomain;
Expand Down Expand Up @@ -579,9 +579,9 @@ function getUserIdsAsEids() {
}

/**
* This function will be exposed in the global-name-space so that userIds can be refreshed after initialization.
* @param {RefreshUserIdsOptions} options
*/
* This function will be exposed in the global-name-space so that userIds can be refreshed after initialization.
* @param {RefreshUserIdsOptions} options
*/
function refreshUserIds(options, callback) {
let submoduleNames = options ? options.submoduleNames : null;
if (!submoduleNames) {
Expand Down
6 changes: 6 additions & 0 deletions src/adapterManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ export let uspDataHandler = {
}
};

export let coppaDataHandler = {
getCoppa: function() {
return !!(config.getConfig('coppa'))
}
};

// export for testing
export let clientTestAdapters = [];
export const allS2SBidders = [];
Expand Down
26 changes: 24 additions & 2 deletions test/spec/modules/sharedIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@ import {
sharedIdSubmodule,
} from 'modules/sharedIdSystem.js';
import { server } from 'test/mocks/xhr.js';
import {uspDataHandler} from 'src/adapterManager';

let expect = require('chai').expect;

describe('SharedId System', function() {
const SHAREDID_RESPONSE = {sharedId: 'testsharedid'};

let uspConsentDataStub;
describe('Xhr Requests from getId()', function() {
let callbackSpy = sinon.spy();

beforeEach(function() {
callbackSpy.resetHistory();
uspConsentDataStub = sinon.stub(uspDataHandler, 'getConsentData');
});

afterEach(function () {

uspConsentDataStub.restore();
});

it('should call shared id endpoint without consent data and handle a valid response', function () {
Expand Down Expand Up @@ -51,5 +53,25 @@ describe('SharedId System', function() {
expect(callbackSpy.calledOnce).to.be.true;
expect(callbackSpy.lastCall.lastArg.id).to.equal(SHAREDID_RESPONSE.sharedId);
});

it('should call shared id endpoint with usp consent data and handle a valid response', function () {
uspConsentDataStub.returns('1YYY');
let consentData = {
gdprApplies: true,
consentString: 'abc12345234',
};

let submoduleCallback = sharedIdSubmodule.getId(undefined, consentData).callback;
submoduleCallback(callbackSpy);

let request = server.requests[0];
expect(request.url).to.equal('https://id.sharedid.org/id?us_privacy=1YYY&gdpr=1&gdpr_consent=abc12345234');
expect(request.withCredentials).to.be.true;

request.respond(200, {}, JSON.stringify(SHAREDID_RESPONSE));

expect(callbackSpy.calledOnce).to.be.true;
expect(callbackSpy.lastCall.lastArg.id).to.equal(SHAREDID_RESPONSE.sharedId);
});
});
});