@dotcms/analytics
Version:
Official JavaScript library for Content Analytics with DotCMS.
21 lines (20 loc) • 656 B
JavaScript
import { useRef as u, useEffect as i } from "react";
import { getUVEState as a } from "../../../uve/src/lib/core/core.utils.js";
import "../../../uve/src/internal/constants.js";
function p(t) {
const n = u(null);
i(() => {
if (!t)
return;
function e() {
const o = window.location.pathname, r = a();
o !== n.current && !r && t && (n.current = o, t.pageView());
}
return e(), window.addEventListener("popstate", e), window.addEventListener("beforeunload", e), () => {
window.removeEventListener("popstate", e), window.removeEventListener("beforeunload", e);
};
}, [t]);
}
export {
p as useRouterTracker
};