Skip to content

Commit

Permalink
ID5 User Id module - pass gpp string and sid in getId request
Browse files Browse the repository at this point in the history
  • Loading branch information
abazylewicz-id5 committed Jan 5, 2024
1 parent 04a7659 commit 532970b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
12 changes: 9 additions & 3 deletions modules/id5IdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {ajax} from '../src/ajax.js';
import {submodule} from '../src/hook.js';
import {getRefererInfo} from '../src/refererDetection.js';
import {getStorageManager} from '../src/storageManager.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 = 'id5Id';
Expand Down Expand Up @@ -118,7 +118,7 @@ export const id5IdSubmodule = {
}

const resp = function (cbFunction) {
new IdFetchFlow(submoduleConfig, consentData, cacheIdObj, uspDataHandler.getConsentData()).execute()
new IdFetchFlow(submoduleConfig, consentData, cacheIdObj, uspDataHandler.getConsentData(), gppDataHandler.getConsentData()).execute()
.then(response => {
cbFunction(response)
})
Expand Down Expand Up @@ -170,11 +170,12 @@ export const id5IdSubmodule = {
};

class IdFetchFlow {
constructor(submoduleConfig, gdprConsentData, cacheIdObj, usPrivacyData) {
constructor(submoduleConfig, gdprConsentData, cacheIdObj, usPrivacyData, gppData) {
this.submoduleConfig = submoduleConfig
this.gdprConsentData = gdprConsentData
this.cacheIdObj = cacheIdObj
this.usPrivacyData = usPrivacyData
this.gppData = gppData
}

execute() {
Expand Down Expand Up @@ -285,6 +286,11 @@ class IdFetchFlow {
if (this.usPrivacyData !== undefined && !isEmpty(this.usPrivacyData) && !isEmptyStr(this.usPrivacyData)) {
data.us_privacy = this.usPrivacyData;
}
if (this.gppData) {
data.gpp_string = this.gppData.gppString;
data.gpp_sid = this.gppData.applicableSections;
}

if (signature !== undefined && !isEmptyStr(signature)) {
data.s = signature;
}
Expand Down
24 changes: 23 additions & 1 deletion test/spec/modules/id5IdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {config} from 'src/config.js';
import * as events from 'src/events.js';
import CONSTANTS from 'src/constants.json';
import * as utils from 'src/utils.js';
import {uspDataHandler} from 'src/adapterManager.js';
import {uspDataHandler, gppDataHandler} from 'src/adapterManager.js';
import 'src/prebid.js';
import {hook} from '../../../src/hook.js';
import {mockGdprConsent} from '../../helpers/consentData.js';
Expand Down Expand Up @@ -259,12 +259,14 @@ describe('ID5 ID System', function () {

describe('Xhr Requests from getId()', function () {
const responseHeader = HEADERS_CONTENT_TYPE_JSON
let gppStub

beforeEach(function () {
});

afterEach(function () {
uspDataHandler.reset()
gppStub?.restore()
});

it('should call the ID5 server and handle a valid response', function () {
Expand Down Expand Up @@ -730,6 +732,26 @@ describe('ID5 ID System', function () {
});
});

it('should pass gpp_string and gpp_sid to ID5 server', function () {
let xhrServerMock = new XhrServerMock(server)
gppStub = sinon.stub(gppDataHandler, 'getConsentData');
gppStub.returns({
ready: true,
gppString: 'GPP_STRING',
applicableSections: [2]
});
let submoduleResponse = callSubmoduleGetId(getId5FetchConfig(), undefined, ID5_STORED_OBJ);

return xhrServerMock.expectFetchRequest()
.then(fetchRequest => {
let requestBody = JSON.parse(fetchRequest.requestBody);
expect(requestBody.gpp_string).is.equal('GPP_STRING');
expect(requestBody.gpp_sid).contains(2);
fetchRequest.respond(200, responseHeader, JSON.stringify(ID5_JSON_RESPONSE));
return submoduleResponse
});
});

describe('when legacy cookies are set', () => {
let sandbox;
beforeEach(() => {
Expand Down

0 comments on commit 532970b

Please sign in to comment.