11import { getCookie , isUndefined , storage } from '@guardian/libs' ;
22import { useState } from 'react' ;
33import { constructQuery } from '../lib/querystring' ;
4+ import { useIsInView } from '../lib/useIsInView' ;
45import { useOnce } from '../lib/useOnce' ;
56import { usePageViewId } from '../lib/usePageViewId' ;
67import type { RenderingTarget } from '../types/renderingTarget' ;
@@ -363,45 +364,52 @@ const ShowSignInGateAuxia = ({
363364 const checkoutCompleteCookieData = undefined ;
364365 const personaliseSignInGateAfterCheckoutSwitch = undefined ;
365366
367+ const [ hasBeenSeen , setNode ] = useIsInView ( {
368+ debounce : true ,
369+ threshold : 0 ,
370+ } ) ;
371+
366372 useOnce ( ( ) => {
367- void auxiaLogTreatmentInteraction (
368- contributionsServiceUrl ,
369- userTreatment ,
370- 'VIEWED' ,
371- '' ,
372- browserId ,
373- ) . catch ( ( error ) => {
374- const errorReport = new Error (
375- `Failed to log treatment interaction` ,
373+ if ( hasBeenSeen ) {
374+ void auxiaLogTreatmentInteraction (
375+ contributionsServiceUrl ,
376+ userTreatment ,
377+ 'VIEWED' ,
378+ '' ,
379+ browserId ,
380+ ) . catch ( ( error ) => {
381+ const errorReport = new Error (
382+ `Failed to log treatment interaction` ,
383+ {
384+ cause : error ,
385+ } ,
386+ ) ;
387+ window . guardian . modules . sentry . reportError (
388+ errorReport ,
389+ 'sign-in-gate' ,
390+ ) ;
391+ } ) ;
392+
393+ void submitComponentEventTracking (
376394 {
377- cause : error ,
395+ component : {
396+ componentType : 'SIGN_IN_GATE' ,
397+ id : treatmentId ,
398+ } ,
399+ action : 'VIEW' ,
400+ abTest : buildAbTestTrackingAuxiaVariant ( treatmentId ) ,
378401 } ,
402+ renderingTarget ,
379403 ) ;
380- window . guardian . modules . sentry . reportError (
381- errorReport ,
382- 'sign-in-gate' ,
383- ) ;
384- } ) ;
385-
386- void submitComponentEventTracking (
387- {
388- component : {
389- componentType : 'SIGN_IN_GATE' ,
390- id : treatmentId ,
391- } ,
392- action : 'VIEW' ,
393- abTest : buildAbTestTrackingAuxiaVariant ( treatmentId ) ,
394- } ,
395- renderingTarget ,
396- ) ;
397404
398- // Once the gate is being displayed we need to update
399- // the tracking of the number of times the gate has been displayed
400- incrementGateDisplayCount ( ) ;
401- } , [ componentId ] ) ;
405+ // Once the gate is being displayed we need to update
406+ // the tracking of the number of times the gate has been displayed
407+ incrementGateDisplayCount ( ) ;
408+ }
409+ } , [ componentId , hasBeenSeen ] ) ;
402410
403411 return (
404- < >
412+ < div ref = { setNode } >
405413 < SignInGateAuxiaV1
406414 guUrl = { host }
407415 signInUrl = { signInUrl }
@@ -417,6 +425,6 @@ const ShowSignInGateAuxia = ({
417425 userTreatment = { userTreatment }
418426 logTreatmentInteractionCall = { logTreatmentInteractionCall }
419427 />
420- </ >
428+ </ div >
421429 ) ;
422430} ;
0 commit comments