Skip to content

Commit 4f31619

Browse files
authored
docs: re-enable page-level analytics (#7021)
1 parent 652736d commit 4f31619

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

docs/docs-new/pages/_app.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import "@cube-dev/marketing-ui/dist/index.css";
1111
import localFont from "next/font/local";
1212
import { Inter } from "next/font/google";
1313
import { SearchProvider } from "@cube-dev/marketing-ui";
14+
import { useRouter } from 'next/router';
15+
import { useEffect } from 'react';
1416

1517
export const SourceCodePro = localFont({
1618
src: "../fonts/SourceCodePro-Regular.woff2",
@@ -59,7 +61,29 @@ export const CeraPro = localFont({
5961
],
6062
});
6163

62-
export default function MyApp({ Component, pageProps }: AppProps) {
64+
type Props = { origin: string | null };
65+
66+
export default function MyApp({ origin, Component, pageProps }: AppProps & Props) {
67+
const router = useRouter()
68+
69+
// Track page views
70+
useEffect(() => {
71+
const handleRouteChange = async (url) => {
72+
if (typeof window !== 'undefined') {
73+
const { page } = await import('cubedev-tracking');
74+
page();
75+
}
76+
}
77+
78+
router.events.on('routeChangeStart', handleRouteChange)
79+
80+
// If the component is unmounted, unsubscribe
81+
// from the event with the `off` method:
82+
return () => {
83+
router.events.off('routeChangeStart', handleRouteChange)
84+
}
85+
}, [router])
86+
6387
return (
6488
<SearchProvider
6589
algoliaAppId={process.env.NEXT_PUBLIC_ALGOLIA_APP_ID}

0 commit comments

Comments
 (0)