Accountant of Visits

Asked

Viewed 1,509 times

-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

    Check it out, you might be interested in: https://answall.com/a/267430/8063

  • 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.

  • 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.

  • You want to count "unique" visits, I assume.

2 answers

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:

  • Visits from previous days
  • Visits by technology (whether mobile or desktop)
  • Visits by region and country
  • Origin of the visits (from where the user found his site)

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.

Configuring gtag.js:

  1. Sign in to your Analytics account.
  2. Click on Admin.
  3. Select an account from the menu in the ACCOUNT column.
  4. Select a property from the menu in the PROPERTY column.
  5. Under PROPERTY, click Tracking Information > Tracking Code. The Tracking ID is displayed at the top of the page.
  6. Fragment of the tracking code
  7. 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

You are not signed in. Login or sign up in order to post.