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
|
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\CoreHome\Columns;
use Piwik\Metrics\Formatter;
use Piwik\Piwik;
use Piwik\Plugin\Dimension\VisitDimension;
use Piwik\Tracker\Action;
use Piwik\Tracker\Request;
use Piwik\Tracker\Visitor;
class VisitorReturning extends VisitDimension
{
const IS_RETURNING_CUSTOMER = 2;
const IS_RETURNING = 1;
const IS_NEW = 0;
protected $columnName = 'visitor_returning';
protected $columnType = 'TINYINT(1) NULL';
protected $segmentName = 'visitorType';
protected $nameSingular = 'General_VisitType';
protected $namePlural = 'General_VisitTypes';
protected $conversionField = true;
protected $type = self::TYPE_ENUM;
public function __construct()
{
$this->acceptValues = 'new, returning, returningCustomer. ';
$this->acceptValues .= Piwik::translate('General_VisitTypeExample', '"&segment=visitorType==returning,visitorType==returningCustomer"');
$this->sqlFilterValue = function ($type) {
if (is_numeric($type)) {
return $type;
}
return $type == "new" ? 0 : ($type == "returning" ? 1 : 2);
};
}
public function formatValue($value, $idSite, Formatter $formatter)
{
if ($value === 1 || $value === '1' || $value === 'returning') {
return Piwik::translate('CoreHome_VisitTypeReturning');
} elseif ($value === 2 || $value === '2' || $value === 'returningCustomer'){
return Piwik::translate('CoreHome_VisitTypeReturningCustomer');
} elseif ($value === 0 || $value === '0' || $value === 'new'){
return Piwik::translate('General_New');
}
return $value;
}
public function getEnumColumnValues()
{
return array(
self::IS_RETURNING_CUSTOMER => 'returningCustomer',
self::IS_RETURNING => 'returning',
self::IS_NEW => 'new',
);
}
/**
* @param Request $request
* @param Visitor $visitor
* @param Action|null $action
* @return mixed
*/
public function onNewVisit(Request $request, Visitor $visitor, $action)
{
$hasOrder = $visitor->getVisitorColumn('visitor_seconds_since_order')
?: $visitor->getPreviousVisitColumn('visitor_seconds_since_order')
?: $request->getParam('ec_id');
$isReturningCustomer = (bool) $hasOrder;
if ($isReturningCustomer) {
return self::IS_RETURNING_CUSTOMER;
}
if ($visitor->isVisitorKnown()) {
return self::IS_RETURNING;
}
return self::IS_NEW;
}
/**
* @param Request $request
* @param Visitor $visitor
* @param Action|null $action
* @return mixed
*/
public function onAnyGoalConversion(Request $request, Visitor $visitor, $action)
{
return $visitor->getVisitorColumn($this->columnName);
}
}
|