Learn business growth with Google Analytics 4 Forums Google Analytics 4 Troubleshooting issue with Google Analytics 4 and virtual page views Reply To: Troubleshooting issue with Google Analytics 4 and virtual page views

  • Robert

    Member
    26 June 2023 at 11:51 am

    Currently, Google Analytics 4 (GA4) may not automatically recognize page views when using HashRouter from React Router. This issue might be caused by GA4 not detecting changes in the URL fragment as new page views. GA4’s automatic page view tracking works based on the history API, that is, when the browser’s actual URL is changing, not the hash fragment. For single page applications (SPAs) that use the hash fragment to manage routing, like your setup, GA4 does not understand these as separate page views and does not automatically fire the page_view event.

    While sending page view events manually might not be the ideal situation, it is currently the most effective way to get virtual page views tracked in GA4 when using HashRouter. You can do this by firing a custom page_view event whenever a route changes in your application by using available React Router functionality.