diff --git a/src/components/Layout/index.tsx b/src/components/Layout/index.tsx index f5c86d326..b19986a4a 100644 --- a/src/components/Layout/index.tsx +++ b/src/components/Layout/index.tsx @@ -37,7 +37,6 @@ import MenuIcon from "@mui/icons-material/Menu" import Typography from "@mui/material/Typography" import Login from "./Login" -import { useGAVersion } from "../../hooks" import { GAVersion, Url } from "../../constants" import Spinner from "../Spinner" import { linkData } from "./links" @@ -117,12 +116,22 @@ const Template: React.FC> = ({ user, }) => { usePageView(title) - const { gaVersion, setGAVersion } = useGAVersion(pathname) + const gaVersion = GAVersion.GoogleAnalytics4 const [open, setOpen] = React.useState(false) useEffect(() => { - //const timeout = setTimeout(() => { + const uaToGa4Redirects: { [key: string]: string } = { + "/campaign-url-builder/": "/ga4/campaign-url-builder/", + "/enhanced-ecommerce/": "/ga4/enhanced-ecommerce/", + "/": "/ga4/", + } + + const redirectPath = uaToGa4Redirects[window.location.pathname] + if (redirectPath) { + window.location.replace(redirectPath) + } + // Redirect to the new domain while preserving the path. if( window.location.hostname.indexOf('web.app') !== -1 && !window.location.hostname.includes('staging')) { const newHostname = window.location.hostname.replace('web.app', 'google'); @@ -130,12 +139,6 @@ const Template: React.FC> = ({ window.location.replace(newLocation); } - if( !window.location.search && window.location.pathname === '/' ) { - const newLocation = window.location.pathname = '/ga4/'; - window.location.replace(newLocation); - } - //}, 1000); - return; }, []); @@ -186,7 +189,7 @@ const Template: React.FC> = ({ setOpen(false)}> > = ({
  1. ( return [fromStorage, setValue] } -const uaToast = (tool: string) => `Redirecting to the UA ${tool}.` -const ga4Toast = (tool: string) => `Redirecting to the GA4 ${tool}.` - -const getRedirectInfo = ( - path: string, - version: GAVersion -): { redirectPath: string; toast: string } | undefined => { - switch (version) { - case GAVersion.UniversalAnalytics: { - switch (path) { - case "/ga4/query-explorer/": - return { - redirectPath: "/query-explorer/", - toast: uaToast("Query Explorer"), - } - case "/ga4/event-builder/": - return { - redirectPath: "/hit-builder/", - toast: uaToast("Hit Builder"), - } - case "/ga4/dimensions-metrics-explorer/": - return { - redirectPath: "/dimensions-metrics-explorer/", - toast: uaToast("Dimensions & Metrics Explorer"), - } - case "/ga4/campaign-url-builder/": - return { - redirectPath: "/campaign-url-builder/", - toast: uaToast("Campaign URL Builder"), - } - case "/ga4/campaign-url-builder/ios/": - return { - redirectPath: "/campaign-url-builder/ios/", - toast: uaToast("iOS Campaign URL Builder"), - } - case "/ga4/campaign-url-builder/play/": - return { - redirectPath: "/campaign-url-builder/play/", - toast: uaToast("play Campaign URL Builder"), - } - case "/ga4/": - return { - redirectPath: "/", - toast: "Redirecting to the UA home page.", - } - default: - return { - redirectPath: "/", - toast: "No UA demo. Redirecting to the UA home page.", - } - } - } - case GAVersion.GoogleAnalytics4: { - switch (path) { - case "/hit-builder/": - return { - redirectPath: "/ga4/event-builder/", - toast: ga4Toast("Event Builder"), - } - case "/dimensions-metrics-explorer/": - return { - redirectPath: "/ga4/dimensions-metrics-explorer/", - toast: ga4Toast("Dimensions & Metrics Explorer"), - } - case "/query-explorer/": - return { - redirectPath: "/ga4/query-explorer/", - toast: ga4Toast("Query Explorer"), - } - case "/request-composer/": - return { - redirectPath: "/ga4/query-explorer/", - toast: ga4Toast("Query Explorer"), - } - case "/campaign-url-builder/": - return { - redirectPath: "/ga4/campaign-url-builder/", - toast: ga4Toast("Campaign URL Builder"), - } - case "/campaign-url-builder/ios/": - return { - redirectPath: "/ga4/campaign-url-builder/ios/", - toast: ga4Toast("iOS Campaign URL Builder"), - } - case "/campaign-url-builder/play/": - return { - redirectPath: "/ga4/campaign-url-builder/play/", - toast: ga4Toast("Play Campaign URL Builder"), - } - case "/": - return { - redirectPath: "/ga4/", - toast: "Redirecting to the GA4 home page.", - } - default: - return { - redirectPath: "/ga4/", - toast: "No GA4 demo. Redirecting to the GA4 home page.", - } - } - } - } -} - export const useSetToast = () => { const dispatch = useDispatch() const setToast = React.useCallback( @@ -272,37 +167,6 @@ export const useSetToast = () => { export const IS_SSR = typeof window === "undefined" -export const useGAVersion = ( - pathname: string -): { - gaVersion: GAVersion - setGAVersion: (version: GAVersion) => void -} => { - const location = useLocation() - const setToast = useSetToast() - const gaVersion = React.useMemo(() => { - if (pathname.includes("/ga4/")) { - return GAVersion.GoogleAnalytics4 - } else { - return GAVersion.UniversalAnalytics - } - }, [pathname]) - - const setGAVersion = React.useCallback( - (version: GAVersion) => { - const redirectInfo = getRedirectInfo(location.pathname, version) - if (redirectInfo === undefined) { - return - } - setToast(redirectInfo.toast) - navigate(redirectInfo.redirectPath) - }, - [location.pathname, setToast] - ) - - return { gaVersion, setGAVersion } -} - export const useScrollTo = () => { const [initialLoad, setInitialLoad] = useState(true) const location = useLocation() diff --git a/src/pages/spreadsheet-add-on.tsx b/src/pages/ga4/spreadsheet-add-on.tsx similarity index 98% rename from src/pages/spreadsheet-add-on.tsx rename to src/pages/ga4/spreadsheet-add-on.tsx index 054979813..240d4105b 100644 --- a/src/pages/spreadsheet-add-on.tsx +++ b/src/pages/ga4/spreadsheet-add-on.tsx @@ -51,7 +51,7 @@ const SpreadsheetAddOn = (props: Props) => {