Support Drupal's built in statistics module.

patchak - April 3, 2009 - 10:20
Project:Boost
Version:6.x-1.x-dev
Component:Core compatibility
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

hey there, I was wondering if this module would still count page views on the site? I would love to install Boost, but I really need to keep counting node views on the whole site, is this possible with statistics module or maybe the new Quickstats module??

If this is not doable now, are there any ways this would be doable using custom code?

thanks a lot
Patchak

#1

andreiashu - April 3, 2009 - 11:51
Status:active» by design

Boost works by caching/saving the html output of a page, so after it is generated the (anonymous) users that visit that page will get the static html of that page.
So, short answer: no, page views will not work properly with boost. It will count the number of authenticated views for that node but it won't count the anonymous users that viewed that node.

#2

mikeytown2 - April 7, 2009 - 01:27

#3

mikeytown2 - June 7, 2009 - 06:05
Title:Do we still get number of page views?» Support Drupal's built in statistics module.
Category:support request» feature request
Status:by design» active

http://groups.drupal.org/node/22573
This would most likely be implemented as a separate module. It's no longer "hard to do" in my mind...

#4

mikeytown2 - June 19, 2009 - 21:23

<?php
//prime php for background operations
ob_end_clean();
header("Connection: close");
ignore_user_abort();

// output of 1 pixel transparent gif
ob_start();
header("Content-type: image/gif");
header("Expires: Wed, 11 Nov 1998 11:11:11 GMT");
header("Cache-Control: no-cache");
header("Cache-Control: must-revalidate");
header("Content-Length: 45");
header("Connection: close");
printf ("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",71,73,70,56,57,97,1,0,1,0,128,255,0,192,192,192,0,0,0,33,249,4,1,0,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59);
ob_end_flush();
flush();

// Do background processing here  - Connect to DB and set stats.
?>

call via
img src='boost_image.php?id=***'

#5

mikeytown2 - June 20, 2009 - 07:52

This is where the magic happens; all I need is the NID
http://api.drupal.org/api/function/statistics_exit
Supporting the access log would be hard to do; would have to get the referrer via javascript most likely.

Once basic stats is working, see if any other modules can easily be supported as well.
http://drupal.org/project/modules?filters=drupal_core:87%20tid:119&solrs...

Untested Code Below!
boost_image.php would go into website root (2nd half of the code).

<?php
 
include_once './includes/bootstrap.inc';
 
drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);

  if (
variable_get('statistics_count_content_views', 0)) {
   
// We are counting content views.
   
if (is_numeric($_GET['nid'])) {
     
// A node has been viewed, so update the node's counters.
     
db_query('UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d', time(), $_GET['nid']);
     
// If we affected 0 rows, this is the first time viewing the node.
     
if (!db_affected_rows()) {
       
// We must create a new row to store counters for the new node.
       
db_query('INSERT INTO {node_counter} (nid, daycount, totalcount, timestamp) VALUES (%d, 1, 1, %d)', $_GET['nid'], time());
      }
    }
  }
?>

Then insert the image code into each node (http://api.drupal.org/api/function/hook_footer)

<?php
function boost_footer() {
  if ((
arg(0) == 'node') && is_numeric(arg(1)) && arg(2) == '' && boost_is_cacheable($GLOBALS['_boost_path'])) {
    return
'<img src="boost_image.php?nid=' . arg(1) . '" />';
  }
}
?>

#6

mikeytown2 - June 20, 2009 - 23:11
Status:active» needs review

Session & referrer not set correctly in access log.

<?php
//Script should take under 1mb of memory to work.
//prime php for background operations
ob_end_clean();
header("Connection: close");
ignore_user_abort();

// output of 1 pixel transparent gif
ob_start();
header("Content-type: image/gif");
header("Expires: Wed, 11 Nov 1998 11:11:11 GMT");
header("Cache-Control: no-cache");
header("Cache-Control: must-revalidate");
header("Content-Length: 45");
header("Connection: close");
printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",71,73,70,56,57,97,1,0,1,0,128,255,0,192,192,192,0,0,0,33,249,4,1,0,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59);
ob_end_flush();
flush();

// Do background processing here  - Connect to DB and set stats.
include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);

