@dotcms/analytics
Version:
Official JavaScript library for Content Analytics with DotCMS.
20 lines (19 loc) • 620 B
JavaScript
import { useRef as r, useEffect as i } from "react";
import { isInsideEditor as u } from "../../dotAnalytics/shared/dot-content-analytics.utils.js";
function s(t) {
const n = r(null);
i(() => {
if (!t)
return;
function e() {
const o = window.location.pathname;
o !== n.current && !u() && 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 {
s as useRouterTracker
};