1

This has been bothering me for a while, I think the problem is this:

  1. GA4 uses batching, i.e. a 5 second buffer to collect any events before making a network request.

  2. GA4 also uses the Beacon API i.e. sends the events asynchronously and directly. This prevents you losing your final few events when the page unloads.

Problem 1: If the 5 seconds haven't elapsed for the batching to finish, the network request isn't sent - you lose the final few events of a session.

Problem 2: Turns out that those events aren't "lost," they're actually stored somewhere and sent when the user starts a new session! More explained below:

I've set up a custom timestamp as outlined by Simo, but I've noticed that on occasion the first event of a new session will actually come from the last event of the previous session. I've only noticed this because the custom_timestamp sets the value on the client-side, i.e. when the event happens, whereas event_timestamp is the batched timestamp of when the payload hits the Google servers.

Question:

That means the batched payload is being stored somewhere (but I have no idea where, this would be helpful info too). Is there ANY way to either flush out the events on unload (as you could in UA as per Simo), or delete the local storage of these events so that I don't get rouge events being sent to new sessions?

5
  • Interesting findings. Can you join Measure Slack where Simo can look at this? I would love to confirm this wild behavior with him. Before this I was sure the batched events are sent on page unload. And GA4's documentation suggests it too. Maybe your network tab misreports them being sent or something... So it's unable to report them on page unload cuz it's closed, but it instead shows them on the next page or something? Might be a devtools thing?
    – BNazaruk
    Commented May 29 at 18:06
  • I've been on the Measure Slack waitlist for over a year now unfortunately. Let me add some more context: I'm only seeing this occur on smart TV's, we have a web app with GTM installed just like on a regular website. There's no pattern in terms of which TV's e.g. manufacturer, model or OS. I'm also observing the problem in BigQuery (rather than the network request tab as I'm unable to recreate the issue manually), so its not a dev tools issue. Commented May 30 at 13:08
  • very interesting. Never implemented any tracking in smart tvs, but if it's just a web app, it shouldn't matter whether this is a tv or not. I asked the measure chat why you're not through yet. I presume you've put your name and linkedin profile there and your name there is the same as here.
    – BNazaruk
    Commented May 30 at 19:28
  • Ok Viral, seems like they approved your initial registration, but then you tried to register with other emails, and they don't allow duplicate accounts (they pay for every account because slack). They suggest you use this form: docs.google.com/forms/d/e/… to change your email. The email to change is v****.m*****@threewhiskey.com
    – BNazaruk
    Commented May 31 at 0:12
  • Wow much much appreciated, I didn't know that was possible! Submitted now so hopefully it'll be sorted soon. I'll try picking up the conversation from where you left it. Thanks again :) Commented May 31 at 11:30

0