Learn business growth with Google Analytics 4 Forums Google Analytics 4 Troubleshooting Browser Back Function with gtag.js in GA4

  • Troubleshooting Browser Back Function with gtag.js in GA4

    Posted by Leo on 11 January 2023 at 1:09 am

    Hey folks, stuck here! Need some help improving the event triggers in GA4 with DTM for one of my clients. I have added Script1 in the head section and Script2 right at the top of the body section of our website, and from what I can tell, the event is firing correctly because the clicks and views are being counted on Google Analytics realtime page and DebugView.

    But here’s a hitch: every time I click on a link and then hit the browser back button, instead of landing me back on the previous page, it takes me to the page before that. This keeps happening whenever I use the back function. Strange, isn’t it?

    I’ve noticed this problem across different platforms:

    • MacOS Google Chrome’s incognito mode and Safari
    • iOS’s versions of Google Chrome and Safari
    • Google Chrome on Android

    And interestingly, this only occurs if you don’t have a JS plugin installed on your browser. No idea why! If anyone knows how to tweak this around, would really appreciate the help.

    You can find scripts1 and scripts2 below, if that helps. Thank you in advance!

    [Here instert scripts]

    Morgan replied 10 months, 4 weeks ago 3 Members · 2 Replies
  • 2 Replies
  • Henry

    21 June 2023 at 3:46 am

    Sounds like there could be an issue with the way your scripts are interacting with the browser’s history. This often happens when something interrupts the natural flow of the “back” function. Without seeing your scripts, it’s hard to be exact, but a common issue could be that your scripts might be adding entries to the history stack, which then misleads the “back” function.

  • Morgan

    7 July 2023 at 6:06 pm

    It seems like your scripts are interfering with the browser’s ‘back’ button function. Maybe they’re adding extra history states or changing the URLs. Try to debug your scripts line by line checking how they interact with browser history. Thankfully, this problem isn’t happening when a JS plugin is installed in the browser, so the issue might be linked with how your script gets processed without the plugin.

Log in to reply.