@@ -11,6 +11,8 @@ import "@cube-dev/marketing-ui/dist/index.css";
1111import localFont from "next/font/local" ;
1212import { Inter } from "next/font/google" ;
1313import { SearchProvider } from "@cube-dev/marketing-ui" ;
14+ import { useRouter } from 'next/router' ;
15+ import { useEffect } from 'react' ;
1416
1517export 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