1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later
* @version $Id$
*
* @category Piwik_Plugins
* @package Piwik_VisitsSummary
*/
/**
*
* @package Piwik_VisitsSummary
*/
class Piwik_VisitsSummary_Controller extends Piwik_Controller
{
public function index()
{
$view = Piwik_View::factory('index');
$this->setPeriodVariablesView($view);
$view->graphEvolutionVisitsSummary = $this->getEvolutionGraph( true, array('nb_visits') );
$this->setSparklinesAndNumbers($view);
echo $view->render();
}
public function getSparklines()
{
$view = Piwik_View::factory('sparklines');
$this->setSparklinesAndNumbers($view);
echo $view->render();
}
public function getEvolutionGraph( $fetch = false, $columns = false)
{
$view = $this->getLastUnitGraph($this->pluginName, __FUNCTION__, "VisitsSummary.get");
if(empty($columns))
{
$columns = Piwik_Common::getRequestVar('columns');
}
$columns = !is_array($columns) ? array($columns) : $columns;
$view->setColumnsToDisplay($columns);
return $this->renderView($view, $fetch);
}
static public function getVisitsSummary()
{
$requestString = "method=VisitsSummary.get".
"&format=original".
// we disable filters for example "search for pattern", in the case this method is called
// by a method that already calls the API with some generic filters applied
"&disable_generic_filters=1";
$request = new Piwik_API_Request($requestString);
return $request->process();
}
static public function getVisits()
{
$requestString = "method=VisitsSummary.getVisits".
"&format=original".
"&disable_generic_filters=1";
$request = new Piwik_API_Request($requestString);
return $request->process();
}
protected function setSparklinesAndNumbers($view)
{
$view->urlSparklineNbVisits = $this->getUrlSparkline( 'getEvolutionGraph', array('columns' => array('nb_visits')));
$view->urlSparklineNbActions = $this->getUrlSparkline( 'getEvolutionGraph', array('columns' => array('nb_actions')));
$view->urlSparklineAvgVisitDuration = $this->getUrlSparkline( 'getEvolutionGraph', array('columns' => array('avg_visit_length')));
$view->urlSparklineMaxActions = $this->getUrlSparkline( 'getEvolutionGraph', array('columns' => array('max_actions')));
$view->urlSparklineActionsPerVisit = $this->getUrlSparkline( 'getEvolutionGraph', array('columns' => array('nb_actions_per_visit')));
$view->urlSparklineBounceRate = $this->getUrlSparkline( 'getEvolutionGraph', array('columns' => array('bounce_rate')));
$dataTableVisit = self::getVisitsSummary();
$dataRow = $dataTableVisit->getFirstRow();
$view->urlSparklineNbUniqVisitors = $this->getUrlSparkline( 'getEvolutionGraph', array('columns' => array('nb_uniq_visitors')));
$view->nbUniqVisitors = $dataRow->getColumn('nb_uniq_visitors');
$nbVisits = $dataRow->getColumn('nb_visits');
$view->nbVisits = $nbVisits;
$view->nbActions = $dataRow->getColumn('nb_actions');
$view->averageVisitDuration = $dataRow->getColumn('avg_visit_length');
$nbBouncedVisits = $dataRow->getColumn('bounce_count');
$view->bounceRate = Piwik::getPercentageSafe($nbBouncedVisits, $nbVisits);
$view->maxActions = $dataRow->getColumn('max_actions');
$view->nbActionsPerVisit = $dataRow->getColumn('nb_actions_per_visit');
}
}
|