Skip to content

Commit

Permalink
Add toggle for main site/support
Browse files Browse the repository at this point in the history
  • Loading branch information
akinsola-guardian committed Jan 9, 2025
1 parent f41fb85 commit 59c2dbf
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 15 deletions.
30 changes: 23 additions & 7 deletions apps/github-pages/src/components/CmpTest.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
let subscriber = window.location.search.includes('subscriber');
let isFeatureFlagEnabled = window.location.search.includes('CMP_COP');
// localStorage.setItem('subscriber', window.location.search.includes('subscriber'));
let isMainSite = window.location.search.includes('CMP_MAIN');
// localStorage.setItem('subscribed', window.location.search.includes('subscribed'));
switch (window.location.hash) {
case '#tcfv2':
Expand Down Expand Up @@ -72,23 +73,28 @@
clearPreferences();
};
const toggleSubscriber = () => {
subscriber = !subscriber;
toggleQueryParams('subscriber');
localStorage.setItem('subscriber', JSON.stringify(subscriber));
};
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 = [];
Expand Down Expand Up @@ -160,6 +166,16 @@
in Australia:
<strong>CCPA-like</strong>
</label>
<label class={isMainSite ? 'selected' : 'none'}>
<input
type="checkbox"
on:change={toggleIsMainSite}
checked={isMainSite}
/>
<strong>Is main site?</strong>
</label>
<label class={subscriber ? 'selected' : 'none'}>
<input
type="checkbox"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { isGuardianDomain } from './domain';

export const ACCOUNT_ID = 1257;
export const PRIVACY_MANAGER_USNAT = 1068329;
export const PROPERTY_ID = 9398;
// export const PROPERTY_ID = 7417;
export const PROPERTY_ID_MAIN = 9398;
export const PROPERTY_ID_SUPPORT = 38161;
// export const PROPERTY_ID_MAIN = 7417;
export const PROPERTY_ID_AUSTRALIA = 13348;
export const PRIVACY_MANAGER_TCFV2 = 106842;
export const PRIVACY_MANAGER_AUSTRALIA = 1178486;
Expand Down
28 changes: 22 additions & 6 deletions libs/@guardian/libs/src/consent-management-platform/sourcepoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import type { Property } from './lib/property';
import {
ACCOUNT_ID,
ENDPOINT,
PROPERTY_ID,
PROPERTY_ID_AUSTRALIA,
PROPERTY_ID_MAIN,
PROPERTY_ID_SUPPORT,
SourcePointChoiceTypes,
} from './lib/sourcepointConfig';
import { invokeCallbacks } from './onConsentChange';
Expand All @@ -26,19 +27,33 @@ export const willShowPrivacyMessage = new Promise<boolean>((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 => {
const getPropertyHref = (
framework: ConsentFramework,
isMainSite: boolean = true,
): Property => {
if (framework == 'aus') {
return 'https://au.theguardian.com';
}
// return isGuardianDomain() ? null : 'https://test.theguardian.com';
return isGuardianDomain() ? null : 'http://ui-dev';
// return isGuardianDomain() ? null : 'http://ui-dev';
return isGuardianDomain()
? null
: isMainSite
? 'http://ui-dev'
: 'http://support-test';
};

const getPropertyId = (framework: ConsentFramework): number => {
const getPropertyId = (
framework: ConsentFramework,
isMainSite: boolean = true,
): number => {
if (framework == 'aus') {
return PROPERTY_ID_AUSTRALIA;
}
return PROPERTY_ID;
if (framework == 'usnat') {
return PROPERTY_ID_MAIN;
}
return isMainSite ? PROPERTY_ID_MAIN : PROPERTY_ID_SUPPORT;
};

export const init = (
Expand Down Expand Up @@ -78,6 +93,7 @@ export const init = (
'variant';

const isFeatureFlagEnabled = window.location.search.includes('CMP_COP');
const isMainSite = window.location.search.includes('CMP_MAIN');

log('cmp', `framework: ${framework}`);
log('cmp', `frameworkMessageType: ${frameworkMessageType}`);
Expand All @@ -88,8 +104,8 @@ export const init = (
config: {
baseEndpoint: ENDPOINT,
accountId: ACCOUNT_ID,
propertyHref: getPropertyHref(framework),
propertyId: getPropertyId(framework),
propertyHref: getPropertyHref(framework, isMainSite),
targetingParams: {
framework,
},
Expand Down

0 comments on commit 59c2dbf

Please sign in to comment.