revgems("trackPageView") when the router fires the routeChangeComplete event:
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Tips for integrating RevGems with Next.js
revgems("trackPageView") when the router fires the routeChangeComplete event:
import { useEffect } from 'react'
import { useRouter } from 'next/router'
export default function MyApp({ Component, pageProps }) {
const router = useRouter();
useEffect(() => {
let originUrl;
// Keep track of where we're navigating from (for the referrer)
const handleRouteChangeStart = (url) => {
originUrl = document.location.href;
};
const handleRouteChangeComplete = (url) => {
window.revgems('trackPageView', { referrer: originUrl }); // 👈 TRACK PAGE VIEW IN REVGEMS
};
router.events.on('routeChangeStart', handleRouteChangeStart);
router.events.on('routeChangeComplete', handleRouteChangeComplete);
// If the component is unmounted, unsubscribe from the event with the `off` method:
return () => {
router.events.off('routeChangeStart', handleRouteChangeStart);
router.events.off('routeChangeComplete', handleRouteChangeComplete);
};
}, [router.events]);
return
}