function piwik_stats_node_statistics in Piwik Statistic Integration 7
Menu callback; prints available statistics of current node.
1 string reference to 'piwik_stats_node_statistics'
- piwik_stats_menu in ./
piwik_stats.module - Implements hook_menu().
File
- ./
piwik_stats.module, line 57 - Integrates piwik statistics per node.
Code
function piwik_stats_node_statistics($type, $object, $name = NULL) {
// Get statistical data of node from database.
$select = db_select('piwik_stats', 'p');
$select
->addField('p', 'nb_visits');
$select
->addField('p', 'nb_hits');
$select
->addField('p', 'entry_nb_visits');
$select
->addField('p', 'entry_nb_actions');
$select
->addField('p', 'entry_sum_visit_length');
$select
->addField('p', 'entry_bounce_count');
$select
->addField('p', 'exit_nb_visits');
$select
->addField('p', 'sum_time_spent');
$select
->addField('p', 'avg_time_on_page');
$select
->addField('p', 'bounce_rate');
$select
->addField('p', 'exit_rate');
$select
->condition('p.nid', $object->nid);
$statistics = $select
->execute()
->fetchAll();
// Abort if no data is available.
if (empty($statistics)) {
drupal_set_message(t('There is no statistical data available for this node yet.'));
drupal_goto('node/' . $object->nid);
}
// Render it to a table.
return theme_table(array(
'header' => array(
t('Description'),
t('Value'),
),
'rows' => array(
'nb_visits' => array(
t('Unique pageviews'),
$statistics[0]->nb_visits,
),
'nb_hits' => array(
t('Pageviews'),
$statistics[0]->nb_hits,
),
'entry_nb_visits' => array(
t('Number of visits that started on a node'),
$statistics[0]->entry_nb_visits,
),
'entry_nb_actions' => array(
t('Number of page views for visits that started on that node'),
$statistics[0]->entry_nb_actions,
),
'entry_sum_visit_length' => array(
t('Time spent, by visits that started on this node'),
format_interval($statistics[0]->entry_sum_visit_length),
),
'entry_bounce_count' => array(
t('Number of visits that started on this node and bounced'),
$statistics[0]->entry_bounce_count,
),
'exit_nb_visits' => array(
t('Number of visits that finished on this node'),
$statistics[0]->exit_nb_visits,
),
'sum_time_spent' => array(
t('Total time spent on this node'),
format_interval($statistics[0]->sum_time_spent),
),
'avg_time_on_page' => array(
t('Average time spent on node'),
format_interval($statistics[0]->avg_time_on_page),
),
'bounce_rate' => array(
t('Ratio of visitors leaving the website after landing on this node'),
t('@count%', array(
'@count' => $statistics[0]->bounce_rate,
)),
),
'exit_rate' => array(
t('Ratio of visitors that do not view any other page after this node'),
t('@count%', array(
'@count' => $statistics[0]->exit_rate,
)),
),
),
'attributes' => array(
'piwik-statistics',
),
));
}