Skip to content

Commit 6ae8db5

Browse files
authored
Merge pull request #14462 from guardian/ph-20250829-1858-supporter-gate
[sign-in gate] decideHideSupportMessagingTimestamp
2 parents 5c9dfb2 + 820fef0 commit 6ae8db5

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export interface AuxiaProxyGetTreatmentsPayload {
127127
shouldServeDismissible: boolean; // [2]
128128
showDefaultGate: ShowGateValues; // [3]
129129
gateDisplayCount: number;
130+
hideSupportMessagingTimestamp: number | undefined; // [4]
130131
}
131132

132133
// [1]
@@ -163,6 +164,16 @@ export interface AuxiaProxyGetTreatmentsPayload {
163164

164165
// Note that this attributes override the value of should_show_legacy_gate_tmp.
165166

167+
// [4]
168+
169+
// date: 30th August 2025
170+
// author: Pascal
171+
172+
// `hideSupportMessagingTimestamp: number | undefined` was introduced to implement the effect
173+
// of not showing the gate if the reader has performed a single contribution in the past 30 days.
174+
// It is either undefined or return the timestamp carried by cookie `gu_hide_support_messaging`
175+
// See: https://github.com/guardian/support-frontend/blob/7a5c0f9209054c24934b876771392531c261f51c/support-frontend/assets/helpers/storage/contributionsCookies.ts#L11
176+
166177
export interface AuxiaProxyGetTreatmentsResponse {
167178
status: boolean;
168179
data?: AuxiaProxyGetTreatmentsProxyResponseData;

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ const fetchProxyGetTreatments = async (
294294
shouldServeDismissible: boolean,
295295
showDefaultGate: ShowGateValues,
296296
gateDisplayCount: number,
297+
hideSupportMessagingTimestamp: number | undefined,
297298
): Promise<AuxiaProxyGetTreatmentsResponse> => {
298299
// pageId example: 'money/2017/mar/10/ministers-to-criminalise-use-of-ticket-tout-harvesting-software'
299300
const articleIdentifier = `www.theguardian.com/${pageId}`;
@@ -319,6 +320,7 @@ const fetchProxyGetTreatments = async (
319320
shouldServeDismissible,
320321
showDefaultGate,
321322
gateDisplayCount,
323+
hideSupportMessagingTimestamp,
322324
};
323325
const params = {
324326
method: 'POST',
@@ -393,6 +395,32 @@ const incrementGateDisplayCount = () => {
393395
storage.local.setRaw('gate_display_count', newCount.toString());
394396
};
395397

398+
const decideHideSupportMessagingTimestamp = (): number | undefined => {
399+
// Date: 1 September 2025
400+
//
401+
// This cookie is overloaded in the following way:
402+
// If the user has performed single contribution, then the value is the
403+
// timestamp of the event. But if the user has performed a recurring
404+
// contribution, then the value is a future timestamp.
405+
//
406+
// Ideally we would correct the semantics of the cookie, but for the moment
407+
// we are simply going to ignore the value if it's in the future. We
408+
// are making this adjustment here, but will also mirror it in SDC
409+
410+
const rawValue: string | null = storage.local.getRaw(
411+
'gu_hide_support_messaging',
412+
);
413+
if (rawValue === null) {
414+
return undefined;
415+
}
416+
const timestamp = parseInt(rawValue, 10);
417+
const now = Date.now(); // current time in milliseconds since epoch
418+
if (Number.isInteger(timestamp) && timestamp < now) {
419+
return timestamp;
420+
}
421+
return undefined;
422+
};
423+
396424
const buildAuxiaGateDisplayData = async (
397425
contributionsServiceUrl: string,
398426
pageId: string,
@@ -434,6 +462,8 @@ const buildAuxiaGateDisplayData = async (
434462
const showDefaultGate = decideShowDefaultGate();
435463
const gateDisplayCount = getGateDisplayCount();
436464

465+
const hideSupportMessagingTimestamp = decideHideSupportMessagingTimestamp();
466+
437467
const response = await fetchProxyGetTreatments(
438468
contributionsServiceUrl,
439469
pageId,
@@ -452,6 +482,7 @@ const buildAuxiaGateDisplayData = async (
452482
shouldServeDismissible,
453483
showDefaultGate,
454484
gateDisplayCount,
485+
hideSupportMessagingTimestamp,
455486
);
456487

457488
if (response.status && response.data) {

0 commit comments

Comments
 (0)