Skip to main content
Solved

Force flush?


Forum|alt.badge.img+1

Is there a way to force amplitude-js to flush events? I’m trying to track an event that triggers a browser refresh, but the logEvent calls just prior to the reload are lost... This is true even if I move the browser refresh into the callback provided to logEvent.

Best answer by Denis Holmes

Hi @ejain-bloom ,

 

I believe with the JS SDK you can use the method amplitude.getInstance().sendEvents() to send any events early. There is some documentation available here for that. Is this what you were looking for? Let me know if it is not and I can ask our Engineers internally.

Kind Regards.,
Denis

View original
Did this topic help you find an answer to your question?

6 replies

Denis Holmes
Team Member
Forum|alt.badge.img+8
  • Team Member
  • 448 replies
  • Answer
  • July 23, 2021

Hi @ejain-bloom ,

 

I believe with the JS SDK you can use the method amplitude.getInstance().sendEvents() to send any events early. There is some documentation available here for that. Is this what you were looking for? Let me know if it is not and I can ask our Engineers internally.

Kind Regards.,
Denis


Forum|alt.badge.img+1
  • Author
  • Helpful Hero
  • 8 replies
  • July 23, 2021

I’ve tried both sendEvents() as well as doing the call to window.location.reload() from the optional logEvent callback, but in both cases the last event is lost :cry:


Denis Holmes
Team Member
Forum|alt.badge.img+8
  • Team Member
  • 448 replies
  • July 26, 2021

Hi @ejain-bloom ,

 

So it works but not for the last event? Can you private message me your amplitude email so I that I can create a ticket and investigate this internally for you? Thank you!


Forum|alt.badge.img+1
  • Author
  • Helpful Hero
  • 8 replies
  • July 26, 2021

I don’t think there is any guarantee that events will have been sent when sendEvents() returns; for that to work, this function would have to return a promise (or accept a callback)...


Jeremie Gluckman
Team Member
Forum|alt.badge.img+9

Hi @ejain-bloom, I hope all is well. I wanted to close the loop here. Were you able to resolve this? I’m looping in platform specialist @ning.chang, who can take a closer look if needed. We appreciate your patience! :relaxed:


Forum|alt.badge.img+1
  • Author
  • Helpful Hero
  • 8 replies
  • February 10, 2022

Thanks for following up! I ended up configuring Amplitude with transport: "beacon". It’s possible that there are drawbacks, but it does seem to work...


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings