@@ -26,6 +26,7 @@ import {
26
26
} from './SignInGate/componentEventTracking' ;
27
27
import {
28
28
incrementUserDismissedGateCount ,
29
+ retrieveDismissedCount ,
29
30
setUserDismissedGate ,
30
31
} from './SignInGate/dismissGate' ;
31
32
import { SignInGateAuxia } from './SignInGate/gateDesigns/SignInGateAuxia' ;
@@ -410,6 +411,11 @@ export const SignInGateSelector = ({
410
411
idUrl = { idUrl }
411
412
contributionsServiceUrl = { contributionsServiceUrl }
412
413
editionId = { editionId }
414
+ isPreview = { isPreview }
415
+ isPaidContent = { isPaidContent }
416
+ contentType = { contentType }
417
+ sectionId = { sectionId }
418
+ tags = { tags }
413
419
/>
414
420
) ;
415
421
}
@@ -444,6 +450,11 @@ type PropsAuxia = {
444
450
idUrl : string ;
445
451
contributionsServiceUrl : string ;
446
452
editionId : EditionId ;
453
+ isPreview : boolean ;
454
+ isPaidContent : boolean ;
455
+ contentType : string ;
456
+ sectionId : string ;
457
+ tags : TagType [ ] ;
447
458
} ;
448
459
449
460
interface ShowSignInGateAuxiaProps {
@@ -508,6 +519,10 @@ const fetchProxyGetTreatments = async (
508
519
isSupporter : boolean ,
509
520
dailyArticleCount : number ,
510
521
editionId : EditionId ,
522
+ contentType : string ,
523
+ sectionId : string ,
524
+ tagIds : string [ ] ,
525
+ gateDismissCount : number ,
511
526
) : Promise < AuxiaProxyGetTreatmentsResponse > => {
512
527
// pageId example: 'money/2017/mar/10/ministers-to-criminalise-use-of-ticket-tout-harvesting-software'
513
528
const articleIdentifier = `www.theguardian.com/${ pageId } ` ;
@@ -521,6 +536,10 @@ const fetchProxyGetTreatments = async (
521
536
dailyArticleCount,
522
537
articleIdentifier,
523
538
editionId,
539
+ contentType,
540
+ sectionId,
541
+ tagIds,
542
+ gateDismissCount,
524
543
} ;
525
544
const params = {
526
545
method : 'POST' ,
@@ -539,15 +558,24 @@ const buildAuxiaGateDisplayData = async (
539
558
contributionsServiceUrl : string ,
540
559
pageId : string ,
541
560
editionId : EditionId ,
561
+ contentType : string ,
562
+ sectionId : string ,
563
+ tags : TagType [ ] ,
564
+ gateDismissCount : number ,
542
565
) : Promise < AuxiaGateDisplayData | undefined > => {
543
566
const readerPersonalData = await decideAuxiaProxyReaderPersonalData ( ) ;
567
+ const tagIds = tags . map ( ( tag ) => tag . id ) ;
544
568
const response = await fetchProxyGetTreatments (
545
569
contributionsServiceUrl ,
546
570
pageId ,
547
571
readerPersonalData . browserId ,
548
572
readerPersonalData . isSupporter ,
549
573
readerPersonalData . dailyArticleCount ,
550
574
editionId ,
575
+ contentType ,
576
+ sectionId ,
577
+ tagIds ,
578
+ gateDismissCount ,
551
579
) ;
552
580
if ( response . status && response . data ) {
553
581
const answer = {
@@ -611,6 +639,11 @@ const SignInGateSelectorAuxia = ({
611
639
idUrl,
612
640
contributionsServiceUrl,
613
641
editionId,
642
+ isPreview,
643
+ isPaidContent,
644
+ contentType,
645
+ sectionId,
646
+ tags,
614
647
} : PropsAuxia ) => {
615
648
/*
616
649
comment group: auxia-prototype-e55a86ef
@@ -656,11 +689,20 @@ const SignInGateSelectorAuxia = ({
656
689
657
690
useOnce ( ( ) => {
658
691
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 ) {
660
698
const data = await buildAuxiaGateDisplayData (
661
699
contributionsServiceUrl ,
662
700
pageId ,
663
701
editionId ,
702
+ contentType ,
703
+ sectionId ,
704
+ tags ,
705
+ retrieveDismissedCount ( abTest . variant , abTest . name ) ,
664
706
) ;
665
707
if ( data !== undefined ) {
666
708
setAuxiaGateDisplayData ( data ) ;
@@ -671,7 +713,13 @@ const SignInGateSelectorAuxia = ({
671
713
} ) ;
672
714
} , [ abTest ] ) ;
673
715
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 ) ) {
675
723
return null ;
676
724
}
677
725
0 commit comments