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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
<?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$
*
* @package Piwik_VisitorInterest
*/
/**
*
* @package Piwik_VisitorInterest
*/
class Piwik_VisitorInterest extends Piwik_Plugin
{
public function getInformation()
{
$info = array(
'name' => 'VisitorInterest',
'description' => 'Reports about the Visitor Interest: number of pages viewed, time spent on the Website.',
'author' => 'Piwik',
'homepage' => 'http://piwik.org/',
'version' => '0.1',
);
return $info;
}
protected $timeGap = array(
array(0, 0.5),
array(0.5, 1),
array(1, 2),
array(2, 4),
array(4, 6),
array(6, 8),
array(8, 11),
array(11, 15),
array(15)
);
protected $pageGap = array(
array(1, 1),
array(2, 2),
array(3, 3),
array(4, 4),
array(5, 5),
array(6, 7),
array(8, 10),
array(11, 14),
array(15, 20),
array(20)
);
function postLoad()
{
Piwik_AddWidget( 'VisitorInterest', 'getNumberOfVisitsPerVisitDuration', Piwik_Translate('VisitorInterest_WidgetLengths'));
Piwik_AddWidget( 'VisitorInterest', 'getNumberOfVisitsPerPage', Piwik_Translate('VisitorInterest_WidgetPages'));
Piwik_RenameMenuEntry('Visitors', Piwik_Translate('VisitFrequency_SubmenuFrequency'),
'Visitors', Piwik_Translate('VisitorInterest_SubmenuFrequencyLoyalty') );
Piwik_AddAction('template_headerVisitsFrequency', array('Piwik_VisitorInterest','headerVisitsFrequency'));
Piwik_AddAction('template_footerVisitsFrequency', array('Piwik_VisitorInterest','footerVisitsFrequency'));
}
function getListHooksRegistered()
{
$hooks = array(
'ArchiveProcessing_Day.compute' => 'archiveDay',
'ArchiveProcessing_Period.compute' => 'archiveMonth',
);
return $hooks;
}
function archiveMonth( $notification )
{
$archiveProcessing = $notification->getNotificationObject();
$dataTableToSum = array(
'VisitorInterest_timeGap',
'VisitorInterest_pageGap',
);
$archiveProcessing->archiveDataTable($dataTableToSum);
}
public function archiveDay( $notification )
{
$this->archiveProcessing = $notification->getNotificationObject();
$recordName = 'VisitorInterest_timeGap';
$tableTimegap = $this->getTableTimeGap();
$record = new Piwik_ArchiveProcessing_Record_BlobArray($recordName, $tableTimegap->getSerialized());
$recordName = 'VisitorInterest_pageGap';
$tablePagegap = $this->getTablePageGap();
$record = new Piwik_ArchiveProcessing_Record_BlobArray($recordName, $tablePagegap->getSerialized());
}
protected function getTablePageGap()
{
$select = array();
foreach($this->pageGap as $gap)
{
if(count($gap) == 2)
{
$minGap = $gap[0];
$maxGap = $gap[1];
$gapName = "'$minGap-$maxGap'";
$select[] = "sum(case when visit_total_actions between $minGap and $maxGap then 1 else 0 end) as $gapName ";
}
else
{
$minGap = $gap[0];
$plusEncoded = urlencode('+');
$gapName = "'".$minGap.$plusEncoded."'";
$select[] = "sum(case when visit_total_actions > $minGap then 1 else 0 end) as $gapName ";
}
}
$toSelect = implode(" , ", $select);
return $this->archiveProcessing->getSimpleDataTableFromSelect($toSelect, Piwik_Archive::INDEX_NB_VISITS);
}
protected function getTableTimeGap()
{
$select = array();
foreach($this->timeGap as $gap)
{
if(count($gap) == 2)
{
$minGap = $gap[0] * 60;
$maxGap = $gap[1] * 60;
$gapName = "'".$minGap."-".$maxGap."'";
$select[] = "sum(case when visit_total_time between $minGap and $maxGap then 1 else 0 end) as $gapName ";
}
else
{
$minGap = $gap[0] * 60;
$gapName = "'$minGap'";
$select[] = "sum(case when visit_total_time > $minGap then 1 else 0 end) as $gapName ";
}
}
$toSelect = implode(" , ", $select);
$table = $this->archiveProcessing->getSimpleDataTableFromSelect($toSelect, Piwik_Archive::INDEX_NB_VISITS);
return $table;
}
public function headerVisitsFrequency($notification)
{
$out =& $notification->getNotificationObject();
$out = '<div id="leftcolumn">';
}
public function footerVisitsFrequency($notification)
{
$out =& $notification->getNotificationObject();
$out = '</div>
<div id="rightcolumn">
';
$out .= Piwik_FrontController::getInstance()->fetchDispatch('VisitorInterest','index');
$out .= '</div>';
}
}
|