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

CommentFileSizeAuthor
#9 boost.module.patch2.24 KBmikeytown2

Comments

andreiashu’s picture

Status: Active » Closed (works as designed)

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.

mikeytown2’s picture

mikeytown2’s picture

Title: Do we still get number of page views? » Support Drupal's built in statistics module.
Category: support » feature
Status: Closed (works as designed) » 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...

mikeytown2’s picture

//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=***'

mikeytown2’s picture

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

  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)

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) . '" />';
  }
}
mikeytown2’s picture

Status: Active » Needs review

Session & referrer not set correctly in access log.

//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;
/**
 * 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 . '" />';
    }
  }
}
mikeytown2’s picture

Javascript referrer, something like this

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

Status: Needs review » Fixed

javascript referrer not added.
committed.

mikeytown2’s picture

Status: Fixed » Needs work
StatusFileSize
new2.24 KB
mikeytown2’s picture

Status: Needs work » Fixed

committed.

Using javascript for referer should be in a new issue.

Status: Fixed » Closed (fixed)

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