Experimental project
This is a sandbox project, which contains experimental code for developer use only.
I think most of the Drupal developers know the Statistics module, which makes part of the Core of D6. It basically logs access statistics for your site. Every time a node is viewed, a counter gets updated. This counter value is stored in the node_counter table, and gets reset each day at 00 AM.
The most important thing is the hook_cron() implementation.
This function will check if we are 24 hours later since the last statistics check. If we are, it will clean all node_counter values. But for us, this was pretty annoying, as we wanted to keep track of older statistics. We wanted to know, "the most viewed" nodes in the last week, month, etc, etc, ...
We started looking around for a contrib module, but really, there was no contrib module that could satisfy our requirements.
So what did we do? We created our own custom Statistics module!
* We created a custom variable which keeps track when we ran our custom statistics system the last time
* If we are 00 AM (or later), copy all values from node_counter to a custom table, and index it with a timestamp
* The structure of this table is defined as:
+----------+------------------+------+-----+---------+-------+
| FIELD | Type | NULL | KEY | DEFAULT | Extra |
+----------+------------------+------+-----+---------+-------+
| date | int(10) UNSIGNED | NO | PRI | NULL | |
| nid | int(10) UNSIGNED | NO | PRI | NULL | |
| daycount | int(10) UNSIGNED | NO | | NULL | |
+----------+------------------+------+-----+---------+-------+
* Reset the node_counter table
* Adjust the variable for cron run (Statistics module). So the "normal" Statistics cron will never run. We couldn't disable the "Statistics" module, as we were still keeping track of the views through the node_counter table :-)
Project information
- Module categories: Integrations
- Created by Jochus on , updated