import{useEffect as r}from"react";import{useLocation as d}from"react-router-dom";import{telemetry as s}from"../telemetry";const g=()=>{const t=d();r(()=>{const i=()=>{if(!e)return;const a=new Date().getTime()-e;s.sendPageTimeMessage([{id:`${window.origin}${t.pathname}`,object:"page",uri:`${window.origin}${t.pathname}`,durationMs:a}]),e=void 0},n=()=>{if(document.visibilityState==="visible"){e=e||new Date().getTime();return}i()},o=()=>{i()};let e=new Date().getTime();return document.addEventListener("visibilitychange",n),window.addEventListener("beforeunload",o),()=>{i(),window.removeEventListener("beforeunload",o),document.removeEventListener("visibilitychange",n)}},[t.pathname])};export{g as usePageTimeTracker};
