0

I'm trying to track a data of users dropping off from my multi-step join flow that uses the same url. I'm using React to render on front end so if someone goes to other pages by clicking any links on the page, I can use componentWillUnmount to tricker an action, but componentWillUnount won't be called on browser close or navigating to other websites.

It looks like I can use eventlistener on beforeunload to use callback function to track drop off on that case, but it seems like it's not working in my backend. Any suggestions?

Code is below for reference:

componentDidMount(){
   window.addEventListener('beforeunload', this.onWindowClose.bind(this))
}

 componentWillUnmount(){
    this.markDropOffData();
    window.removeEventListener('beforeunload', this.onWindowClose.bind(this));
 }

onWindowClose(e) {
   e.preventDefault();
   this.markDropOffData();
 }
Eric Cheon
  • 33
  • 1
  • 6
  • your backend has nothing to do with your browser window / tab. You also do not have to bind that `onWindowClose` method. This topic is about your needs: https://stackoverflow.com/questions/3888902/detect-browser-or-tab-closing – messerbill Sep 25 '19 at 17:36
  • Possible duplicate of [Detect browser or tab closing](https://stackoverflow.com/questions/3888902/detect-browser-or-tab-closing) – messerbill Sep 25 '19 at 17:36

0 Answers0