Skip to content

Commit e22ca18

Browse files
authored
Merge pull request #13384 from guardian/ph-20250214-0444-paul
auxia experiment: Use default GU data in case of non consenting reader
2 parents addcc16 + 91d6fa2 commit e22ca18

File tree

2 files changed

+79
-52
lines changed

2 files changed

+79
-52
lines changed

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

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ export type SignInGateTestMap = { [name: string]: SignInGateComponent };
8484
comment group: auxia-prototype-e55a86ef
8585
*/
8686

87+
// Convention: In the naming of these types, we maintain the distinction between "AuxiaAPI", "AuxiaProxy" and "AuxiaGate".
88+
89+
// Get Treatments
90+
8791
export interface TreatmentContentDecoded {
8892
title: string;
8993
subtitle: string;
@@ -104,20 +108,24 @@ export interface AuxiaAPIResponseDataUserTreatment {
104108
surface: string;
105109
}
106110

107-
export interface SDCAuxiaGetTreatmentsProxyResponse {
111+
export interface AuxiaProxyGetTreatmentsPayload {
112+
browserId: string | undefined;
113+
isSupporter: boolean;
114+
dailyArticleCount: number;
115+
articleIdentifier: string;
116+
}
117+
118+
export interface AuxiaProxyGetTreatmentsResponse {
108119
status: boolean;
109-
data?: SDCAuxiaGetTreatmentsProxyResponseData;
120+
data?: AuxiaProxyGetTreatmentsProxyResponseData;
110121
}
111122

112-
export interface SDCAuxiaGetTreatmentsProxyResponseData {
123+
export interface AuxiaProxyGetTreatmentsProxyResponseData {
113124
responseId: string;
114125
userTreatment?: AuxiaAPIResponseDataUserTreatment;
115126
}
116127

117-
export interface AuxiaGateDisplayData {
118-
browserId: string;
119-
auxiaData: SDCAuxiaGetTreatmentsProxyResponseData;
120-
}
128+
// Log Treatment Interaction
121129

122130
export type AuxiaInteractionInteractionType =
123131
| 'VIEWED'
@@ -133,6 +141,29 @@ export type AuxiaInteractionActionName =
133141
| 'HELP-LINK'
134142
| ''; // used for 'VIEWED' and 'DISMISSED' interactions
135143

144+
export interface AuxiaProxyLogTreatmentInteractionPayload {
145+
browserId: string | undefined;
146+
treatmentTrackingId: string;
147+
treatmentId: string;
148+
surface: string;
149+
interactionType: AuxiaInteractionInteractionType;
150+
interactionTimeMicros: number;
151+
actionName: AuxiaInteractionActionName;
152+
}
153+
154+
// DCR Types
155+
156+
export interface AuxiaGateReaderPersonalData {
157+
browserId: string | undefined;
158+
dailyArticleCount: number;
159+
isSupporter: boolean;
160+
}
161+
162+
export interface AuxiaGateDisplayData {
163+
browserId: string | undefined;
164+
auxiaData: AuxiaProxyGetTreatmentsProxyResponseData;
165+
}
166+
136167
export type SignInGatePropsAuxia = {
137168
guUrl: string;
138169
signInUrl: string;

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

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ import { signInGateTestIdToComponentId } from './SignInGate/signInGateMappings';
3131
import type {
3232
AuxiaAPIResponseDataUserTreatment,
3333
AuxiaGateDisplayData,
34+
AuxiaGateReaderPersonalData,
3435
AuxiaInteractionActionName,
3536
AuxiaInteractionInteractionType,
37+
AuxiaProxyGetTreatmentsPayload,
38+
AuxiaProxyGetTreatmentsResponse,
39+
AuxiaProxyLogTreatmentInteractionPayload,
3640
CheckoutCompleteCookieData,
3741
CurrentSignInGateABTest,
38-
SDCAuxiaGetTreatmentsProxyResponse,
3942
SignInGateComponent,
4043
} from './SignInGate/types';
4144

@@ -440,36 +443,21 @@ interface ShowSignInGateAuxiaProps {
440443
abTest: CurrentSignInGateABTest;
441444
userTreatment: AuxiaAPIResponseDataUserTreatment;
442445
contributionsServiceUrl: string;
443-
browserId: string;
446+
browserId: string | undefined;
444447
logTreatmentInteractionCall: (
445448
interactionType: AuxiaInteractionInteractionType,
446449
actionName: AuxiaInteractionActionName,
447450
) => Promise<void>;
448451
}
449452

450-
const decideBrowserIdWithConsentCheck = async (): Promise<
451-
string | undefined
452-
> => {
453-
const hasConsent = await hasCmpConsentForBrowserId();
454-
if (!hasConsent) {
455-
return Promise.resolve(undefined);
456-
}
457-
458-
const cookie = getCookie({ name: 'bwid', shouldMemoize: true });
459-
if (cookie === null) {
460-
return Promise.resolve(undefined);
461-
}
462-
return Promise.resolve(cookie);
463-
};
464-
465453
const decideIsSupporter = (): boolean => {
466454
// nb: We will not be calling the Auxia API if the user is signed in, so we can set isSignedIn to false.
467455
const isSignedIn = false;
468-
const is_supporter = shouldHideSupportMessaging(isSignedIn);
469-
if (is_supporter === 'Pending') {
456+
const isSupporter = shouldHideSupportMessaging(isSignedIn);
457+
if (isSupporter === 'Pending') {
470458
return true;
471459
}
472-
return is_supporter;
460+
return isSupporter;
473461
};
474462

475463
const decideDailyArticleCount = (): number => {
@@ -486,25 +474,40 @@ const decideDailyArticleCount = (): number => {
486474
return 0;
487475
};
488476

477+
const decideAuxiaProxyReaderPersonalData =
478+
async (): Promise<AuxiaGateReaderPersonalData> => {
479+
const browserId =
480+
getCookie({ name: 'bwid', shouldMemoize: true }) ?? '';
481+
const dailyArticleCount = decideDailyArticleCount();
482+
const hasConsent = await hasCmpConsentForBrowserId();
483+
const isSupporter = decideIsSupporter();
484+
const data = {
485+
browserId: hasConsent ? browserId : undefined,
486+
dailyArticleCount,
487+
isSupporter,
488+
};
489+
return Promise.resolve(data);
490+
};
491+
489492
const fetchProxyGetTreatments = async (
490493
contributionsServiceUrl: string,
491494
pageId: string,
492-
browserId: string,
493-
is_supporter: boolean,
494-
daily_article_count: number,
495-
): Promise<SDCAuxiaGetTreatmentsProxyResponse> => {
495+
browserId: string | undefined,
496+
isSupporter: boolean,
497+
dailyArticleCount: number,
498+
): Promise<AuxiaProxyGetTreatmentsResponse> => {
496499
// pageId example: 'money/2017/mar/10/ministers-to-criminalise-use-of-ticket-tout-harvesting-software'
497-
const article_identifier = `www.theguardian.com/${pageId}`;
500+
const articleIdentifier = `www.theguardian.com/${pageId}`;
498501

499502
const url = `${contributionsServiceUrl}/auxia/get-treatments`;
500503
const headers = {
501504
'Content-Type': 'application/json',
502505
};
503-
const payload = {
506+
const payload: AuxiaProxyGetTreatmentsPayload = {
504507
browserId,
505-
is_supporter,
506-
daily_article_count,
507-
article_identifier,
508+
isSupporter,
509+
dailyArticleCount,
510+
articleIdentifier,
508511
};
509512
const params = {
510513
method: 'POST',
@@ -514,7 +517,7 @@ const fetchProxyGetTreatments = async (
514517

515518
const response_raw = await fetch(url, params);
516519
const response =
517-
(await response_raw.json()) as SDCAuxiaGetTreatmentsProxyResponse;
520+
(await response_raw.json()) as AuxiaProxyGetTreatmentsResponse;
518521

519522
return Promise.resolve(response);
520523
};
@@ -523,25 +526,17 @@ const buildAuxiaGateDisplayData = async (
523526
contributionsServiceUrl: string,
524527
pageId: string,
525528
): Promise<AuxiaGateDisplayData | undefined> => {
526-
const browserId = await decideBrowserIdWithConsentCheck();
527-
if (browserId === undefined) {
528-
return Promise.resolve(undefined);
529-
}
530-
531-
const is_supporter = decideIsSupporter();
532-
const daily_article_count = decideDailyArticleCount();
533-
529+
const readerPersonalData = await decideAuxiaProxyReaderPersonalData();
534530
const response = await fetchProxyGetTreatments(
535531
contributionsServiceUrl,
536532
pageId,
537-
browserId,
538-
is_supporter,
539-
daily_article_count,
533+
readerPersonalData.browserId,
534+
readerPersonalData.isSupporter,
535+
readerPersonalData.dailyArticleCount,
540536
);
541-
542537
if (response.status && response.data) {
543538
const answer = {
544-
browserId,
539+
browserId: readerPersonalData.browserId,
545540
auxiaData: response.data,
546541
};
547542
return Promise.resolve(answer);
@@ -555,14 +550,15 @@ const auxiaLogTreatmentInteraction = async (
555550
userTreatment: AuxiaAPIResponseDataUserTreatment,
556551
interactionType: AuxiaInteractionInteractionType,
557552
actionName: AuxiaInteractionActionName,
558-
browserId: string,
553+
browserId: string | undefined,
559554
): Promise<void> => {
560555
const url = `${contributionsServiceUrl}/auxia/log-treatment-interaction`;
561556
const headers = {
562557
'Content-Type': 'application/json',
563558
};
564559
const microTime = Date.now() * 1000;
565-
const payload = {
560+
561+
const payload: AuxiaProxyLogTreatmentInteractionPayload = {
566562
browserId,
567563
treatmentTrackingId: userTreatment.treatmentTrackingId,
568564
treatmentId: userTreatment.treatmentId,

0 commit comments

Comments
 (0)