Skip to content

Commit

Permalink
Yahoo ConnectId - gpp consent module usage. (prebid#10022)
Browse files Browse the repository at this point in the history
Co-authored-by: dumitrubarbos <[email protected]>
  • Loading branch information
2 people authored and Michele Nasti committed Aug 25, 2023
1 parent 4ceb2d2 commit 5d4f6e3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
10 changes: 9 additions & 1 deletion modules/connectIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {includes} from '../src/polyfill.js';
import {getRefererInfo} from '../src/refererDetection.js';
import {getStorageManager} from '../src/storageManager.js';
import {formatQS, isPlainObject, logError, parseUrl} from '../src/utils.js';
import {uspDataHandler} from '../src/adapterManager.js';
import {uspDataHandler, gppDataHandler} from '../src/adapterManager.js';
import {MODULE_TYPE_UID} from '../src/activities/modules.js';

const MODULE_NAME = 'connectId';
Expand Down Expand Up @@ -198,6 +198,14 @@ export const connectIdSubmodule = {
us_privacy: uspString
};

const gppConsent = gppDataHandler.getConsentData();
if (gppConsent) {
data.gpp = `${gppConsent.gppString ? gppConsent.gppString : ''}`;
if (Array.isArray(gppConsent.applicableSections)) {
data.gpp_sid = gppConsent.applicableSections.join(',');
}
}

let topmostLocation = getRefererInfo().topmostLocation;
if (typeof topmostLocation === 'string') {
data.url = topmostLocation.split('?')[0];
Expand Down
47 changes: 43 additions & 4 deletions test/spec/modules/connectIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {expect} from 'chai';
import {connectIdSubmodule, storage} from 'modules/connectIdSystem.js';
import {server} from '../../mocks/xhr';
import {parseQS, parseUrl} from 'src/utils.js';
import {uspDataHandler} from 'src/adapterManager.js';
import {uspDataHandler, gppDataHandler} from 'src/adapterManager.js';

const TEST_SERVER_URL = 'http://localhost:9876/';

Expand All @@ -14,6 +14,10 @@ describe('Yahoo ConnectID Submodule', () => {
const OVERRIDE_ENDPOINT = 'https://foo/bar';
const STORAGE_KEY = 'connectId';
const USP_DATA = '1YYY';
const GPP_DATA = {
gppString: 'gppconsent',
applicableSections: [6, 7]
};

it('should have the correct module name declared', () => {
expect(connectIdSubmodule.name).to.equal('connectId');
Expand All @@ -34,6 +38,7 @@ describe('Yahoo ConnectID Submodule', () => {
let localStorageEnabledStub;
let removeLocalStorageDataStub;
let uspConsentDataStub;
let gppConsentDataStub;

let consentData;
beforeEach(() => {
Expand All @@ -48,10 +53,12 @@ describe('Yahoo ConnectID Submodule', () => {
localStorageEnabledStub = sinon.stub(storage, 'localStorageIsEnabled');
removeLocalStorageDataStub = sinon.stub(storage, 'removeDataFromLocalStorage');
uspConsentDataStub = sinon.stub(uspDataHandler, 'getConsentData');
gppConsentDataStub = sinon.stub(gppDataHandler, 'getConsentData');

cookiesEnabledStub.returns(true);
localStorageEnabledStub.returns(true);
uspConsentDataStub.returns(USP_DATA);
gppConsentDataStub.returns(GPP_DATA);

consentData = {
gdprApplies: 1,
Expand All @@ -69,6 +76,7 @@ describe('Yahoo ConnectID Submodule', () => {
localStorageEnabledStub.restore();
removeLocalStorageDataStub.restore();
uspConsentDataStub.restore();
gppConsentDataStub.restore();
});

function invokeGetIdAPI(configParams, consentData) {
Expand Down Expand Up @@ -495,7 +503,9 @@ describe('Yahoo ConnectID Submodule', () => {
gdpr_consent: consentData.consentString,
v: '1',
url: TEST_SERVER_URL,
us_privacy: USP_DATA
us_privacy: USP_DATA,
gpp: GPP_DATA.gppString,
gpp_sid: GPP_DATA.applicableSections.join(',')
};
const requestQueryParams = parseQS(ajaxStub.firstCall.args[0].split('?')[1]);

Expand All @@ -518,7 +528,9 @@ describe('Yahoo ConnectID Submodule', () => {
pixelId: PIXEL_ID,
gdpr_consent: consentData.consentString,
url: TEST_SERVER_URL,
us_privacy: USP_DATA
us_privacy: USP_DATA,
gpp: GPP_DATA.gppString,
gpp_sid: GPP_DATA.applicableSections.join(',')
};
const requestQueryParams = parseQS(ajaxStub.firstCall.args[0].split('?')[1]);

Expand All @@ -543,7 +555,9 @@ describe('Yahoo ConnectID Submodule', () => {
gdpr_consent: consentData.consentString,
v: '1',
url: TEST_SERVER_URL,
us_privacy: USP_DATA
us_privacy: USP_DATA,
gpp: GPP_DATA.gppString,
gpp_sid: GPP_DATA.applicableSections.join(',')
};
const requestQueryParams = parseQS(ajaxStub.firstCall.args[0].split('?')[1]);

Expand All @@ -558,6 +572,31 @@ describe('Yahoo ConnectID Submodule', () => {
endpoint: OVERRIDE_ENDPOINT
}, consentData);

const expectedParams = {
he: HASHED_EMAIL,
'1p': '0',
gdpr: '1',
gdpr_consent: consentData.consentString,
v: '1',
url: TEST_SERVER_URL,
us_privacy: USP_DATA,
gpp: GPP_DATA.gppString,
gpp_sid: GPP_DATA.applicableSections.join(',')
};
const requestQueryParams = parseQS(ajaxStub.firstCall.args[0].split('?')[1]);

expect(ajaxStub.firstCall.args[0].indexOf(`${OVERRIDE_ENDPOINT}?`)).to.equal(0);
expect(requestQueryParams).to.deep.equal(expectedParams);
expect(ajaxStub.firstCall.args[3]).to.deep.equal({method: 'GET', withCredentials: true});
});

it('Makes an ajax GET request to the specified override API endpoint without GPP', () => {
gppConsentDataStub.returns(undefined);
invokeGetIdAPI({
he: HASHED_EMAIL,
endpoint: OVERRIDE_ENDPOINT
}, consentData);

const expectedParams = {
he: HASHED_EMAIL,
'1p': '0',
Expand Down

0 comments on commit 5d4f6e3

Please sign in to comment.