Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 566
  • Last Modified:

How to detect a user has left a website

I need to now when a user leaves my webiste, lets says I have a website www.xyz.com
When the user logs in to my website I record the login time, when they leave the website say by typing www.google.com.
I need to know if they hit the browser back button, they had left my website, gone somewhere else and now trying to get back.
0
countrymeister
Asked:
countrymeister
  • 6
  • 4
  • 2
  • +2
1 Solution
 
Michel PlungjanIT ExpertCommented:
That is not trivial.

There are no events triggered on back or close.

onbeforeunload can be used to ask the user if they really want to leave, but you cannot register their answer.

You can add onclicks to links to see when they leave your site by clicking an external link
0
 
countrymeisterAuthor Commented:
mplungjan:

onbeforeunload is triggered when the user navigates from  page a to page b within the website and also when the user types in a new URL and also when he closes the browser

so is there any way to track the new URL typed?
0
 
Anurag ThakurCommented:
web is working in a disconnected mode and there is no way (in my knowledge) to identify if the user after getting result from your website because what ever happens is controlled through the browser and the browser will only navigate to the new url that is typed and will not send back any information to the previous URL
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
countrymeisterAuthor Commented:
ragi0017:

i have seen quite a few websites where the user on navigating from the  URL of interest and comes back, it lets the user know that the session has been terminated.
How is this done then
0
 
CodebotCommented:
if you are using asp,asp.net or other languages use
Session_OnStart and sub Session_OnEnd functions see details here
http://www.w3schools.com/ASP/asp_globalasa.asp

or simple you can follow this as well
http://www.siteexperts.com/forums/viewConverse.asp?d_id=20684
0
 
BardobraveCommented:
In classic ASP this is made through session variables. I supose that ASP.NET would have something similar.

When a user access to your webpage a session environment is created for him. This session environment stores variables where you can assign values relative to each unique user.

Sessions and session variables has a defined life time, when a user leaves a webpage, or becomes inactive, it's session starts to die, being totally death upon reaching it's maximum duration.

On classic ASP the death of a session triggers the execution of a function in Global.asa file (session_onUnload I think... it's been a long time since last time I used it), once more I supose that should be an equivalent for ASP.NET

The time you define for your user sessions is very important, as a session doesn't dies until users pass this determinated time without navigating or interacting with your page... so if you give 20 seconds to force quick disconnects after leaving page you risk that users get disconnected when taking brief seconds reading data in one of your pages (as they become inactive for more than 20 seconds).
0
 
countrymeisterAuthor Commented:
mplungjan:

" You cannot track if they load a url in the browser except if it is another of your urls "

Do you have any code samples in doing the above

I tried to get the location.href when the type in the new URL, say I am on www.xyz.com and then I navigate to www.google.com, the onunload trigger still shows me xyz.com
0
 
CodebotCommented:
0
 
Michel PlungjanIT ExpertCommented:
You cannot track any url typed into the location bar - not even your own

What you CAN track is that you end on your site again using for example cookies.

referrer will be empty if you come from a typed url or a bookmark
0
 
countrymeisterAuthor Commented:
mplungjan:
can you please give me some code sample to do what you mentioned above
0
 
Michel PlungjanIT ExpertCommented:
I was thinking to set a cookie with a time stamp onbeforeunload and read this cookie when loading. In both cases tell the server. In the load part tell the server to ignore the previous unload if the time stamp is less than x seconds.
0
 
countrymeisterAuthor Commented:
tis is not going to work, because the user could be on the main site for say five mins and then type in google.com and then the very next min hit the back button
0
 
Michel PlungjanIT ExpertCommented:
Then please request a delete rather than giving a "C" grade which is unacceptable. I have un-accepted this question.
Please read http://www.experts-exchange.com/help.jsp?hi=403

I posted enough information for you to realise that perhaps you are on the wrong path. Just because you do not like the answers does not mean they are wrong.
0
 
countrymeisterAuthor Commented:
How about a B, let me know if that is OK
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 6
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now