Answer the question
In order to leave comments, you need to log in
How to track user leaving the page?
Hello. Is it possible to track when a user leaves a page? For example: you need to start the execution of the method when the user leaves the new action.
def new
flash[:notice] = 'Bye' if user.leave_from_this_action
end
Answer the question
In order to leave comments, you need to log in
On the server side, you can only keep track of which pages the user is requesting.
Keep a flag in the session indicating that the user last requested the new page. If the current page is not new and the flag is up, then the user has just left. You can add time invalidation to taste, so as not to cut off cases when the user opened new, left the site and returned the next day to another page.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question