简体   繁体   中英

How can I detect when a visitor leaves my page/site on our corporate intranet and where they're going?

On our internal intranet, we have several embedded help files linked to from within our internal applications. I'm trying to determine whether or not the user is solely using our internal help files specific to the application or if they're visiting other resources such as our internal wiki, forums, newsletters, etc.. or possibly external sources.

I tried using onbeforeunload to return document.location.href, but it doesn't work as I need it to. For example, if the user is at internalhelp.company.com/page1.html and then leaves the page to go to internalwiki.company.com/wikipage1.php, the onbeforeunload returns internalhelp.company.com. I need it to return internalwiki.company.com.

Any help would be greatly appreciated.

Thanks.

For privacy reasons, this is totally impossible.

If you're only interested in hyperlinks, you could add a click handler to all <a> tags which sends an AJAX request telling you that the link was clicked (or use a server-side interstitial page)

As far as I know, this isn't possible to do with just JavaScript. For security reasons, JavaScript is sandboxed - in this case, it's confined to the page in which the script was loaded. You would have to use a browser extension, or something else that exists outside of the page scope.

You can set cookie for each page using javascript when they are loaded. Then when they are closed you can call window.unload function. In this function you can remove the cookie for that page. Then when there are no cookie user exits the site from browser. Can't it be implemented?

One way to get some information, IF you have administrative/content control of the help site, is to wrap a external links with your own URL that can log the user clicking out.

For example, most/all external links on Facebook are of the form:

http://www.facebook.com/l.php?u={actual URL}

This way, Facebook can log the outclick.

If you don't have access to the links on the help site, you're stuck (for privacy reasons, by design -- otherwise anyone could write JavaScript that tracks what users are doing and where they're going).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM