Skip to content

Commit cc7ac4d

Browse files
authored
Merge pull request #1304 from guardian/ph-20250306-0710-auxia
auxia experiment: upgrade the proxy payload for GetTreatments
2 parents 347a5c8 + 1169cbe commit cc7ac4d

File tree

1 file changed

+72
-5
lines changed

1 file changed

+72
-5
lines changed

src/server/api/auxiaProxyRouter.ts

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,33 @@ const guDefaultShouldShowTheGate = (daily_article_count: number): boolean => {
158158

159159
const guDefaultGateGetTreatmentsResponseData = (
160160
daily_article_count: number,
161+
gateDismissCount: number,
161162
): AuxiaAPIGetTreatmentsResponseData => {
163+
// This function is called in the case of non consenting users, which is detected by the absence of the browserId.
164+
162165
const responseId = ''; // This value is not important, it is not used by the client.
163166

167+
// First we enforce the GU policy of not showing the gate if the user has dismissed it more than 5 times.
168+
// (We do not want users to have to dismiss the gate 6 times)
169+
170+
if (gateDismissCount > 5) {
171+
return {
172+
responseId,
173+
userTreatments: [],
174+
};
175+
}
176+
177+
// Then to prevent showing the gate too many times, we only show the gate every 10 pages views
178+
164179
if (!guDefaultShouldShowTheGate(daily_article_count)) {
165-
// We show the GU gate every 10 pageviews
166180
return {
167181
responseId,
168182
userTreatments: [],
169183
};
170184
}
171185

186+
// We are now clear to show the default gu gate.
187+
172188
const title = 'Register: it’s quick and easy';
173189
const subtitle = 'It’s still free to read – this is not a paywall';
174190
const body =
@@ -200,6 +216,29 @@ const guDefaultGateGetTreatmentsResponseData = (
200216
return data;
201217
};
202218

219+
const isValidContentType = (contentType: string): boolean => {
220+
const validTypes = ['Article'];
221+
return validTypes.includes(contentType);
222+
};
223+
224+
const isValidSection = (sectionId: string): boolean => {
225+
const invalidSections = [
226+
'about',
227+
'info',
228+
'membership',
229+
'help',
230+
'guardian-live-australia',
231+
'gnm-archive',
232+
];
233+
return !invalidSections.some((section: string): boolean => sectionId === section);
234+
};
235+
236+
const isValidTagIdCollection = (tagIds: string[]): boolean => {
237+
const invalidTagIds = ['info/newsletter-sign-up'];
238+
// Check that no tagId is in the invalidTagIds list.
239+
return !tagIds.some((tagId: string): boolean => invalidTagIds.includes(tagId));
240+
};
241+
203242
const callGetTreatments = async (
204243
apiKey: string,
205244
projectId: string,
@@ -208,16 +247,36 @@ const callGetTreatments = async (
208247
dailyArticleCount: number,
209248
articleIdentifier: string,
210249
editionId: string,
250+
contentType: string,
251+
sectionId: string,
252+
tagIds: string[],
253+
gateDismissCount: number,
211254
): Promise<AuxiaAPIGetTreatmentsResponseData | undefined> => {
212-
// Here the behavior depends on the value of `user_has_consented_to_personal_data_use`
213-
// If defined, we perform the normal API call to Auxia.
214-
// If undefined, we return a default answer (controlled by GU).
255+
// The logic here is to perform a certain number of checks, each resulting with a different behavior.
256+
257+
// First we check page metada to comply with Guardian policies
258+
259+
if (
260+
!isValidContentType(contentType) ||
261+
!isValidSection(sectionId) ||
262+
!isValidTagIdCollection(tagIds)
263+
) {
264+
return Promise.resolve(undefined);
265+
}
266+
267+
// Then we check if the user has consented to personal data use.
268+
// If the user has not consented, we call for the gu-default gate, which may or may not be served depending on
269+
// policies.
215270

216271
if (browserId === undefined) {
217-
const data = guDefaultGateGetTreatmentsResponseData(dailyArticleCount);
272+
const data = guDefaultGateGetTreatmentsResponseData(dailyArticleCount, gateDismissCount);
218273
return Promise.resolve(data);
219274
}
220275

276+
console.log('We have consent to use personal data');
277+
278+
// We now have clearance to call the Auxia API.
279+
221280
const url = 'https://apis.auxia.io/v1/GetTreatments';
222281

223282
const headers = {
@@ -358,6 +417,10 @@ export const buildAuxiaProxyRouter = (config: AuxiaRouterConfig): Router => {
358417
'dailyArticleCount',
359418
'articleIdentifier',
360419
'editionId',
420+
'contentType',
421+
'sectionId',
422+
'tagIds',
423+
'gateDismissCount',
361424
]),
362425
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
363426
try {
@@ -369,6 +432,10 @@ export const buildAuxiaProxyRouter = (config: AuxiaRouterConfig): Router => {
369432
req.body.dailyArticleCount,
370433
req.body.articleIdentifier,
371434
req.body.editionId,
435+
req.body.contentType,
436+
req.body.sectionId,
437+
req.body.tagIds,
438+
req.body.gateDismissCount,
372439
);
373440

374441
if (auxiaData !== undefined) {

0 commit comments

Comments
 (0)