[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

How to detect a user has left a website

Posted on 2010-11-15
16
Medium Priority
?
568 Views
Last Modified: 2012-05-10
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
Comment
Question by:countrymeister
  • 6
  • 4
  • 2
  • +2
14 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34142915
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
 
LVL 1

Author Comment

by:countrymeister
ID: 34142950
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
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 34143048
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 1

Author Comment

by:countrymeister
ID: 34143090
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
 
LVL 6

Expert Comment

by:Codebot
ID: 34143239
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
 
LVL 19

Expert Comment

by:Bardobrave
ID: 34143246
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
 
LVL 1

Author Comment

by:countrymeister
ID: 34144967
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
 
LVL 6

Expert Comment

by:Codebot
ID: 34144996
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34146143
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
 
LVL 1

Author Comment

by:countrymeister
ID: 34152186
mplungjan:
can you please give me some code sample to do what you mentioned above
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34152454
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
 
LVL 1

Author Comment

by:countrymeister
ID: 34154494
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
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 1500 total points
ID: 34154601
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
 
LVL 1

Author Closing Comment

by:countrymeister
ID: 34154659
How about a B, let me know if that is OK
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

613 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question