Skip to content

Commit 6e45da0

Browse files
authored
Merge pull request #14373 from guardian/ph-20250811-1417-new-gate-logic-p1
Introduce gate_display_count
2 parents 1e0f774 + 95a9043 commit 6e45da0

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

dotcom-rendering/src/components/SignInGate/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export interface AuxiaProxyGetTreatmentsPayload {
126126
hasConsented: boolean;
127127
shouldServeDismissible: boolean; // [2]
128128
showDefaultGate: ShowGateValues; // [3]
129+
gateDisplayCount: number;
129130
}
130131

131132
// [1]

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getCookie, isUndefined } from '@guardian/libs';
1+
import { getCookie, isUndefined, storage } from '@guardian/libs';
22
import { useState } from 'react';
33
import {
44
hasCmpConsentForBrowserId,
@@ -293,6 +293,7 @@ const fetchProxyGetTreatments = async (
293293
hasConsented: boolean,
294294
shouldServeDismissible: boolean,
295295
showDefaultGate: ShowGateValues,
296+
gateDisplayCount: number,
296297
): Promise<AuxiaProxyGetTreatmentsResponse> => {
297298
// pageId example: 'money/2017/mar/10/ministers-to-criminalise-use-of-ticket-tout-harvesting-software'
298299
const articleIdentifier = `www.theguardian.com/${pageId}`;
@@ -317,6 +318,7 @@ const fetchProxyGetTreatments = async (
317318
hasConsented,
318319
shouldServeDismissible,
319320
showDefaultGate,
321+
gateDisplayCount,
320322
};
321323
const params = {
322324
method: 'POST',
@@ -372,6 +374,26 @@ const decideShowDefaultGate = (): ShowGateValues => {
372374
return undefined;
373375
};
374376

377+
const getGateDisplayCount = (): number => {
378+
const rawValue = storage.local.getRaw('gate_display_count');
379+
const count = parseInt(rawValue ?? '0', 10);
380+
return count;
381+
};
382+
383+
const incrementGateDisplayCount = () => {
384+
const count = getGateDisplayCount();
385+
const now = new Date();
386+
const oneYearFromNow = new Date(now.getTime() + 365 * 86400);
387+
const newCount = count + 1;
388+
// Using `storage.local.set`, instead of `storage.local.setRaw`
389+
// because `setRaw` doesn't allow for specifying the duration.
390+
storage.local.set(
391+
'gate_display_count',
392+
newCount.toString(),
393+
oneYearFromNow,
394+
);
395+
};
396+
375397
const buildAuxiaGateDisplayData = async (
376398
contributionsServiceUrl: string,
377399
pageId: string,
@@ -410,8 +432,8 @@ const buildAuxiaGateDisplayData = async (
410432
}
411433

412434
const shouldServeDismissible = decideShouldServeDismissible();
413-
414435
const showDefaultGate = decideShowDefaultGate();
436+
const gateDisplayCount = getGateDisplayCount();
415437

416438
const response = await fetchProxyGetTreatments(
417439
contributionsServiceUrl,
@@ -430,6 +452,7 @@ const buildAuxiaGateDisplayData = async (
430452
readerPersonalData.hasConsented,
431453
shouldServeDismissible,
432454
showDefaultGate,
455+
gateDisplayCount,
433456
);
434457

435458
if (response.status && response.data) {
@@ -724,6 +747,10 @@ const ShowSignInGateAuxia = ({
724747
},
725748
renderingTarget,
726749
);
750+
751+
// Once the gate is being displayed we need to update
752+
// the tracking of the number of times the gate has been displayed
753+
incrementGateDisplayCount();
727754
}, [componentId]);
728755

729756
return (

0 commit comments

Comments
 (0)