Skip to content

Commit

Permalink
ConnectID: Support new easy-opt out method (#9069)
Browse files Browse the repository at this point in the history
* Respect custom opt-out override localstorage key.

* Wrap opt-out check in a function.

* Rename function

* Add unit tests

Co-authored-by: slimkrazy <[email protected]>
  • Loading branch information
slimkrazy and slimkrazy authored Oct 11, 2022
1 parent 7287486 commit 958acae
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
17 changes: 16 additions & 1 deletion modules/connectIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,27 @@

import {ajax} from '../src/ajax.js';
import {submodule} from '../src/hook.js';
import {formatQS, logError} from '../src/utils.js';
import {includes} from '../src/polyfill.js';
import {formatQS, logError} from '../src/utils.js';

const MODULE_NAME = 'connectId';
const VENDOR_ID = 25;
const PLACEHOLDER = '__PIXEL_ID__';
const UPS_ENDPOINT = `https://ups.analytics.yahoo.com/ups/${PLACEHOLDER}/fed`;
const OVERRIDE_OPT_OUT_KEY = 'connectIdOptOut';

function isEUConsentRequired(consentData) {
return !!(consentData && consentData.gdpr && consentData.gdpr.gdprApplies);
}

function userHasOptedOut() {
try {
return localStorage.getItem(OVERRIDE_OPT_OUT_KEY) === '1';
} catch {
return false;
}
}

/** @type {Submodule} */
export const connectIdSubmodule = {
/**
Expand All @@ -36,6 +45,9 @@ export const connectIdSubmodule = {
* @returns {{connectId: string} | undefined}
*/
decode(value) {
if (userHasOptedOut()) {
return undefined;
}
return (typeof value === 'object' && value.connectid)
? {connectId: value.connectid} : undefined;
},
Expand All @@ -47,6 +59,9 @@ export const connectIdSubmodule = {
* @returns {IdResponse|undefined}
*/
getId(config, consentData) {
if (userHasOptedOut()) {
return;
}
const params = config.params || {};
if (!params || typeof params.he !== 'string' ||
(typeof params.pixelId === 'undefined' && typeof params.endpoint === 'undefined')) {
Expand Down
20 changes: 20 additions & 0 deletions test/spec/modules/connectIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,26 @@ describe('Yahoo ConnectID Submodule', () => {
expect(result.callback).to.be.a('function');
});

it('returns an undefined if the Yahoo specific opt-out key is present in local storage', () => {
localStorage.setItem('connectIdOptOut', '1');
expect(invokeGetIdAPI({
he: HASHED_EMAIL,
pixelId: PIXEL_ID
}, consentData)).to.be.undefined;
localStorage.removeItem('connectIdOptOut');
});

it('returns an object with the callback function if the correct params are passed and Yahoo opt-out value is not "1"', () => {
localStorage.setItem('connectIdOptOut', 'true');
let result = invokeGetIdAPI({
he: HASHED_EMAIL,
pixelId: PIXEL_ID
}, consentData);
expect(result).to.be.an('object').that.has.all.keys('callback');
expect(result.callback).to.be.a('function');
localStorage.removeItem('connectIdOptOut');
});

it('Makes an ajax GET request to the production API endpoint with query params', () => {
invokeGetIdAPI({
he: HASHED_EMAIL,
Expand Down

0 comments on commit 958acae

Please sign in to comment.