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();
}