From 9884b3852c23dfc81be5f46f8c89f11ddd8d6e32 Mon Sep 17 00:00:00 2001 From: Akinsola Lawanson <106528085+akinsola-guardian@users.noreply.github.com> Date: Wed, 13 Nov 2024 12:06:57 +0000 Subject: [PATCH 01/25] Update window.d.ts --- .../libs/src/consent-management-platform/types/window.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/@guardian/libs/src/consent-management-platform/types/window.d.ts b/libs/@guardian/libs/src/consent-management-platform/types/window.d.ts index 26d1c4d2a..d3dced10a 100644 --- a/libs/@guardian/libs/src/consent-management-platform/types/window.d.ts +++ b/libs/@guardian/libs/src/consent-management-platform/types/window.d.ts @@ -34,8 +34,10 @@ declare global { accountId: number; propertyHref?: Property; propertyId?: number; + campaignEnv: 'PROD' | 'STAGE'; targetingParams: { framework: ConsentFramework; + subscribed: boolean; }; ccpa?: { targetingParams?: { From fd5560894cc9c4ffb45ea100a23de25b49a7dc42 Mon Sep 17 00:00:00 2001 From: Akinsola Lawanson <106528085+akinsola-guardian@users.noreply.github.com> Date: Wed, 13 Nov 2024 12:07:19 +0000 Subject: [PATCH 02/25] Temporarily use property id --- .../libs/src/consent-management-platform/sourcepoint.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libs/@guardian/libs/src/consent-management-platform/sourcepoint.ts b/libs/@guardian/libs/src/consent-management-platform/sourcepoint.ts index 2f6a5f4c3..ee6977f92 100644 --- a/libs/@guardian/libs/src/consent-management-platform/sourcepoint.ts +++ b/libs/@guardian/libs/src/consent-management-platform/sourcepoint.ts @@ -36,7 +36,8 @@ const getPropertyId = (framework: ConsentFramework): number => { if (framework == 'aus') { return PROPERTY_ID_AUSTRALIA; } - return PROPERTY_ID; + return 9398; + // return PROPERTY_ID; }; export const init = (framework: ConsentFramework, pubData = {}): void => { @@ -80,10 +81,13 @@ export const init = (framework: ConsentFramework, pubData = {}): void => { config: { baseEndpoint: ENDPOINT, accountId: ACCOUNT_ID, - propertyHref: getPropertyHref(framework), + // propertyHref: getPropertyHref(framework), + propertyId: getPropertyId(framework), targetingParams: { framework, + subscribed: true, }, + campaignEnv: 'STAGE', pubData: { ...pubData, cmpInitTimeUtc: new Date().getTime() }, // ccpa or gdpr object added below From 794524232b9ff64a5559306ff0ae8d7ff666aa77 Mon Sep 17 00:00:00 2001 From: Akinsola Lawanson <106528085+akinsola-guardian@users.noreply.github.com> Date: Wed, 13 Nov 2024 12:10:27 +0000 Subject: [PATCH 03/25] Take in subscribed via init --- .../@guardian/libs/src/consent-management-platform/cmp.ts | 8 ++++++-- .../libs/src/consent-management-platform/sourcepoint.ts | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libs/@guardian/libs/src/consent-management-platform/cmp.ts b/libs/@guardian/libs/src/consent-management-platform/cmp.ts index 2b4faba55..869b022be 100644 --- a/libs/@guardian/libs/src/consent-management-platform/cmp.ts +++ b/libs/@guardian/libs/src/consent-management-platform/cmp.ts @@ -16,9 +16,13 @@ import type { WillShowPrivacyMessage, } from './types'; -const init = (framework: ConsentFramework, pubData?: PubData): void => { +const init = ( + framework: ConsentFramework, + subscribed: boolean, + pubData?: PubData, +): void => { mark('cmp-init'); - initSourcepoint(framework, pubData); + initSourcepoint(framework, subscribed, pubData); }; const willShowPrivacyMessage: WillShowPrivacyMessage = () => diff --git a/libs/@guardian/libs/src/consent-management-platform/sourcepoint.ts b/libs/@guardian/libs/src/consent-management-platform/sourcepoint.ts index ee6977f92..93a36bad0 100644 --- a/libs/@guardian/libs/src/consent-management-platform/sourcepoint.ts +++ b/libs/@guardian/libs/src/consent-management-platform/sourcepoint.ts @@ -40,7 +40,11 @@ const getPropertyId = (framework: ConsentFramework): number => { // return PROPERTY_ID; }; -export const init = (framework: ConsentFramework, pubData = {}): void => { +export const init = ( + framework: ConsentFramework, + subscribed: boolean, + pubData = {}, +): void => { stub(framework); // make sure nothing else on the page has accidentally @@ -85,7 +89,7 @@ export const init = (framework: ConsentFramework, pubData = {}): void => { propertyId: getPropertyId(framework), targetingParams: { framework, - subscribed: true, + subscribed, }, campaignEnv: 'STAGE', pubData: { ...pubData, cmpInitTimeUtc: new Date().getTime() }, From aea85d01daffc98791f1c2cb12f0a33ab5a25329 Mon Sep 17 00:00:00 2001 From: Akinsola Lawanson <106528085+akinsola-guardian@users.noreply.github.com> Date: Wed, 13 Nov 2024 12:27:20 +0000 Subject: [PATCH 04/25] Update test and reorder params --- .../src/consent-management-platform/cmp.ts | 2 +- .../consent-management-platform/index.test.ts | 22 +++++++++---------- .../src/consent-management-platform/index.ts | 4 ++-- .../lib/sourcepointConfig.ts | 3 ++- .../sourcepoint.ts | 21 +++++++++--------- .../types/index.ts | 7 +++++- 6 files changed, 32 insertions(+), 27 deletions(-) diff --git a/libs/@guardian/libs/src/consent-management-platform/cmp.ts b/libs/@guardian/libs/src/consent-management-platform/cmp.ts index 869b022be..99fb79905 100644 --- a/libs/@guardian/libs/src/consent-management-platform/cmp.ts +++ b/libs/@guardian/libs/src/consent-management-platform/cmp.ts @@ -22,7 +22,7 @@ const init = ( pubData?: PubData, ): void => { mark('cmp-init'); - initSourcepoint(framework, subscribed, pubData); + initSourcepoint(framework, pubData, subscribed); }; const willShowPrivacyMessage: WillShowPrivacyMessage = () => diff --git a/libs/@guardian/libs/src/consent-management-platform/index.test.ts b/libs/@guardian/libs/src/consent-management-platform/index.test.ts index 4b213e55d..9104a0523 100644 --- a/libs/@guardian/libs/src/consent-management-platform/index.test.ts +++ b/libs/@guardian/libs/src/consent-management-platform/index.test.ts @@ -23,8 +23,8 @@ describe('cmp.init', () => { it('does nothing if CMP is disabled', () => { disable(); - cmp.init({ country: 'GB' }); - cmp.init({ country: 'US' }); + cmp.init({ country: 'GB', subscribed: true }); + cmp.init({ country: 'US', subscribed: true }); expect(CMP.init).not.toHaveBeenCalled(); @@ -33,22 +33,22 @@ describe('cmp.init', () => { it('requires country to be set', () => { expect(() => { - cmp.init({ pubData: {} }); + cmp.init({ subscribed: true, pubData: {} }); }).toThrow('required'); }); it('initializes CMP when in the US', () => { - cmp.init({ country: 'US' }); + cmp.init({ country: 'US', subscribed: true }); expect(CMP.init).toHaveBeenCalledTimes(1); }); it('initializes CMP when in Australia', () => { - cmp.init({ country: 'AU' }); + cmp.init({ country: 'AU', subscribed: true }); expect(CMP.init).toHaveBeenCalledTimes(1); }); it('initializes TCF when neither in the US or Australia', () => { - cmp.init({ country: 'GB' }); + cmp.init({ country: 'GB', subscribed: true }); expect(CMP.init).toHaveBeenCalledTimes(1); }); }); @@ -56,10 +56,10 @@ describe('cmp.init', () => { // *************** START commercial.dcr.js hotfix *************** describe('hotfix cmp.init', () => { it('only initialises once per page', () => { - cmp.init({ country: 'GB' }); - cmp.init({ country: 'GB' }); - cmp.init({ country: 'GB' }); - cmp.init({ country: 'GB' }); + cmp.init({ country: 'GB', subscribed: true }); + cmp.init({ country: 'GB', subscribed: true }); + cmp.init({ country: 'GB', subscribed: true }); + cmp.init({ country: 'GB', subscribed: true }); expect(CMP.init).toHaveBeenCalledTimes(1); expect(window.guCmpHotFix.initialised).toBe(true); }); @@ -68,7 +68,7 @@ describe('hotfix cmp.init', () => { const consoleWarn = jest .spyOn(global.console, 'warn') .mockImplementation(() => undefined); - cmp.init({ country: 'GB' }); + cmp.init({ country: 'GB', subscribed: true }); const currentVersion = window.guCmpHotFix.cmp?.version; const mockedVersion = 'X.X.X-mock'; diff --git a/libs/@guardian/libs/src/consent-management-platform/index.ts b/libs/@guardian/libs/src/consent-management-platform/index.ts index bce0d8130..1e743e348 100644 --- a/libs/@guardian/libs/src/consent-management-platform/index.ts +++ b/libs/@guardian/libs/src/consent-management-platform/index.ts @@ -33,7 +33,7 @@ const initialised = new Promise((resolve) => { resolveInitialised = resolve; }); -const init: InitCMP = ({ pubData, country }) => { +const init: InitCMP = ({ pubData, country, subscribed = true }) => { if (isDisabled() || isServerSide) { return; } @@ -61,7 +61,7 @@ const init: InitCMP = ({ pubData, country }) => { const framework = getFramework(country); - UnifiedCMP.init(framework, pubData ?? {}); + UnifiedCMP.init(framework, subscribed, pubData ?? {}); void UnifiedCMP.willShowPrivacyMessage().then((willShowValue) => { _willShowPrivacyMessage = willShowValue; diff --git a/libs/@guardian/libs/src/consent-management-platform/lib/sourcepointConfig.ts b/libs/@guardian/libs/src/consent-management-platform/lib/sourcepointConfig.ts index 761e4acf8..72aba180e 100644 --- a/libs/@guardian/libs/src/consent-management-platform/lib/sourcepointConfig.ts +++ b/libs/@guardian/libs/src/consent-management-platform/lib/sourcepointConfig.ts @@ -2,7 +2,8 @@ import { isGuardianDomain } from './domain'; export const ACCOUNT_ID = 1257; export const PRIVACY_MANAGER_USNAT = 1068329; -export const PROPERTY_ID = 7417; +export const PROPERTY_ID = 9398; +// export const PROPERTY_ID = 7417; export const PROPERTY_ID_AUSTRALIA = 13348; export const PRIVACY_MANAGER_TCFV2 = 106842; export const PRIVACY_MANAGER_AUSTRALIA = 1178486; diff --git a/libs/@guardian/libs/src/consent-management-platform/sourcepoint.ts b/libs/@guardian/libs/src/consent-management-platform/sourcepoint.ts index 93a36bad0..464003e8d 100644 --- a/libs/@guardian/libs/src/consent-management-platform/sourcepoint.ts +++ b/libs/@guardian/libs/src/consent-management-platform/sourcepoint.ts @@ -1,8 +1,8 @@ import { log } from '../logger/logger'; import { setCurrentFramework } from './getCurrentFramework'; -import { isGuardianDomain } from './lib/domain'; +// import { isGuardianDomain } from './lib/domain'; import { mark } from './lib/mark'; -import type { Property } from './lib/property'; +// import type { Property } from './lib/property'; import { ACCOUNT_ID, ENDPOINT, @@ -25,25 +25,24 @@ export const willShowPrivacyMessage = new Promise((resolve) => { * Australia has a single property while the rest of the world has a test and prod property. * TODO: incorporate au.theguardian into *.theguardian.com */ -const getPropertyHref = (framework: ConsentFramework): Property => { - if (framework == 'aus') { - return 'https://au.theguardian.com'; - } - return isGuardianDomain() ? null : 'https://test.theguardian.com'; -}; +// const getPropertyHref = (framework: ConsentFramework): Property => { +// if (framework == 'aus') { +// return 'https://au.theguardian.com'; +// } +// return isGuardianDomain() ? null : 'https://test.theguardian.com'; +// }; const getPropertyId = (framework: ConsentFramework): number => { if (framework == 'aus') { return PROPERTY_ID_AUSTRALIA; } - return 9398; - // return PROPERTY_ID; + return PROPERTY_ID; }; export const init = ( framework: ConsentFramework, - subscribed: boolean, pubData = {}, + subscribed: boolean, ): void => { stub(framework); diff --git a/libs/@guardian/libs/src/consent-management-platform/types/index.ts b/libs/@guardian/libs/src/consent-management-platform/types/index.ts index 0b5bbb11c..cb892f203 100644 --- a/libs/@guardian/libs/src/consent-management-platform/types/index.ts +++ b/libs/@guardian/libs/src/consent-management-platform/types/index.ts @@ -21,6 +21,7 @@ export type CMP = { export type InitCMP = (arg0: { pubData?: PubData; country?: CountryCode; + subscribed?: boolean; }) => void; export type OnConsentChange = ( @@ -46,7 +47,11 @@ export interface PubData { [propName: string]: unknown; } export interface SourcepointImplementation { - init: (framework: ConsentFramework, pubData?: PubData) => void; + init: ( + framework: ConsentFramework, + subscribed: boolean, + pubData?: PubData, + ) => void; willShowPrivacyMessage: WillShowPrivacyMessage; showPrivacyManager: () => void; } From b757471ea14aebc734bff50c95583e0c33b232f9 Mon Sep 17 00:00:00 2001 From: Akinsola Lawanson <106528085+akinsola-guardian@users.noreply.github.com> Date: Wed, 13 Nov 2024 15:23:47 +0000 Subject: [PATCH 05/25] Updated campaignEnv --- .../src/consent-management-platform/index.ts | 2 +- .../sourcepoint.ts | 24 ++++++++++--------- .../types/window.d.ts | 3 ++- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/libs/@guardian/libs/src/consent-management-platform/index.ts b/libs/@guardian/libs/src/consent-management-platform/index.ts index 1e743e348..079d0cd2a 100644 --- a/libs/@guardian/libs/src/consent-management-platform/index.ts +++ b/libs/@guardian/libs/src/consent-management-platform/index.ts @@ -33,7 +33,7 @@ const initialised = new Promise((resolve) => { resolveInitialised = resolve; }); -const init: InitCMP = ({ pubData, country, subscribed = true }) => { +const init: InitCMP = ({ pubData, country, subscribed = false }) => { if (isDisabled() || isServerSide) { return; } diff --git a/libs/@guardian/libs/src/consent-management-platform/sourcepoint.ts b/libs/@guardian/libs/src/consent-management-platform/sourcepoint.ts index 464003e8d..112046ac6 100644 --- a/libs/@guardian/libs/src/consent-management-platform/sourcepoint.ts +++ b/libs/@guardian/libs/src/consent-management-platform/sourcepoint.ts @@ -1,8 +1,8 @@ import { log } from '../logger/logger'; import { setCurrentFramework } from './getCurrentFramework'; -// import { isGuardianDomain } from './lib/domain'; +import { isGuardianDomain } from './lib/domain'; import { mark } from './lib/mark'; -// import type { Property } from './lib/property'; +import type { Property } from './lib/property'; import { ACCOUNT_ID, ENDPOINT, @@ -25,12 +25,13 @@ export const willShowPrivacyMessage = new Promise((resolve) => { * Australia has a single property while the rest of the world has a test and prod property. * TODO: incorporate au.theguardian into *.theguardian.com */ -// const getPropertyHref = (framework: ConsentFramework): Property => { -// if (framework == 'aus') { -// return 'https://au.theguardian.com'; -// } -// return isGuardianDomain() ? null : 'https://test.theguardian.com'; -// }; +const getPropertyHref = (framework: ConsentFramework): Property => { + if (framework == 'aus') { + return 'https://au.theguardian.com'; + } + // return isGuardianDomain() ? null : 'https://test.theguardian.com'; + return isGuardianDomain() ? null : 'http://ui-dev'; +}; const getPropertyId = (framework: ConsentFramework): number => { if (framework == 'aus') { @@ -84,13 +85,13 @@ export const init = ( config: { baseEndpoint: ENDPOINT, accountId: ACCOUNT_ID, - // propertyHref: getPropertyHref(framework), + propertyHref: getPropertyHref(framework), propertyId: getPropertyId(framework), targetingParams: { - framework, + framework: 'aus', subscribed, }, - campaignEnv: 'STAGE', + campaignEnv: 'stage', pubData: { ...pubData, cmpInitTimeUtc: new Date().getTime() }, // ccpa or gdpr object added below @@ -204,6 +205,7 @@ export const init = ( window._sp_.config.gdpr = { targetingParams: { framework, + subscribed, }, }; break; diff --git a/libs/@guardian/libs/src/consent-management-platform/types/window.d.ts b/libs/@guardian/libs/src/consent-management-platform/types/window.d.ts index d3dced10a..124e53486 100644 --- a/libs/@guardian/libs/src/consent-management-platform/types/window.d.ts +++ b/libs/@guardian/libs/src/consent-management-platform/types/window.d.ts @@ -34,7 +34,7 @@ declare global { accountId: number; propertyHref?: Property; propertyId?: number; - campaignEnv: 'PROD' | 'STAGE'; + campaignEnv: 'prod' | 'stage'; targetingParams: { framework: ConsentFramework; subscribed: boolean; @@ -47,6 +47,7 @@ declare global { gdpr?: { targetingParams?: { framework: ConsentFramework; + subscribed: boolean; }; }; usnat?: { From d354339790e210b1bbf6ecf638492d508520811e Mon Sep 17 00:00:00 2001 From: Akinsola Lawanson <106528085+akinsola-guardian@users.noreply.github.com> Date: Thu, 21 Nov 2024 12:37:29 +0000 Subject: [PATCH 06/25] Add subscribed value to test page --- .../src/components/CmpTest.svelte | 27 ++++++++++++++++--- .../src/consent-management-platform/index.ts | 2 +- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/apps/github-pages/src/components/CmpTest.svelte b/apps/github-pages/src/components/CmpTest.svelte index 2186fce56..ead6255ee 100644 --- a/apps/github-pages/src/components/CmpTest.svelte +++ b/apps/github-pages/src/components/CmpTest.svelte @@ -3,6 +3,10 @@ import { cmp, onConsentChange, log } from '@guardian/libs'; import { onMount } from 'svelte'; + + let subscribed = window.location.search.includes('subscribed'); + // localStorage.setItem('subscribed', window.location.search.includes('subscribed')); + switch (window.location.hash) { case '#tcfv2': localStorage.setItem('framework', JSON.stringify('tcfv2')); @@ -53,6 +57,7 @@ }; let framework = JSON.parse(localStorage.getItem('framework')); + // let subscribed = JSON.parse(localStorage.getItem('subscribed')); let setLocation = () => { localStorage.setItem('framework', JSON.stringify(framework)); @@ -60,6 +65,12 @@ clearPreferences(); }; + let toggleSubscribed = () => { + subscribed = !subscribed; + window.location.search = subscribed ? 'subscribed' : ''; + localStorage.setItem('subscribed', JSON.stringify(subscribed)); + }; + $: consentState = {}; $: eventsList = []; @@ -91,10 +102,10 @@ } // do this loads to make sure that doesn't break things - cmp.init({ country }); - cmp.init({ country }); - cmp.init({ country }); - cmp.init({ country }); + cmp.init({ country, subscribed: subscribed ?? false }); + // cmp.init({ country, subscribed: subscribed ?? false }); + // cmp.init({ country, subscribed: subscribed ?? false }); + // cmp.init({ country, subscribed: subscribed ?? false }); }); @@ -133,6 +144,14 @@ in Australia: CCPA-like +