Statistics_ajax in action

Description:

This module provides a way to programmatically update the {node_counter} table (provided by the core statistics module).

This module listens to a URL in the format of /statistics/ajax/[nid] where [nid] is the id of the node you are looking to update the statistics for.

Alternatives to this module:

  • Drupal 7 backport of #1209532: Count node views via AJAX in the statistics module - this was committed to Drupal 8 and has now been backported to Drupal 7 (in the 7.25 release). This Drupal 7 backport includes a lightweight bootstrap as well so will perform better on higher traffic websites.
  • Boost has a statistics component to the module, so if you are already using boost, you may not need this module. Statistics_ajax is a extremely lightweight module, and would be great if you did not want to deploy boost to your site, and still have node statistics updated through AJAX.

Installation:

Sample code:

Sample javascript code (using jQuery):

// TODO, remove the hardcoded nid
var nid = 52;
// fire AJAX
$.ajax({
url: "/statistics/ajax/" + nid,
type: "POST",
dataTypeString: "text"
});

Sample response:

The response is return in the JSON format:

Example success message:

{ "status": "success", "data": "node updated" }

Example error message:

{ "status": "error", "data": "POST is not allowed" }

Project Information

Downloads