graphEvolutionVisitFrequency = $this->getEvolutionGraph(true, array('nb_visits_returning'));
$this->setSparklinesAndNumbers($view);
return $view->render();
}
public function getSparklines()
{
$view = new View('@VisitFrequency/getSparklines');
$this->setSparklinesAndNumbers($view);
return $view->render();
}
public function getEvolutionGraph($fetch = false, array $columns = array())
{
if (empty($columns)) {
$columns = Common::getRequestVar('columns');
$columns = Piwik::getArrayFromApiParameter($columns);
}
$documentation = Piwik::translate('VisitFrequency_ReturningVisitsDocumentation') . '
'
. Piwik::translate('General_BrokenDownReportDocumentation') . '
'
. Piwik::translate('VisitFrequency_ReturningVisitDocumentation');
// Note: if you edit this array, maybe edit the code below as well
$selectableColumns = array(
// columns from VisitFrequency.get
'nb_visits_returning',
'nb_actions_returning',
'nb_actions_per_visit_returning',
'bounce_rate_returning',
'avg_time_on_site_returning',
// columns from VisitsSummary.get
'nb_visits',
'nb_actions',
'nb_actions_per_visit',
'bounce_rate',
'avg_time_on_site'
);
$period = Common::getRequestVar('period', false);
if ($period == 'day') {
// add number of unique (returning) visitors for period=day
$selectableColumns = array_merge(
array($selectableColumns[0]),
array('nb_uniq_visitors_returning'),
array_slice($selectableColumns, 1, -4),
array('nb_uniq_visitors'),
array_slice($selectableColumns, -4));
}
$view = $this->getLastUnitGraphAcrossPlugins($this->pluginName, __FUNCTION__, $columns,
$selectableColumns, $documentation);
return $this->renderView($view);
}
protected function setSparklinesAndNumbers($view)
{
$view->urlSparklineNbVisitsReturning = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('nb_visits_returning')));
$view->urlSparklineNbActionsReturning = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('nb_actions_returning')));
$view->urlSparklineActionsPerVisitReturning = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('nb_actions_per_visit_returning')));
$view->urlSparklineAvgVisitDurationReturning = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('avg_time_on_site_returning')));
$view->urlSparklineBounceRateReturning = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('bounce_rate_returning')));
$dataTableFrequency = $this->getSummary();
$dataRow = $dataTableFrequency->getFirstRow();
$nbVisitsReturning = $dataRow->getColumn('nb_visits_returning');
$view->nbVisitsReturning = $nbVisitsReturning;
$view->nbActionsReturning = $dataRow->getColumn('nb_actions_returning');
$view->nbActionsPerVisitReturning = $dataRow->getColumn('nb_actions_per_visit_returning');
$view->avgVisitDurationReturning = $dataRow->getColumn('avg_time_on_site_returning');
$nbBouncedReturningVisits = $dataRow->getColumn('bounce_count_returning');
$view->bounceRateReturning = Piwik::getPercentageSafe($nbBouncedReturningVisits, $nbVisitsReturning);
}
protected function getSummary()
{
$requestString = "method=VisitFrequency.get&format=original";
$request = new Request($requestString);
return $request->process();
}
}