Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions dotcom-rendering/src/components/SignInGate/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export interface AuxiaAPIResponseDataUserTreatment {
surface: string;
}

export type ShowGateValues = 'true' | 'mandatory' | 'dismissible' | undefined;

export interface AuxiaProxyGetTreatmentsPayload {
browserId: string | undefined;
isSupporter: boolean;
Expand All @@ -123,7 +125,7 @@ export interface AuxiaProxyGetTreatmentsPayload {
should_show_legacy_gate_tmp: boolean; // [1]
hasConsented: boolean;
shouldServeDismissible: boolean; // [2]
mustShowDefaultGate: boolean; // [3]
showDefaultGate: ShowGateValues; // [3]
}

// [1]
Expand All @@ -146,19 +148,19 @@ export interface AuxiaProxyGetTreatmentsPayload {
// We will be setting it to false.

// [2]
// date: 03rd July 2025
// If shouldServeDismissible is true, we should show a dismissible gate.
// date: 03rd July 2025// If shouldServeDismissible is true, we should show a dismissible gate.

// [3]
// date: 23rd July 2025

// date: 25rd July 2025
// author: Pascal
// In order to facilitate internal testing, this attribute forces
// the display of a sign-in gate, namely the default gu gate. If it is true then
// the default gate is going to be displayed. Note that this applies to both auxia and
// non auxia audiences. In particular because it also applies to auxia audiences, for which
// the value of should_show_legacy_gate_tmp is ignored, then the information needs to come to
// the SDC server as a new parameter in the GetTreatments payload. To trigger
// gate display, the url should have query parameter `showgate=true`

// In order to facilitate internal testing, this attribute, when defined, forces
// the display of a sign-in gate. The values 'true' and 'dismissible' displays the
// dismissible variant of the gu default gate, and the value 'mandatory' displays
// the mandatory variant of the gu default gate.

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

export interface AuxiaProxyGetTreatmentsResponse {
status: boolean;
Expand Down
27 changes: 19 additions & 8 deletions dotcom-rendering/src/components/SignInGateSelector.importable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import type {
AuxiaProxyLogTreatmentInteractionPayload,
CanShowGateProps,
CurrentSignInGateABTest,
ShowGateValues,
} from './SignInGate/types';

// ------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -291,7 +292,7 @@ const fetchProxyGetTreatments = async (
should_show_legacy_gate_tmp: boolean,
hasConsented: boolean,
shouldServeDismissible: boolean,
mustShowDefaultGate: boolean,
showDefaultGate: ShowGateValues,
): Promise<AuxiaProxyGetTreatmentsResponse> => {
// pageId example: 'money/2017/mar/10/ministers-to-criminalise-use-of-ticket-tout-harvesting-software'
const articleIdentifier = `www.theguardian.com/${pageId}`;
Expand All @@ -315,7 +316,7 @@ const fetchProxyGetTreatments = async (
should_show_legacy_gate_tmp,
hasConsented,
shouldServeDismissible,
mustShowDefaultGate,
showDefaultGate,
};
const params = {
method: 'POST',
Expand All @@ -332,8 +333,8 @@ const fetchProxyGetTreatments = async (

const decideShouldServeDismissible = (): boolean => {
// Return a boolean indicating whether or not we accept mandatory gates for this call.
// If the answer is `false` this doesn't decide whether the gate should be displayed or not,
// it only means that if a gate is returned, then it must be mandatory.
// If the answer is `true` this doesn't decide whether the gate should be displayed or not,
// it only means that if a gate is returned, then it must be dismissible (not be mandatory).

// Now the question is how do we decide the answer ?
// We return false if the following query parameter is present in the url:
Expand All @@ -348,7 +349,7 @@ const decideShouldServeDismissible = (): boolean => {
return false;
};

const decideMustShowDefaultGate = (): boolean => {
const decideShowDefaultGate = (): ShowGateValues => {
// In order to facilitate internal testing, this function observes a query parameter which forces
// the display of a sign-in gate, namely the default gu gate. If this returns true then
// the default gate is going to be displayed. Note that this applies to both auxia and
Expand All @@ -360,7 +361,17 @@ const decideMustShowDefaultGate = (): boolean => {

const params = new URLSearchParams(window.location.search);
const value: string | null = params.get('showgate');
return value === 'true';

if (value === null) {
return undefined;
}

const validValues = ['true', 'dismissible', 'mandatory'];
if (validValues.includes(value)) {
return value as ShowGateValues;
}

return undefined;
};

const buildAuxiaGateDisplayData = async (
Expand Down Expand Up @@ -402,7 +413,7 @@ const buildAuxiaGateDisplayData = async (

const shouldServeDismissible = decideShouldServeDismissible();

const mustShowDefaultGate = decideMustShowDefaultGate();
const showDefaultGate = decideShowDefaultGate();

const response = await fetchProxyGetTreatments(
contributionsServiceUrl,
Expand All @@ -420,7 +431,7 @@ const buildAuxiaGateDisplayData = async (
should_show_legacy_gate_tmp,
readerPersonalData.hasConsented,
shouldServeDismissible,
mustShowDefaultGate,
showDefaultGate,
);

if (response.status && response.data) {
Expand Down