$count_views = db_fetch_array(db_query_range("SELECT value FROM {variable} WHERE name = '%s'", 'statistics_count_content_views', 0, 1));
$count_views = unserialize($count_views['value']);
$access_log = db_fetch_array(db_query_range("SELECT value FROM {variable} WHERE name = '%s'", 'statistics_enable_access_log', 0, 1));
$access_log = unserialize($access_log['value']);

if (
$count_views) {
 
// We are counting content views.
 
if (isset($_GET['nid']) && is_numeric($_GET['nid'])) {
   
// A node has been viewed, so update the node's counters.
   
db_query('UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d', time(), $_GET['nid']);
   
// If we affected 0 rows, this is the first time viewing the node.
   
if (!db_affected_rows()) {
     
// We must create a new row to store counters for the new node.
     
db_query('INSERT INTO {node_counter} (nid, daycount, totalcount, timestamp) VALUES (%d, 1, 1, %d)', $_GET['nid'], time());
    }
  }
}

if (
$access_log && isset($_GET['title']) && isset($_GET['q'])) {
 
// Log this page access.
 
db_query("INSERT INTO {accesslog} (title, path, url, hostname, uid, sid, timer, timestamp) values('%s', '%s', '%s', '%s', %d, '%s', %d, %d)", urldecode($_GET['title']), $_GET['q'], referer_uri(), ip_address(), 0, 'none', 0, time());
}
exit;
?>

<?php
/**
* Implementation of hook_footer().
*
* Place boost image into pages footer.
*/
function boost_footer() {
  Global
$base_url;
  if (!(  
strpos($_SERVER['SCRIPT_FILENAME'], 'index.php') === FALSE
     
|| variable_get('site_offline', 0)
      ||
$_SERVER['REQUEST_METHOD'] != 'GET'
     
|| $_SERVER['SERVER_SOFTWARE'] === 'PHP CLI'
     
|| !BOOST_ENABLED
     
|| isset($_GET['nocache'])
      || !
boost_is_cacheable($GLOBALS['_boost_path'])
      || !empty(
$user->uid)
      || !
file_exists('boost_image.php')
      )) {
    if (
arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '' && variable_get('statistics_count_content_views', 0)) {
     
$nid = arg(1);
    }
    if ((
variable_get('statistics_enable_access_log', 0)) && (module_invoke('throttle', 'status') == 0)) {
     
$title = drupal_urlencode(strip_tags(drupal_get_title()));
     
$q = $_GET['q'];
    }

    if (isset(
$nid) & !isset($title)) {
      return
'<img src="'. $base_url . '/boost_image.php?nid=' . $nid . '" />';
    }
    elseif (isset(
$nid) & isset($title)) {
      return
'<img src="'. $base_url . '/boost_image.php?nid=' . $nid . '&q=' . $q . '&title=' . $title . '" />';
    }
    elseif (!isset(
$nid) & isset($title)) {
      return
'<img src="'. $base_url . '/boost_image.php?q=' . $q . '&title=' . $title . '" />';
    }
  }
}
?>

#7

mikeytown2 - June 21, 2009 - 01:13

Javascript referrer, something like this

if (document.referrer != '') {
  document.write('<img src="...&referer=' + document.referrer + '" />')
}

#8

mikeytown2 - June 21, 2009 - 01:33
Status:needs review» fixed

javascript referrer not added.
committed.

#9

mikeytown2 - June 22, 2009 - 10:56
Status:fixed» needs work
AttachmentSize
boost.module.patch 2.24 KB

#10

mikeytown2 - June 23, 2009 - 00:25
Status:needs work» fixed

committed.

Using javascript for referer should be in a new issue.

#11

System Message - July 7, 2009 - 00:30
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.