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

ConnectID: Support new easy-opt out method #9069

Merged
Merged
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
17 changes: 16 additions & 1 deletion modules/connectIdSystem.js
Original file line number Diff line number Diff line change
@@ -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 = {
/**
@@ -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;
},
@@ -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')) {
20 changes: 20 additions & 0 deletions test/spec/modules/connectIdSystem_spec.js
Original file line number Diff line number Diff line change
@@ -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,