Answer the question
In order to leave comments, you need to log in
How can php + js accurately and easily determine that a person has visited a page (for the hit counter)?
For several pages of my site (for example, here ) I set a page visit counter (so far only in php).
Please tell me a javascript event that:
- Occurs in the browser only for humans (not for robots).
- Occurs once - so that from js to give the php-script of the counter an event only once when viewing the page - so that the script would be less twitchy.
I will clarify - the counter should only count the fact of viewing the page. Those. you need a hit count.
Answer the question
In order to leave comments, you need to log in
I have compiled a working script, please have a look.
If it can somehow be simplified or facilitated, then write, I will make corrections.
<script type="text/javascript">
var human_detected = false;//для однократного запуска функции
//3 события, каждое из которых показывает, что на странице человек
document.onmouseover = is_human_view;//нахождение мыши на документе
document.onscroll = is_human_view;//скролл
document.addEventListener("touchstart", is_human_view);//тач на мобилке
function is_human_view ()
{
if (human_detected == false)//если функция еще не запускалась
{
alert ('IS HUMAN VIEW');
human_detected = true;//уже определили просмотр страницы человеком, больше запускать фунцию не будем
}
}
</script>
- Occurs in the browser only for humans (not for robots).
- Happens once
document.addEventListener("DOMContentLoaded", function(){
//ваш ajax запрос
});
Hang a reaction to the scroll event, and in order not to send it twice, save the sending status to a variable.
99% accurate is buying something on your site. Everything else is generated by millions for free.
Regarding the question, you can count only unique sessions, do not count the same session twice.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question