Skip to content

Commit

Permalink
identityLinkIdSystem: include gpp in 3p envelope retrieval (#10745)
Browse files Browse the repository at this point in the history
* identityLinkIdSystem - liveramp - include gpp in 3p envelope retrieval

* identityLinkIdSystem - liveramp - adjust test description
  • Loading branch information
mamatic authored Nov 27, 2023
1 parent 1205d53 commit 656680b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
9 changes: 7 additions & 2 deletions modules/identityLinkIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ajax } from '../src/ajax.js';
import { submodule } from '../src/hook.js';
import {getStorageManager} from '../src/storageManager.js';
import {MODULE_TYPE_UID} from '../src/activities/modules.js';
import { gppDataHandler } from '../src/adapterManager.js';

const MODULE_NAME = 'identityLink';

Expand Down Expand Up @@ -59,12 +60,16 @@ export const identityLinkSubmodule = {
utils.logInfo('identityLink: Consent string is required to call envelope API.');
return;
}
const url = `https://api.rlcdn.com/api/identity/envelope?pid=${configParams.pid}${hasGdpr ? (tcfPolicyV2 ? '&ct=4&cv=' : '&ct=1&cv=') + gdprConsentString : ''}`;
const gppData = gppDataHandler.getConsentData();
const gppString = gppData && gppData.gppString ? gppData.gppString : false;
const gppSectionId = gppData && gppData.gppString && gppData.applicableSections.length > 0 && gppData.applicableSections[0] !== -1 ? gppData.applicableSections[0] : false;
const hasGpp = gppString && gppSectionId;
const url = `https://api.rlcdn.com/api/identity/envelope?pid=${configParams.pid}${hasGdpr ? (tcfPolicyV2 ? '&ct=4&cv=' : '&ct=1&cv=') + gdprConsentString : ''}${hasGpp ? '&gpp=' + gppString + '&gpp_sid=' + gppSectionId : ''}`;
let resp;
resp = function (callback) {
// Check ats during callback so it has a chance to initialise.
// If ats library is available, use it to retrieve envelope. If not use standard third party endpoint
if (window.ats) {
if (window.ats && window.ats.retrieveEnvelope) {
utils.logInfo('identityLink: ATS exists!');
window.ats.retrieveEnvelope(function (envelope) {
if (envelope) {
Expand Down
44 changes: 44 additions & 0 deletions test/spec/modules/identityLinkIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as utils from 'src/utils.js';
import {server} from 'test/mocks/xhr.js';
import {getCoreStorageManager} from '../../../src/storageManager.js';
import {stub} from 'sinon';
import { gppDataHandler } from '../../../src/adapterManager.js';

const storage = getCoreStorageManager();

Expand All @@ -20,6 +21,7 @@ function setTestEnvelopeCookie () {

describe('IdentityLinkId tests', function () {
let logErrorStub;
let gppConsentDataStub;

beforeEach(function () {
defaultConfigParams = { params: {pid: pid} };
Expand Down Expand Up @@ -112,6 +114,48 @@ describe('IdentityLinkId tests', function () {
expect(callBackSpy.calledOnce).to.be.true;
});

it('should call the LiveRamp envelope endpoint with GPP consent string', function() {
gppConsentDataStub = sinon.stub(gppDataHandler, 'getConsentData');
gppConsentDataStub.returns({
ready: true,
gppString: 'DBABLA~BVVqAAAACqA.QA',
applicableSections: [7]
});
let callBackSpy = sinon.spy();
let submoduleCallback = identityLinkSubmodule.getId(defaultConfigParams).callback;
submoduleCallback(callBackSpy);
let request = server.requests[0];
expect(request.url).to.be.eq('https://api.rlcdn.com/api/identity/envelope?pid=14&gpp=DBABLA~BVVqAAAACqA.QA&gpp_sid=7');
request.respond(
200,
responseHeader,
JSON.stringify({})
);
expect(callBackSpy.calledOnce).to.be.true;
gppConsentDataStub.restore();
});

it('should call the LiveRamp envelope endpoint without GPP consent string if consent string is not provided', function () {
gppConsentDataStub = sinon.stub(gppDataHandler, 'getConsentData');
gppConsentDataStub.returns({
ready: true,
gppString: '',
applicableSections: [7]
});
let callBackSpy = sinon.spy();
let submoduleCallback = identityLinkSubmodule.getId(defaultConfigParams).callback;
submoduleCallback(callBackSpy);
let request = server.requests[0];
expect(request.url).to.be.eq('https://api.rlcdn.com/api/identity/envelope?pid=14');
request.respond(
200,
responseHeader,
JSON.stringify({})
);
expect(callBackSpy.calledOnce).to.be.true;
gppConsentDataStub.restore();
});

it('should not throw Uncaught TypeError when envelope endpoint returns empty response', function () {
let callBackSpy = sinon.spy();
let submoduleCallback = identityLinkSubmodule.getId(defaultConfigParams).callback;
Expand Down

0 comments on commit 656680b

Please sign in to comment.