@@ -49,6 +49,7 @@ const getTimeout = (
4949
5050 return 45000
5151}
52+ const exceptions = [ 'https://nosgestesclimat.fr' , 'https://jagis.beta.gouv.fr' ]
5253
5354const NPS = ( { tracking } : { tracking : string } ) => {
5455 const t = useTranslations ( 'nps' )
@@ -60,7 +61,7 @@ const NPS = ({ tracking }: { tracking: string }) => {
6061 } = useParamContext ( )
6162
6263 const [ display , setDisplay ] = useState ( false )
63- const [ blockedBySeen , setBlockedBySeen ] = useState ( false )
64+ const [ blocked , setBlocked ] = useState ( false )
6465 const timeoutRef = useRef < NodeJS . Timeout | null > ( null )
6566
6667 const [ selected , setSelected ] = useState < number | null > ( null )
@@ -70,7 +71,6 @@ const NPS = ({ tracking }: { tracking: string }) => {
7071 const [ closed , setClosed ] = useState ( false )
7172 const [ sending , setSending ] = useState ( false )
7273 const [ error , setError ] = useState ( false )
73-
7474 const send = async ( ) => {
7575 if ( sending ) {
7676 return
@@ -126,6 +126,12 @@ const NPS = ({ tracking }: { tracking: string }) => {
126126 }
127127
128128 useEffect ( ( ) => {
129+ const source = getSource ( )
130+ if ( exceptions . some ( ( exception ) => source . startsWith ( exception ) ) ) {
131+ setBlocked ( true )
132+ return
133+ }
134+
129135 const seenAtRaw = localStorage . getItem ( NPS_SEEN_STORAGE_KEY )
130136 if ( ! seenAtRaw ) {
131137 return
@@ -138,7 +144,7 @@ const NPS = ({ tracking }: { tracking: string }) => {
138144 }
139145
140146 if ( Date . now ( ) - seenAt < NPS_SEEN_TTL ) {
141- setBlockedBySeen ( true )
147+ setBlocked ( true )
142148 return
143149 }
144150
@@ -150,7 +156,7 @@ const NPS = ({ tracking }: { tracking: string }) => {
150156 clearTimeout ( timeoutRef . current )
151157 }
152158
153- if ( blockedBySeen ) {
159+ if ( blocked ) {
154160 return
155161 }
156162
@@ -159,7 +165,6 @@ const NPS = ({ tracking }: { tracking: string }) => {
159165 }
160166
161167 const timeout = getTimeout ( window . location . pathname , searchParams , { km, start, end } )
162- console . log ( 'NPS timeout set to' , timeout )
163168 timeoutRef . current = setTimeout ( ( ) => {
164169 localStorage . setItem ( NPS_SEEN_STORAGE_KEY , Date . now ( ) . toString ( ) )
165170 setDisplay ( true )
@@ -170,13 +175,13 @@ const NPS = ({ tracking }: { tracking: string }) => {
170175 clearTimeout ( timeoutRef . current )
171176 }
172177 }
173- } , [ display , tracking , searchParams , km , start , end , blockedBySeen ] )
178+ } , [ display , tracking , searchParams , km , start , end , blocked ] )
174179
175180 if ( closed ) {
176181 return null
177182 }
178183
179- if ( blockedBySeen ) {
184+ if ( blocked ) {
180185 return null
181186 }
182187
0 commit comments