How to count page views on a site

0

I'd like to implement a pageview counter on my site, display a numeric reference on the site, and use that data to perform a top-ranked article / post ranking and automatically insert a widget in the sidebar of the site.

Node.js solves the problem, it bridges the gap between front and back using javascript, where I am most familiar, I can access the database, be MongoBD and / or MySQL and learn a language that will dominate in the near future. Now it's dedicate to learning, let's move on!

    
asked by anonymous 10.03.2014 / 21:17

6 answers

3

To what end do you need this information? Just for analysis? If so, use Google Analytics ( link ). Then simply implement your tracking code on your site and get your information, including checking visitors in real time.

    
10.03.2014 / 21:22
2

A table (if it is the case of a relational database) with 2 basic fields, post ID and number of views should be created, it would look like this in the table

| id | id_post | qnt |
----------------------
| 30 | 000050  | 010 |
----------------------
| 31 | 000014  | 017 |
----------------------

Then you would create a script / function that every time the blog view page was called, then with the id in hand (and you should have) of the post, you would go to that function. Thus it would be incremented 1 to the registry referring to the post.

    
10.03.2014 / 23:52
1

For review you can use Google Analytics now to create your own rankin content-accessible system, you need to calculate all visits to register in a database and then display this information.

It can be done basically with any language.

    
10.03.2014 / 21:33
1

First create a page called the counter.php, it should be empty if no code is in it.

Then create another index.php file

<?php
$a = 0;
include 'contador.php';
if (isset($_COOKIE['counte'])) {
  $counte = $_COOKIE['counte'] + 1;
}else{
$counte = 1;
$a++; 
}
setcookie('counte', "$counte", time()+3700);
$abre =@fopen("contador.php","w");
 $ss ='<?php $a='.$a.'; ?>';
 $escreve =fwrite($abre, $ss);
 ?>
 <html>
 <head>Contador de Visitas</head>
 <body>

<?php 
echo "<br>$a Pessoas visitaram esse site e você já visitou" .$counte. "vezes";
?>  

 <p>Conteúdo do seu site</p>

<?php $a=0; ?>
</body>
</html>
    
10.03.2014 / 21:39
1

You can create a table in your database and each time the page is requested use a for () to add +1 to the bank record! if you want to make a single counter use cookies to save the user and do not re-register in the database if he has visited the page! Now this varies if you are going to do procedural or object oriented! This was the first logic that came to mind, but you have many ways to do it!

    
10.03.2014 / 22:44
0

If what you need can not be met by using analytics, then the best would be to use a database for this and insert a php (or server-side language you prefer) to add +1 in the number of visits from that page in the database ...

Then to pull this in a widget would just get the data from the bank ...

If there is anything missing, comment here that I will complete the answer.

    
11.03.2014 / 17:49