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..0dca6750a 100644 --- a/apps/github-pages/src/components/CmpTest.svelte +++ b/apps/github-pages/src/components/CmpTest.svelte @@ -3,6 +3,11 @@ import { cmp, onConsentChange, log } from '@guardian/libs'; import { onMount } from 'svelte'; + + let subscribed = window.location.search.includes('subscribed'); + let isFeatureFlagEnabled = window.location.search.includes('CMP_COP'); + // localStorage.setItem('subscribed', window.location.search.includes('subscribed')); + switch (window.location.hash) { case '#tcfv2': localStorage.setItem('framework', JSON.stringify('tcfv2')); @@ -37,6 +42,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 +72,23 @@ clearPreferences(); }; + const toggleSubscribed = () => { + subscribed = !subscribed; + toggleQueryParams('subscribed'); + localStorage.setItem('subscribed', JSON.stringify(subscribed)); + }; + + 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 toggleIsFeatureFlagEnabled = () => { + isFeatureFlagEnabled = !isFeatureFlagEnabled; + toggleQueryParams('CMP_COP'); + }; + $: consentState = {}; $: eventsList = []; @@ -91,10 +120,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, subscribed: subscribed ?? false }); }); @@ -104,6 +130,7 @@ >open privacy manager + + + +