determinar cuando el usuario abandona el sitio

I want to determine when user is leaving the site using javascript. By site I means domain here.

The body unload occur before leaving any page. So it won't do the job. But is there any way to capture where the user is headed? So when the address is on another domain something is alerted by this event.

Another way, attach an onclick or onsubmit to any inner form and inner link. On this events we set a variable so on unload understand that we are going to an inner page. Maybe you suggest a script that do that automatically but without any javascript framework.

Dears, I don't want to use this as a "please, stay on my site". I want to ask those user that go to order page but anyhow can't submit and finalize the order, and leaving our site to contact us on the phone. So please don't judge it.

preguntado el 27 de agosto de 11 a las 22:08

I certainly hope not; that'd have some serious privacy concerns. -

Are you talking about links that originate FROM your site? Or just navigation away (ie, bookmarks, home button, address bar, etc...)? -

posible duplicado de Javascript function, on web page close y muchos otros. -

By your edit then, you're wanting a type of "This is an offsite link and realize you will be leaving by continuing" type of link? -

Just because they leave without finalizing an order doesn't mean they did so due to anything you can resolve. You should probably have them create an account and email them X number of days after placing an order if that's what you want to do. -

2 Respuestas

Esta pregunta is very similar, and like others I would encourage you not to do this for privacy reasons. Knowing when users leave your site is going to be near impossible; if instead you want to track when people use links on your site to dejar your site, you can impliment click tracking via various means: Piwik is one, you can also use some PHP libraries if you have the option.

Usted no puedo however check what URL a user has entered into the search bar; that would be a huge privacy invasion.

contestado el 23 de mayo de 17 a las 12:05

I don't want to know where they are going. I just want to know they are leaving by any means, maybe closing. So the second method is how to goes. Can you suggest a javascript that automatically overwrite all onclick function of As and FORMs that are internal so a variable is set. - Ali

If a user types in the URL into his browser, you have no way of knowing what was requested. If he clicks an external link, you again have no way of detecting AFAIK.

However, you can create a redirect page on your server and rewrite all links on the page to point to that page, for instance se cambia a This is how Facebook used to do it.

Respondido 28 ago 11, 02:08

Facebook still does that, doesn't it? - Bojangles

Not anymore as far as I know. Part of the reason seems to have been security-related. They used to include a "are you sure?" landing page (similar to deviantArt's), but that was vulnerable to XSS attacks. Is it possible to run a function with a link's onClick event to achieve the same purpose? - Christian Mann

Not that I know of. You could probably work some magic with AJAX, but I'm not sure. - Bojangles

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.