P
P
Pavel Shcheglov2016-01-07 09:54:40
Ruby on Rails
Pavel Shcheglov, 2016-01-07 09:54:40

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

2 answer(s)
P
Pavel Shcheglov, 2016-01-07
@hrumhrumble

before_action :some_method, except: :new

A
Alexey Ukolov, 2016-01-07
@alexey-m-ukolov

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 question

Ask a Question

731 491 924 answers to any question