-1
I want to create an online visit counter on my site, but I don’t know where to start, it weighs a lot the database? how to start?
-1
I want to create an online visit counter on my site, but I don’t know where to start, it weighs a lot the database? how to start?
4
There are good services that already do this, such as Google Analytics, which in addition to giving you the total of visits in real time will also provide you:
You will also be able to follow the user’s steps until they reach the desired goal and with this evaluate how to improve navigation to make it easier for the user to get to where you want, like finalize a purchase, or submit a form, etc.
Glue the following fragment immediately after the label <head>
on each page of the website. Substitute GA_TRACKING_ID
by his own ID
follow-up to Google Analytics:
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'GA_TRACKING_ID');
</script>
3
There are two types of analysis that you want to do the counter, try to count unique users, or try to count the total number of accesses, for this you can use test cookies or Session respectively.
To rely on cookies:
$access_test = isset($_COOKIE["access_test"]) ? $_COOKIE['access_test'] : null;
if($access_test != true){
setcookie("access_test",true);
//Aqui você adiciona mais um ao campo do contador no banco de dados
}
Or to count generally:
session_start();
$access_test = isset($_SESSION['access_test']) ? $_SESSION['access_test'] : null ;
if($access_test != true){
$_SESSION['access_test'] = true;
//Aqui você adiciona mais um ao campo do contador no banco de dados
}
OBS:
The count is not 100% accurate, just the user update the page cleaning the cache that will be counted one more, but there is no way to know accurately without having registration of each user of the site.
Browser other questions tagged php html html5
You are not signed in. Login or sign up in order to post.
Check it out, you might be interested in: https://answall.com/a/267430/8063
– Sam
I saw this post, but I do not want to counter another site, because I’m creating a portal with administrative area, I wanted the site statistics in the panel.
– Erick Pereira
I use SESSION. I see if SESSION does not exist and send to the bank a command to add +1 on visits. As SESSION lasts only a few minutes, if the user is browsing the site within the time limit of SESSION, I do not send anything to the bank, his visit will be counted as 1 while SESSION is alive.
– Sam
You want to count "unique" visits, I assume.
– Wallace Maxters