import { useEffect , useState } from 'react' ; declare global { interface Window { hj : any ; } } async function renderScript ( ) { return new Promise < boolean > ( resolve => { ( function ( h , o , t , j , a , r ) { h . hj = h . hj || function ( ) { ( h . hj . q = h . hj . q || [ ] ) . push ( arguments ) ; } ; h . _hjSettings = { hjid : 3858 , hjsv : 6 } ; a = o . getElementsByTagName ( 'head' ) [ 0 ] ; r = o . createElement ( 'script' ) ; r . async = true ; r . src = t + h . _hjSettings . hjid + j + h . _hjSettings . hjsv ; a . appendChild ( r ) ; } ) ( window , document , '//static.hotjar.com/c/hotjar-' , '.js?sv=' ) ; resolve ( true ) ; } ) ; } const heatMapTrigger = ( triggerName ) : void => { try { window . hj ( 'trigger' , triggerName ) ; } catch ( e ) { } } ; const useHotjar = ( shouldRender , triggerName ? ) => { const [ rendered , setRendered ] = useState ( false ) ; useEffect ( ( ) => { if ( shouldRender && ! rendered ) { renderScript ( ) . then ( ( ) => { setRendered ( true ) ; if ( triggerName ) { heatMapTrigger ( triggerName ) ; } } ) ; } if ( rendered && triggerName ) { heatMapTrigger ( triggerName ) ; } } , [ ] ) ; } ; export default useHotjar ;