Skip to content

Commit

Permalink
[IdentityLinkIdSystem] - pass tcfv2 consent string to envelope api (#…
Browse files Browse the repository at this point in the history
…5634)

* [IdentityLinkIdSystem] - pass tcfv2 consent string to envelope api

* [IdentityLinkIdSystem] - used deepAccess
  • Loading branch information
NemanjaRajkovic9 authored Aug 24, 2020
1 parent 29bd8de commit b26bfe3
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
22 changes: 16 additions & 6 deletions modules/identityLinkIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

import * as utils from '../src/utils.js'
import {ajax} from '../src/ajax.js';
import {submodule} from '../src/hook.js';
import { ajax } from '../src/ajax.js';
import { submodule } from '../src/hook.js';

/** @type {Submodule} */
export const identityLinkSubmodule = {
Expand All @@ -16,6 +16,11 @@ export const identityLinkSubmodule = {
* @type {string}
*/
name: 'identityLink',
/**
* used to specify vendor id
* @type {number}
*/
gvlid: 97,
/**
* decode the stored id value for passing to bid requests
* @function
Expand All @@ -39,10 +44,15 @@ export const identityLinkSubmodule = {
}
const hasGdpr = (consentData && typeof consentData.gdprApplies === 'boolean' && consentData.gdprApplies) ? 1 : 0;
const gdprConsentString = hasGdpr ? consentData.consentString : '';
const tcfPolicyV2 = utils.deepAccess(consentData, 'vendorData.tcfPolicyVersion') === 2;
// use protocol relative urls for http or https
const url = `https://api.rlcdn.com/api/identity/envelope?pid=${configParams.pid}${hasGdpr ? '&ct=1&cv=' + gdprConsentString : ''}`;
if (hasGdpr && (!gdprConsentString || gdprConsentString === '')) {
utils.logInfo('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 : ''}`;
let resp;
resp = function(callback) {
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) {
Expand All @@ -60,7 +70,7 @@ export const identityLinkSubmodule = {
}
};

return {callback: resp};
return { callback: resp };
}
};
// return envelope from third party endpoint
Expand All @@ -83,7 +93,7 @@ function getEnvelope(url, callback) {
callback();
}
};
ajax(url, callbacks, undefined, {method: 'GET', withCredentials: true});
ajax(url, callbacks, undefined, { method: 'GET', withCredentials: true });
}

submodule('userId', identityLinkSubmodule);
38 changes: 37 additions & 1 deletion test/spec/modules/identityLinkIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,22 @@ describe('IdentityLinkId tests', function () {
expect(callBackSpy.calledOnce).to.be.true;
});

it('should call the LiveRamp envelope endpoint with consent string', function () {
it('should NOT call the LiveRamp envelope endpoint if gdpr applies but consent string is empty string', function () {
let consentData = {
gdprApplies: true,
consentString: ''
};
let submoduleCallback = identityLinkSubmodule.getId(defaultConfigParams, consentData);
expect(submoduleCallback).to.be.undefined;
});

it('should NOT call the LiveRamp envelope endpoint if gdpr applies but consent string is missing', function () {
let consentData = { gdprApplies: true };
let submoduleCallback = identityLinkSubmodule.getId(defaultConfigParams, consentData);
expect(submoduleCallback).to.be.undefined;
});

it('should call the LiveRamp envelope endpoint with IAB consent string v1', function () {
let callBackSpy = sinon.spy();
let consentData = {
gdprApplies: true,
Expand All @@ -59,6 +74,27 @@ describe('IdentityLinkId tests', function () {
expect(callBackSpy.calledOnce).to.be.true;
});

it('should call the LiveRamp envelope endpoint with IAB consent string v2', function () {
let callBackSpy = sinon.spy();
let consentData = {
gdprApplies: true,
consentString: 'CO4VThZO4VTiuADABBENAzCgAP_AAEOAAAAAAwwAgAEABhAAgAgAAA.YAAAAAAAAAA',
vendorData: {
tcfPolicyVersion: 2
}
};
let submoduleCallback = identityLinkSubmodule.getId(defaultConfigParams, consentData).callback;
submoduleCallback(callBackSpy);
let request = server.requests[0];
expect(request.url).to.be.eq('https://api.rlcdn.com/api/identity/envelope?pid=14&ct=4&cv=CO4VThZO4VTiuADABBENAzCgAP_AAEOAAAAAAwwAgAEABhAAgAgAAA.YAAAAAAAAAA');
request.respond(
200,
responseHeader,
JSON.stringify({})
);
expect(callBackSpy.calledOnce).to.be.true;
});

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 b26bfe3

Please sign in to comment.