Skip to content

Commit 5e405f0

Browse files
committed
feat(google-one-tap): Limit Google One Tap to Ireland initially
1 parent 3ea647d commit 5e405f0

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

dotcom-rendering/src/components/GoogleOneTap.importable.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import type { CountryCode } from '@guardian/libs';
12
import { log } from '@guardian/libs';
23
import type { TAction, TComponentType } from '@guardian/ophan-tracker-js';
34
import { submitComponentEvent } from '../client/ophan/ophan';
45
import { useIsSignedIn } from '../lib/useAuthStatus';
56
import { useConsent } from '../lib/useConsent';
7+
import { useCountryCode } from '../lib/useCountryCode';
68
import { useOnce } from '../lib/useOnce';
79
import type { ServerSideTests, StageType } from '../types/config';
810

@@ -108,9 +110,10 @@ const getProviders = (stage: StageType): IdentityProviderConfig[] => {
108110

109111
export const initializeFedCM = async ({
110112
isSignedIn,
113+
countryCode,
111114
}: {
112115
isSignedIn?: boolean;
113-
isInTest?: boolean;
116+
countryCode?: CountryCode;
114117
}): Promise<void> => {
115118
const isSupported = 'IdentityCredential' in window;
116119

@@ -131,6 +134,8 @@ export const initializeFedCM = async ({
131134
'Web',
132135
);
133136

137+
// TODO: Expand Google One Tap to outside Ireland
138+
if (countryCode !== 'IE') return;
134139
if (isSignedIn) return;
135140

136141
/**
@@ -256,6 +261,7 @@ export const GoogleOneTap = () => {
256261
// TODO: FedCM doesn't require cookies? Do we need to check consent?
257262
const consent = useConsent();
258263
const isSignedIn = useIsSignedIn();
264+
const countryCode = useCountryCode('google-one-tap');
259265
// useIsSignedIn returns 'Pending' until the auth status is known.
260266
// We don't want to initialize FedCM until we know the auth status, so we pass `undefined` to `useOnce` if it is 'Pending'
261267
// to stop it from initializing.
@@ -265,6 +271,7 @@ export const GoogleOneTap = () => {
265271
useOnce(() => {
266272
void initializeFedCM({
267273
isSignedIn: isSignedInWithoutPending,
274+
countryCode,
268275
});
269276
}, [isSignedInWithoutPending, consent]);
270277

dotcom-rendering/src/components/GoogleOneTap.test.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe('GoogleOneTap', () => {
9494
replace: locationReplace,
9595
});
9696

97-
await initializeFedCM({ isSignedIn: false });
97+
await initializeFedCM({ isSignedIn: false, countryCode: 'IE' });
9898

9999
expect(navigatorGet).toHaveBeenCalledWith({
100100
identity: {
@@ -150,7 +150,7 @@ describe('GoogleOneTap', () => {
150150
replace: locationReplace,
151151
});
152152

153-
await initializeFedCM({ isSignedIn: false });
153+
await initializeFedCM({ isSignedIn: false, countryCode: 'IE' });
154154

155155
expect(submitComponentEventMock).toHaveBeenNthCalledWith(
156156
1,
@@ -205,9 +205,9 @@ describe('GoogleOneTap', () => {
205205
replace: locationReplace,
206206
});
207207

208-
await expect(initializeFedCM({ isSignedIn: false })).rejects.toThrow(
209-
'window.navigator.credentials.get failed',
210-
);
208+
await expect(
209+
initializeFedCM({ isSignedIn: false, countryCode: 'IE' }),
210+
).rejects.toThrow('window.navigator.credentials.get failed');
211211

212212
expect(submitComponentEventMock).toHaveBeenNthCalledWith(
213213
1,
@@ -249,7 +249,7 @@ describe('GoogleOneTap', () => {
249249
enableFedCM: false,
250250
});
251251

252-
await initializeFedCM({ isSignedIn: false });
252+
await initializeFedCM({ isSignedIn: false, countryCode: 'IE' });
253253

254254
expect(submitComponentEventMock).toHaveBeenCalledTimes(1);
255255
expect(submitComponentEventMock).toHaveBeenCalledWith(
@@ -276,13 +276,13 @@ describe('GoogleOneTap', () => {
276276
replace: locationReplace,
277277
});
278278

279-
await initializeFedCM({ isSignedIn: true });
279+
await initializeFedCM({ isSignedIn: true, countryCode: 'IE' });
280280

281281
expect(navigatorGet).not.toHaveBeenCalled();
282282
expect(locationReplace).not.toHaveBeenCalled();
283283
});
284284

285-
it('should not initializeFedCM when user is not in test', async () => {
285+
it('should not initializeFedCM when user is not in Ireland', async () => {
286286
const navigatorGet = jest.fn();
287287
const locationReplace = jest.fn();
288288

@@ -291,7 +291,7 @@ describe('GoogleOneTap', () => {
291291
replace: locationReplace,
292292
});
293293

294-
await initializeFedCM({ isSignedIn: true });
294+
await initializeFedCM({ isSignedIn: false, countryCode: 'GB' });
295295

296296
expect(submitComponentEventMock).toHaveBeenCalledTimes(1);
297297
expect(submitComponentEventMock).toHaveBeenCalledWith(

0 commit comments

Comments
 (0)