diff --git a/.changeset/popular-trees-brake.md b/.changeset/popular-trees-brake.md new file mode 100644 index 000000000..6055bd4f4 --- /dev/null +++ b/.changeset/popular-trees-brake.md @@ -0,0 +1,5 @@ +--- +'@guardian/libs': minor +--- + +Test for Consent or Pay diff --git a/apps/github-pages/src/components/CmpTest.svelte b/apps/github-pages/src/components/CmpTest.svelte index 2186fce56..f28ca5a3d 100644 --- a/apps/github-pages/src/components/CmpTest.svelte +++ b/apps/github-pages/src/components/CmpTest.svelte @@ -3,6 +3,12 @@ import { cmp, onConsentChange, log } from '@guardian/libs'; import { onMount } from 'svelte'; + + let subscriber = window.location.search.includes('subscriber'); + let isFeatureFlagEnabled = window.location.search.includes('CMP_COP'); + let isMainSite = window.location.search.includes('CMP_MAIN'); + // localStorage.setItem('subscribed', window.location.search.includes('subscribed')); + switch (window.location.hash) { case '#tcfv2': localStorage.setItem('framework', JSON.stringify('tcfv2')); @@ -37,6 +43,13 @@ log('cmp', event); } + let rejectAllFunc = () => { + cmp.rejectAll().then(() => { + logEvent({ title: 'rejectAll'}); + // window.location.reload(); + }); + }; + let clearPreferences = () => { // clear local storage // https://documentation.sourcepoint.com/web-implementation/general/cookies-and-local-storage#cmp-local-storage @@ -60,6 +73,28 @@ clearPreferences(); }; + const toggleQueryParams = (param) => { + let queryParams = new URLSearchParams(window.location.search); + queryParams.has(param) ? queryParams.delete(param) : queryParams.append(param, ''); + window.location.search = queryParams.toString(); + }; + + const toggleSubscriber = () => { + subscribed = !subscribed; + toggleQueryParams('subscribed'); + localStorage.setItem('subscribed', JSON.stringify(subscribed)); + }; + + const toggleIsFeatureFlagEnabled = () => { + isFeatureFlagEnabled = !isFeatureFlagEnabled; + toggleQueryParams('CMP_COP'); + }; + + const toggleIsMainSite = () => { + isMainSite = !isMainSite; + toggleQueryParams('CMP_MAIN'); + }; + $: consentState = {}; $: eventsList = []; @@ -91,10 +126,7 @@ } // 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, subscriber: subscriber ?? false }); }); @@ -104,6 +136,7 @@ >open privacy manager + + + + + + +