blob: d40e51c1747ed68382c9ddce27b7a4d6695a912b (
plain)
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
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\CoreHome;
use Piwik\Metrics\Formatter;
use Piwik\Plugins\CoreHome\Columns\VisitGoalBuyer;
use Piwik\Plugins\Live\VisitorDetailsAbstract;
class VisitorDetails extends VisitorDetailsAbstract
{
public function extendVisitorDetails(&$visitor)
{
$visitor['userId'] = $this->getUserId();
$visitor['visitorType'] = $this->getVisitorReturning();
$visitor['visitorTypeIcon'] = $this->getVisitorReturningIcon();
$visitor['visitConverted'] = $this->isVisitorGoalConverted();
$visitor['visitConvertedIcon'] = $this->getVisitorGoalConvertedIcon();
$visitor['visitCount'] = $this->getVisitCount();
$visitor['visitEcommerceStatus'] = $this->getVisitEcommerceStatus();
$visitor['visitEcommerceStatusIcon'] = $this->getVisitEcommerceStatusIcon();
$visitor['daysSinceFirstVisit'] = $this->getDaysSinceFirstVisit();
$visitor['daysSinceLastEcommerceOrder'] = $this->getDaysSinceLastEcommerceOrder();
$visitor['visitDuration'] = $this->getVisitLength();
$visitor['visitDurationPretty'] = $this->getVisitLengthPretty();
}
protected function getVisitEcommerceStatusIcon()
{
$status = $this->getVisitEcommerceStatus();
if (in_array($status, array('ordered', 'orderedThenAbandonedCart'))) {
return "plugins/Morpheus/images/ecommerceOrder.svg";
} elseif ($status == 'abandonedCart') {
return "plugins/Morpheus/images/ecommerceAbandonedCart.svg";
}
// Note: it is important that there is no icon when there was no ecommerce conversion
return null;
}
protected function getVisitEcommerceStatus()
{
return VisitGoalBuyer::getVisitEcommerceStatusFromId($this->details['visit_goal_buyer']);
}
protected function isVisitorGoalConverted()
{
return $this->details['visit_goal_converted'];
}
protected function getVisitorGoalConvertedIcon()
{
return $this->isVisitorGoalConverted()
? "plugins/Morpheus/images/goal.svg"
: null;
}
protected function getDaysSinceFirstVisit()
{
return $this->details['visitor_days_since_first'];
}
protected function getDaysSinceLastEcommerceOrder()
{
return $this->details['visitor_days_since_order'];
}
protected function getVisitorReturning()
{
$type = $this->details['visitor_returning'];
return $type == 2
? 'returningCustomer'
: ($type == 1
? 'returning'
: 'new');
}
protected function getVisitorReturningIcon()
{
$type = $this->getVisitorReturning();
if ($type == 'returning'
|| $type == 'returningCustomer'
) {
return "plugins/Live/images/returningVisitor.png";
}
return null;
}
protected function getVisitCount()
{
return $this->details['visitor_count_visits'];
}
protected function getVisitLength()
{
return $this->details['visit_total_time'];
}
protected function getVisitLengthPretty()
{
$formatter = new Formatter();
return $formatter->getPrettyTimeFromSeconds($this->details['visit_total_time'], true);
}
protected function getUserId()
{
if (isset($this->details['user_id'])
&& strlen($this->details['user_id']) > 0
) {
return $this->details['user_id'];
}
return null;
}
}
|