You are here

function hook_better_statistics_log in Better Statistics 7

Log access statistics.

This hook allows modules to route access statistics to custom destinations in custom formats such as syslog, flat files, csv, etc.

Note that Better Statistics logs access data to the Drupal {accesslog} table by default. You may wish to disable this functionality by instructing users to add a variable setting in settings.php, or manually doing so yourself by setting the global variable in hook_better_statistics_prelog().

The variable in question is "statistics_log_to_db."

Parameters

$data: An array of access statistics data keyed by field name.

Related topics

1 function implements hook_better_statistics_log()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

better_statistics_better_statistics_log in ./better_statistics.statistics.inc
Implements hook_better_statistics_log().
2 invocations of hook_better_statistics_log()
better_statistics_better_statistics_ajax in ./better_statistics.statistics.inc
Implements hook_better_statistics_ajax().
better_statistics_exit in ./better_statistics.module
Implements hook_exit().

File

./better_statistics.api.php, line 253
This file contains no working PHP code; it exists to provide additional documentation for doxygen as well as to document hooks in the standard Drupal manner.

Code

function hook_better_statistics_log($data) {

  // Send data to Google Analytics using php-ga.
  $tracker = new GoogleAnalytics\Tracker('UA-12345678-9', 'example.com');
  $session = new GoogleAnalytics\Session();
  $visitor = new GoogleAnalytics\Visitor();
  $visitor
    ->setIpAddress(ip_address());
  $page = new GoogleAnalytics\Page(request_path());
  $n = 1;
  foreach ($data as $name => $value) {
    $custom_var = new GoogleAnalytics\CustomVariable($n++, $name, $value);
    $tracker
      ->addCustomVar($custom_var);
  }
  $tracker
    ->trackPageview($page, $session, $visitor);
}