Skip to content

Commit ceef640

Browse files
authored
Merge pull request #13533 from guardian/ph-20250305-1024-auxia
auxia experiment: upgrade payload of GetTreatments
2 parents 5fa2633 + d0d8cd9 commit ceef640

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ export const hasUserDismissedGate = (
100100
return !(pref == null);
101101
};
102102

103-
const retrieveDismissedCount = (variant: string, name: string): number => {
103+
export const retrieveDismissedCount = (
104+
variant: string,
105+
name: string,
106+
): number => {
104107
const prefs = getSigninGatePrefsSafely();
105108
const dismissed = prefs[localStorageDismissedCountKey(variant, name)];
106109

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ export interface AuxiaProxyGetTreatmentsPayload {
114114
dailyArticleCount: number;
115115
articleIdentifier: string;
116116
editionId: EditionId;
117+
contentType: string;
118+
sectionId: string;
119+
tagIds: string[];
120+
gateDismissCount: number;
117121
}
118122

119123
export interface AuxiaProxyGetTreatmentsResponse {

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

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
} from './SignInGate/componentEventTracking';
2727
import {
2828
incrementUserDismissedGateCount,
29+
retrieveDismissedCount,
2930
setUserDismissedGate,
3031
} from './SignInGate/dismissGate';
3132
import { SignInGateAuxia } from './SignInGate/gateDesigns/SignInGateAuxia';
@@ -410,6 +411,11 @@ export const SignInGateSelector = ({
410411
idUrl={idUrl}
411412
contributionsServiceUrl={contributionsServiceUrl}
412413
editionId={editionId}
414+
isPreview={isPreview}
415+
isPaidContent={isPaidContent}
416+
contentType={contentType}
417+
sectionId={sectionId}
418+
tags={tags}
413419
/>
414420
);
415421
}
@@ -444,6 +450,11 @@ type PropsAuxia = {
444450
idUrl: string;
445451
contributionsServiceUrl: string;
446452
editionId: EditionId;
453+
isPreview: boolean;
454+
isPaidContent: boolean;
455+
contentType: string;
456+
sectionId: string;
457+
tags: TagType[];
447458
};
448459

449460
interface ShowSignInGateAuxiaProps {
@@ -508,6 +519,10 @@ const fetchProxyGetTreatments = async (
508519
isSupporter: boolean,
509520
dailyArticleCount: number,
510521
editionId: EditionId,
522+
contentType: string,
523+
sectionId: string,
524+
tagIds: string[],
525+
gateDismissCount: number,
511526
): Promise<AuxiaProxyGetTreatmentsResponse> => {
512527
// pageId example: 'money/2017/mar/10/ministers-to-criminalise-use-of-ticket-tout-harvesting-software'
513528
const articleIdentifier = `www.theguardian.com/${pageId}`;
@@ -521,6 +536,10 @@ const fetchProxyGetTreatments = async (
521536
dailyArticleCount,
522537
articleIdentifier,
523538
editionId,
539+
contentType,
540+
sectionId,
541+
tagIds,
542+
gateDismissCount,
524543
};
525544
const params = {
526545
method: 'POST',
@@ -539,15 +558,24 @@ const buildAuxiaGateDisplayData = async (
539558
contributionsServiceUrl: string,
540559
pageId: string,
541560
editionId: EditionId,
561+
contentType: string,
562+
sectionId: string,
563+
tags: TagType[],
564+
gateDismissCount: number,
542565
): Promise<AuxiaGateDisplayData | undefined> => {
543566
const readerPersonalData = await decideAuxiaProxyReaderPersonalData();
567+
const tagIds = tags.map((tag) => tag.id);
544568
const response = await fetchProxyGetTreatments(
545569
contributionsServiceUrl,
546570
pageId,
547571
readerPersonalData.browserId,
548572
readerPersonalData.isSupporter,
549573
readerPersonalData.dailyArticleCount,
550574
editionId,
575+
contentType,
576+
sectionId,
577+
tagIds,
578+
gateDismissCount,
551579
);
552580
if (response.status && response.data) {
553581
const answer = {
@@ -611,6 +639,11 @@ const SignInGateSelectorAuxia = ({
611639
idUrl,
612640
contributionsServiceUrl,
613641
editionId,
642+
isPreview,
643+
isPaidContent,
644+
contentType,
645+
sectionId,
646+
tags,
614647
}: PropsAuxia) => {
615648
/*
616649
comment group: auxia-prototype-e55a86ef
@@ -656,11 +689,20 @@ const SignInGateSelectorAuxia = ({
656689

657690
useOnce(() => {
658691
void (async () => {
659-
if (!isSignedIn) {
692+
// Although the component is returning null if we are in preview or it's a paid content
693+
// We need to guard against the API possibly being called before the component returns.
694+
// That is because it would count as a content delivery for them, above all if they return a treatment
695+
// without the subsequent Log Treatment notification, which would cause confusion.
696+
697+
if (!isSignedIn && !isPreview && !isPaidContent) {
660698
const data = await buildAuxiaGateDisplayData(
661699
contributionsServiceUrl,
662700
pageId,
663701
editionId,
702+
contentType,
703+
sectionId,
704+
tags,
705+
retrieveDismissedCount(abTest.variant, abTest.name),
664706
);
665707
if (data !== undefined) {
666708
setAuxiaGateDisplayData(data);
@@ -671,7 +713,13 @@ const SignInGateSelectorAuxia = ({
671713
});
672714
}, [abTest]);
673715

674-
if (isSignedIn || isUndefined(pageViewId)) {
716+
// We are not showing the gate if we are in preview, it's a paid contents
717+
// or the user is signed in or if for some reasons we could not determine the
718+
// pageViewId
719+
720+
// According to the reacts rules we can only put this check after all the hooks.
721+
722+
if (isPreview || isPaidContent || isSignedIn || isUndefined(pageViewId)) {
675723
return null;
676724
}
677725

0 commit comments

Comments
 (0)