window.dataLayer = window.dataLayer || []; // Function to push virtual pageview with the current URL path function gtmPageView(url) { window.dataLayer.push({ event: 'virtualPageView', page: url, }); } // Fire an initial virtual pageview for homepage load (optional, GTM snippet usually does this) gtmPageView(window.location.pathname); // Listen for Framer route changes and send virtual pageview events window.addEventListener('framerPageChange', () => { gtmPageView(window.location.pathname); }); // Fallback for history API changes (SPA navigation) const pushState = history.pushState; history.pushState = function () { pushState.apply(history, arguments); gtmPageView(window.location.pathname); }; window.addEventListener('popstate', () => { gtmPageView(window.location.pathname); });