Skip to content

Commit 0d0f21c

Browse files
Enable consent or pay banner (#13199)
* beta libs * new cmp params * reuse function * use correct benefit * Refactor AuthStatus type * playwright fix * disable sign-in check * remove allowRejectAll * no extra params * add params back * disableCMP * remove disableCMP, debug * more debug * increase timeout * undo timeout * increase timeouts, correct logic * fix reject all in tests * remove logs * back to 2 second timeout * fix allowRejectAll call * v21.1.0 * Update pnpm-lock.yaml --------- Co-authored-by: Akinsola Lawanson <[email protected]>
1 parent a5e5f5d commit 0d0f21c

File tree

9 files changed

+68
-42
lines changed

9 files changed

+68
-42
lines changed

dotcom-rendering/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"@guardian/eslint-config-typescript": "9.0.1",
4848
"@guardian/identity-auth": "6.0.1",
4949
"@guardian/identity-auth-frontend": "8.1.0",
50-
"@guardian/libs": "20.0.0",
50+
"@guardian/libs": "21.1.0",
5151
"@guardian/ophan-tracker-js": "2.2.5",
5252
"@guardian/react-crossword": "2.0.2",
5353
"@guardian/react-crossword-next": "npm:@guardian/[email protected]",

dotcom-rendering/playwright/lib/cmp.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { BrowserContext, Page } from '@playwright/test';
2+
import { ALLOW_REJECT_ALL_COOKIE } from '../../src/client/userFeatures/cookies/allowRejectAll';
23
import { addCookie } from './cookies';
34
import { waitForIsland } from './islands';
45

@@ -40,6 +41,15 @@ const cmpRejectAll = async (page: Page): Promise<void> => {
4041
await new Promise((r) => setTimeout(r, 2000));
4142
};
4243

44+
const allowRejectAll = (context: BrowserContext): Promise<void> => {
45+
const expires = new Date();
46+
expires.setMonth(expires.getMonth() + 6);
47+
return addCookie(context, {
48+
name: ALLOW_REJECT_ALL_COOKIE,
49+
value: expires.getTime().toString(),
50+
});
51+
};
52+
4353
/**
4454
* Reconsent on the Sourcepoint CMP banner
4555
*
@@ -72,6 +82,7 @@ export {
7282
cmpAcceptAll,
7383
cmpReconsent,
7484
cmpRejectAll,
85+
allowRejectAll,
7586
disableCMP,
7687
CMP_LAYER1_IFRAME,
7788
};

dotcom-rendering/playwright/tests/atom.video.e2e.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isUndefined } from '@guardian/libs';
22
import type { Page } from '@playwright/test';
33
import { expect, test } from '@playwright/test';
4-
import { cmpAcceptAll, cmpRejectAll } from '../lib/cmp';
4+
import { allowRejectAll, cmpAcceptAll, cmpRejectAll } from '../lib/cmp';
55
import { waitForIsland } from '../lib/islands';
66
import { fetchAndloadPageWithOverrides } from '../lib/load-page';
77
import { expectToBeVisible, expectToNotExist } from '../lib/locators';
@@ -383,7 +383,10 @@ test.describe.skip('YouTube Atom', () => {
383383

384384
test.skip('plays the video if the reader rejects consent', async ({
385385
page,
386+
context,
386387
}) => {
388+
await allowRejectAll(context);
389+
387390
await fetchAndloadPageWithOverrides(
388391
page,
389392
'https://www.theguardian.com/environment/2021/oct/05/volcanoes-are-life-how-the-ocean-is-enriched-by-eruptions-devastating-on-land',

dotcom-rendering/playwright/tests/ophan.e2e.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import {
55
IMPRESSION_REQUEST_PATH,
66
interceptOphanRequest,
77
} from 'playwright/lib/ophan';
8-
import { cmpAcceptAll, cmpRejectAll, disableCMP } from '../lib/cmp';
8+
import {
9+
allowRejectAll,
10+
cmpAcceptAll,
11+
cmpRejectAll,
12+
disableCMP,
13+
} from '../lib/cmp';
914
import { loadPage } from '../lib/load-page';
1015

1116
const articleUrl =
@@ -16,7 +21,9 @@ const frontUrl = 'https://www.theguardian.com/uk';
1621
test.describe('Ophan requests', () => {
1722
test('should make an IMPRESSION request on an article when consent is rejected', async ({
1823
page,
24+
context,
1925
}) => {
26+
await allowRejectAll(context);
2027
const ophanImpressionRequestPromise = interceptOphanRequest({
2128
page,
2229
path: IMPRESSION_REQUEST_PATH,

dotcom-rendering/src/client/bootCmp.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import type { ConsentState } from '@guardian/libs';
22
import { cmp, onConsent } from '@guardian/libs';
33
import { getCookie, log } from '@guardian/libs';
44
import { getLocaleCode } from '../lib/getCountryCode';
5+
import { isUserLoggedInOktaRefactor } from '../lib/identity';
56
import type { RenderingTarget } from '../types/renderingTarget';
67
import { getOphan } from './ophan/ophan';
8+
import { allowRejectAll } from './userFeatures/cookies/allowRejectAll';
79

810
const submitConsentToOphan = async (renderingTarget: RenderingTarget) => {
911
const consentState: ConsentState = await onConsent();
@@ -59,6 +61,9 @@ const initialiseCmp = async () => {
5961
const code = await getLocaleCode();
6062
const browserId = getCookie({ name: 'bwid', shouldMemoize: true });
6163
const { pageViewId } = window.guardian.config.ophan;
64+
const isUserSignedIn = await isUserLoggedInOktaRefactor();
65+
// If user has the "reject all" benefit then show the reduced, "non-advertised" list
66+
const useNonAdvertisedList = allowRejectAll(isUserSignedIn);
6267

6368
const country = code ?? undefined;
6469
cmp.init({
@@ -69,6 +74,8 @@ const initialiseCmp = async () => {
6974
pageViewId,
7075
},
7176
country,
77+
useNonAdvertisedList,
78+
isUserSignedIn,
7279
});
7380
log('dotcom', 'CMP initialised');
7481
};

dotcom-rendering/src/components/TopBarMyAccount.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ import {
1414
import { useEffect, useState } from 'react';
1515
import type { UserProfile } from '../lib/discussion';
1616
import { getZIndex } from '../lib/getZIndex';
17-
import type {
18-
AuthStatus,
19-
SignedInWithCookies,
20-
SignedInWithOkta,
21-
} from '../lib/identity';
17+
import type { SignedInWithCookies, SignedInWithOkta } from '../lib/identity';
2218
import { createAuthenticationEventParams } from '../lib/identity-component-event';
2319
import {
2420
addNotificationsToDropdownLinks,
@@ -27,6 +23,7 @@ import {
2723
import type { Notification } from '../lib/notification';
2824
import { nestedOphanComponents } from '../lib/ophan-helpers';
2925
import { useApi } from '../lib/useApi';
26+
import type { AuthStatusOrPending } from '../lib/useAuthStatus';
3027
import { useBraze } from '../lib/useBraze';
3128
import { palette as themePalette } from '../palette';
3229
import ProfileIcon from '../static/icons/profile.svg';
@@ -40,7 +37,7 @@ interface MyAccountProps {
4037
idUrl: string;
4138
discussionApiUrl: string;
4239
idApiUrl: string;
43-
authStatus: AuthStatus;
40+
authStatus: AuthStatusOrPending;
4441
}
4542

4643
// when SignedIn, authStatus can only be one of the two SignedIn states

dotcom-rendering/src/lib/identity.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export type SignedInWithOkta = {
4141
};
4242

4343
export type AuthStatus =
44-
| { kind: 'Pending' }
4544
| SignedOutWithCookies
4645
| SignedInWithCookies
4746
| SignedOutWithOkta

dotcom-rendering/src/lib/useAuthStatus.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
getSignedInStatusWithOkta,
77
} from './identity';
88

9+
export type AuthStatusOrPending = AuthStatus | { kind: 'Pending' };
10+
911
/**
1012
* A hook to find out if a user is signed in.
1113
* Returns `'Pending'` until status is known.
@@ -25,8 +27,8 @@ export const useIsSignedIn = (): boolean | 'Pending' => {
2527
}
2628
};
2729

28-
export const useAuthStatus = (): AuthStatus => {
29-
const [authStatus, setAuthStatus] = useState<AuthStatus>({
30+
export const useAuthStatus = (): AuthStatusOrPending => {
31+
const [authStatus, setAuthStatus] = useState<AuthStatusOrPending>({
3032
kind: 'Pending',
3133
});
3234

pnpm-lock.yaml

Lines changed: 30 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)