Skip to content
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

PBID-14: Support US Privacy Framework #7

Merged
merged 3 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 9 additions & 3 deletions modules/parrableIdSystem.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 { ajax } from '../src/ajax.js';
import { submodule } from '../src/hook.js';
import { getRefererInfo } from '../src/refererDetection.js';
import { uspDataHandler } from '../src/adapterManager.js';

const PARRABLE_URL = 'https://h.parrable.com/prebid';

Expand All @@ -24,10 +25,11 @@ function isValidConfig(configParams) {
return true;
}

function fetchId(configParams, consentData, currentStoredId) {
function fetchId(configParams, currentStoredId) {
if (!isValidConfig(configParams)) return;

const refererInfo = getRefererInfo();
const uspString = uspDataHandler.getConsentData();

const data = {
eid: currentStoredId || null,
Expand All @@ -40,6 +42,10 @@ function fetchId(configParams, consentData, currentStoredId) {
_rand: Math.random()
};

if (uspString) {
searchParams.us_privacy = uspString;
}

const options = {
method: 'GET',
withCredentials: true
Expand Down Expand Up @@ -88,8 +94,8 @@ export const parrableIdSubmodule = {
* @param {ConsentData} [consentData]
* @returns {function(callback:function)}
*/
getId(configParams, consentData, currentStoredId) {
return fetchId(configParams, consentData, currentStoredId);
getId(configParams, gdprConsentData, currentStoredId) {
return fetchId(configParams, currentStoredId);
}
};

Expand Down
45 changes: 30 additions & 15 deletions test/spec/modules/parrableIdSystem_spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { expect } from 'chai';
import { config } from 'src/config.js';
import * as utils from 'src/utils.js';
import { init, requestBidsHook, setSubmoduleRegistry } from 'modules/userId/index.js';
import { parrableIdSubmodule } from 'modules/parrableIdSystem.js';
import { newStorageManager } from 'src/storageManager.js';
import { getRefererInfo } from 'src/refererDetection.js';

import { uspDataHandler } from 'src/adapterManager.js';
import { init, requestBidsHook, setSubmoduleRegistry } from 'modules/userId/index.js';
import { parrableIdSubmodule } from 'modules/parrableIdSystem.js';
import { server } from 'test/mocks/xhr';

const storage = newStorageManager();
Expand Down Expand Up @@ -52,45 +52,60 @@ describe('Parrable ID System', function() {
}

describe('parrableIdSystem.getId()', function() {
let submoduleCallback;
let callbackSpy = sinon.spy();

beforeEach(function() {
submoduleCallback = parrableIdSubmodule.getId(
callbackSpy.resetHistory();
});

it('returns a callback used to refresh the ID', function() {
let getIdResponse = parrableIdSubmodule.getId(
P_CONFIG_MOCK.params,
null,
P_COOKIE_EID
).callback;
callbackSpy.reset();
);
expect(getIdResponse.callback).to.be.a('function');
});

it('returns a callback used to refresh the ID', function() {
expect(submoduleCallback).to.be.a('function');
});
it('callback creates xhr to Parrable that synchronizes the ID', function() {
let getIdCallback = parrableIdSubmodule.getId(
P_CONFIG_MOCK.params,
null,
P_COOKIE_EID
).callback;

it('invoked callback creates an xhr request to Parrable with id and telemetry', function() {
submoduleCallback(callbackSpy);
getIdCallback(callbackSpy);

let request = server.requests[0];
let queryParams = utils.parseQS(request.url.split('?')[1]);
let data = JSON.parse(atob(queryParams.data));

expect(request.url).to.contain('h.parrable.com/prebid');
expect(queryParams).to.not.have.property('us_privacy');
expect(data).to.deep.equal({
eid: P_COOKIE_EID,
trackers: P_CONFIG_MOCK.params.partner.split(','),
url: getRefererInfo().referer
});
});

it('callback responds with updated eid from Parrable backend', function() {
submoduleCallback(callbackSpy);
server.requests[0].respond(200,
{ 'Content-Type': 'text/plain' },
JSON.stringify({ eid: P_XHR_EID })
);

expect(callbackSpy.calledWith(P_XHR_EID)).to.be.true;
});

it('passes the uspString to Parrable', function() {
let uspString = '1YNN';
uspDataHandler.setConsentData(uspString);
parrableIdSubmodule.getId(
P_CONFIG_MOCK.params,
null,
P_COOKIE_EID
).callback(callbackSpy);
expect(server.requests[0].url).to.contain('us_privacy=' + uspString);
});
});

describe('Parrable ID in Bid Request', function() {
Expand Down