Bob's Free Stuff Forum - Watch Anime Online - Debt Consolidation - Jobs search - Name tag

PDA

View Full Version : Any way of capturing the exit url when someone leaves?


mopacfan
Jun 16th 2004, 9:47 am
Does anyone know of a method to capture the url someone has clicked on when they are leaving your site? I'd like to know the destination of a visitor if they click on an ad or type in a new address. It would be helpful to know where they are going, moreso than just the url of the page they exited from.

digitalpoint
Jun 16th 2004, 9:50 am
You could do it with a JavaScript embedded on all your pages that do something based on when the user leaves. A more common way of doing it would be to make all your links clickable to a script that redirects.

mopacfan
Jun 16th 2004, 11:19 am
I use the redirect on my own web site. For the corporate site I maintain, we don't have many external links, only to our other division's sites. However, I'd like to know if a person goes back to where they came from, types in a new address or clicks on one of our division's sites (don't want to loose the anchor text links for redirection).

So, in javascript, what method would I use on the onExit function, to capture the url and store it in a database?

relaxzoolander
Jan 15th 2005, 5:54 pm
"types in a new address..."
now you are getting into privacy issues....
who do you think you are...google?
;)

phrozen_ra
Jan 18th 2005, 1:23 am
So, in javascript, what method would I use on the onExit function, to capture the url and store it in a database?


you must have a PHP that does the database job... and then from javascript you take the url of the current page stored in window.location.href into a variable

then you pase it to the PHP using an image

document.getElementById('imageid').src= 'http://path_to_php?exitURL='+window.location.href;

that should do it... from here is a PHP job

relaxzoolander
Jan 18th 2005, 9:06 pm
window.location.href does not gets its value from the address bar.
see this page:
http://www.moshbox.com/testing/window-location-href.html
change the address bar value and press the first link.
.

phrozen_ra
Jan 19th 2005, 1:33 am
:)... funny guy
you cannot, by any means cannot capture what it's written in the address bar...
you can capture that only if you press enter after you type in something new

as for the mail topic starter... if you want to track the url they click on right before they live...

instead of using window.location.href... use the url in the link they clicked on...
this means you have to redirect all the links

daboss
Jan 19th 2005, 6:54 am
you must have a PHP that does the database job... and then from javascript you take the url of the current page stored in window.location.href into a variable

then you pase it to the PHP using an image

document.getElementById('imageid').src= 'http://path_to_php?exitURL='+window.location.href;

that should do it... from here is a PHP job

or you can also use a form with a get action that calls an external php file?

greensweater
Nov 29th 2005, 1:05 pm
I found this thread while looking for a solution to this problem. Here is what I've come up with so far. No need to screw around with your link tags -- just add the image tag in your document to direct log data to the PHP script (or whatever). Works with Explorer 6 and Firefox, untested with other browsers.


<html>
<head>
<script>
document.onclick = exitURL; // route all click events
function exitURL(e) {
if (!document.getElementById) return true; // DOM only
var eTag = document.getElementById('tracker');
var uLog = '/path/to/logscript.php?url=';
var isLink = false;

if (!e) {
var e = window.event; // IE
var elmClick = e.srcElement;
} else {
var elmClick = e.target; // FF
}
while (String(elmClick.nodeName) != "A") {
elmClick=elmClick.parentNode; // up the tree
if (String(elmClick.nodeName) == "HTML") return true;
}
url = String(elmClick);
if (url.indexOf("http") != -1 && url.indexOf(location.hostname) == -1) {
eTag.onerror = function() { document.location.href = url; }
eTag.src = uLog + url;
return false; // wait for log, then leave page
}
return true; // pass back to originating object
}
</script>
</head>
<body>
<a href='http://www.example.com'>Example</a>
<img id='tracker' width=0 height=0 border=0>
</body>
</html>


All click events are routed through this function, which checks to make sure it's an anchor tag. The indexOf checks for http (non-local) links on different hostnames. The onerror event fires when the image fails to load (because it's not really an image), which then directs the browser to the requested page. Should fail cleanly on browsers that don't support it.