@@ -200,6 +200,29 @@ const guDefaultGateGetTreatmentsResponseData = (
200200 return data ;
201201} ;
202202
203+ const isValidContentType = ( contentType : string ) : boolean => {
204+ const validTypes = [ 'Article' ] ;
205+ return validTypes . includes ( contentType ) ;
206+ } ;
207+
208+ const isValidSection = ( sectionId : string ) : boolean => {
209+ const invalidSections = [
210+ 'about' ,
211+ 'info' ,
212+ 'membership' ,
213+ 'help' ,
214+ 'guardian-live-australia' ,
215+ 'gnm-archive' ,
216+ ] ;
217+ return ! invalidSections . some ( ( section : string ) : boolean => sectionId === section ) ;
218+ } ;
219+
220+ const isValidTagIdCollection = ( tagIds : string [ ] ) : boolean => {
221+ const invalidTagIds = [ 'info/newsletter-sign-up' ] ;
222+ // Check that no tagId is in the invalidTagIds list.
223+ return ! tagIds . some ( ( tagId : string ) : boolean => invalidTagIds . includes ( tagId ) ) ;
224+ } ;
225+
203226const callGetTreatments = async (
204227 apiKey : string ,
205228 projectId : string ,
@@ -208,16 +231,41 @@ const callGetTreatments = async (
208231 dailyArticleCount : number ,
209232 articleIdentifier : string ,
210233 editionId : string ,
234+ contentType : string ,
235+ sectionId : string ,
236+ tagIds : string [ ] ,
237+ gateDismissCount : number ,
211238) : 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).
239+ // The logic here is to perform a certain number of checks, each resulting with a different behavior.
240+
241+ // First we check page metada to comply with Guardian policies
242+
243+ if (
244+ ! isValidContentType ( contentType ) ||
245+ ! isValidSection ( sectionId ) ||
246+ ! isValidTagIdCollection ( tagIds )
247+ ) {
248+ return Promise . resolve ( undefined ) ;
249+ }
250+
251+ // Then we enforce the GU policy of not showing the gate if the user has dismissed it more than 5 times.
252+ // (We do not want users to have to dismiss the gate 6 times)
253+
254+ if ( gateDismissCount > 5 ) {
255+ return Promise . resolve ( undefined ) ;
256+ }
257+
258+ // Then we check if the user has consented to personal data use.
259+ // If the user has not consented, we return the default gu-gate (which we can generate
260+ // and serve wihtout calling Auxia).
215261
216262 if ( browserId === undefined ) {
217263 const data = guDefaultGateGetTreatmentsResponseData ( dailyArticleCount ) ;
218264 return Promise . resolve ( data ) ;
219265 }
220266
267+ // We now have clearance to call the Auxia API.
268+
221269 const url = 'https://apis.auxia.io/v1/GetTreatments' ;
222270
223271 const headers = {
@@ -358,6 +406,10 @@ export const buildAuxiaProxyRouter = (config: AuxiaRouterConfig): Router => {
358406 'dailyArticleCount' ,
359407 'articleIdentifier' ,
360408 'editionId' ,
409+ 'contentType' ,
410+ 'sectionId' ,
411+ 'tagIds' ,
412+ 'gateDismissCount' ,
361413 ] ) ,
362414 async ( req : express . Request , res : express . Response , next : express . NextFunction ) => {
363415 try {
@@ -369,6 +421,10 @@ export const buildAuxiaProxyRouter = (config: AuxiaRouterConfig): Router => {
369421 req . body . dailyArticleCount ,
370422 req . body . articleIdentifier ,
371423 req . body . editionId ,
424+ req . body . contentType ,
425+ req . body . sectionId ,
426+ req . body . tagIds ,
427+ req . body . gateDismissCount ,
372428 ) ;
373429
374430 if ( auxiaData !== undefined ) {
0 commit comments