services/tracking/GeneralPageTracking.jsxjavascript
import React from "react";
import { useLocation } from "react-router";
import { resolveModeForPath } from "../presentationModes";
const BASE_TITLE = "SIAG ES Digital Exhibitions";
// "/rad-enablement/cancer-2" -> "Rad Enablement - cancer-2", "/" -> base title
const titleForPath = (pathname) => {
const mode = resolveModeForPath(pathname);
if (!mode) return BASE_TITLE;
const viewId = pathname.slice(mode.path.length + 1);
return viewId ? `${mode.label} - ${viewId}` : mode.label;
};
/**
* Invisible helper mounted next to the routes (see Routes.jsx): keeps
* `document.title` in sync with the current route. Page-view tracking itself
* is handled implicitly by the analytics SDK's History API listener (see
* services/analytics/AnalyticsSDK.js) - no explicit tracking call needed here.
*/
export const GeneralPageTracking = () => {
const location = useLocation();
React.useEffect(() => {
document.title = titleForPath(location.pathname);
}, [location]);
return null;
};