SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
-
Oct 28, 2006, 10:23 #1
- Join Date
- Mar 2002
- Posts
- 608
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Stupid OnUnload - page visit duration Question
Hello,
I was wondering if there is a way, without using exit popups, to submit to a database using onUnload when a visitor leaves a web page. The reason is I want to track the last moment somebody is on a page before they leave the domain entirely (I can determine the last page, so that's not a factor)
Problem is, I want to know if Onunload can actually perform a command such as submit a form or hit a pixelated tracking script that is invisible to the user as they leave the page?
I know javascript can track page duration, but if one leaves the domain, how does it know when they left, is what I am asking. Thanks
-
Oct 28, 2006, 10:55 #2
- Join Date
- Jul 2005
- Location
- West Springfield, Massachusetts
- Posts
- 17,290
- Mentioned
- 198 Post(s)
- Tagged
- 3 Thread(s)
length of stay
As long as the user doesn't mess with the javascript or their time settings you could use js to get the time on page load and on page unload and POST the info to a page using hidden fields.
Big Change Coming Soon - if you want your PMs save them now!
What you need to do to prepare for our migration to Discourse
A New SitePoint Forum Experience: Our Move to Discourse
-
Oct 28, 2006, 11:04 #3
- Join Date
- Mar 2002
- Posts
- 608
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
How do I do that? is it happening after they exit?
So if I have a hidden form posting to response.php, with the value of the current time and first visit time, their exit would allow unload to submit?
I just want to make sure. I certainly don't want to use refresh (at least a visible one) or popups, so I just have to make sure.
Thanks for your time and forgive my ignorance.
-
Oct 28, 2006, 11:48 #4
- Join Date
- Jul 2005
- Location
- West Springfield, Massachusetts
- Posts
- 17,290
- Mentioned
- 198 Post(s)
- Tagged
- 3 Thread(s)
onunload
You could modify something like this to submit the POST info
HTML Code:<html> <head> <script type="text/javascript"> function winUnload(){ alert("Unloading Window"); } window.onunload = winUnload; </script> </head> <body> if you go, this page unloads <a href="http://www.sitepoint.com">Sitepoint</a> </body> </html>
Big Change Coming Soon - if you want your PMs save them now!
What you need to do to prepare for our migration to Discourse
A New SitePoint Forum Experience: Our Move to Discourse
-
Oct 28, 2006, 11:57 #5
- Join Date
- Mar 2002
- Posts
- 608
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
So in place of "alert ("unloading Window") I just have the form
submit? Interesting.Last edited by jbh; Oct 28, 2006 at 14:49.
-
Oct 28, 2006, 14:49 #6
- Join Date
- Mar 2002
- Posts
- 608
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Actually, I am a dope. It doesn't because if I use onsubmit it lands them on the submission page.
How do I physically insert that last bit of data without them going to the submit page or use a popup?
Does anybody know?
Bookmarks