Repository navigation
Expand file tree
/
Copy pathAPI.php
More file actions
65 lines (57 loc) · 1.92 KB
/
Copy pathAPI.php
File metadata and controls
65 lines (57 loc) · 1.92 KB
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
<?php
/**
* IPGeolocation.io plugin for Matomo
*
* @link https://ipgeolocation.io
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\IPGeolocation;
use Piwik\Archive;
use Piwik\DataTable;
use Piwik\Piwik;
use Piwik\Plugins\IPGeolocation\Columns\TrafficType;
use Piwik\Plugins\IPGeolocation\RecordBuilders\TrafficTypes;
/**
* Reports of the IPGeolocation.io plugin.
*
* @method static \Piwik\Plugins\IPGeolocation\API getInstance()
*/
class API extends \Piwik\Plugin\API
{
/**
* Visits per traffic type: bot, Tor, known attacker, residential proxy,
* proxy, VPN, relay, corporate gateway, hosting, not flagged. Visits recorded
* without an IP Security, Residential Proxy or IP Hosting database are shown
* as "Not checked".
*
* @param int $idSite
* @param string $period
* @param string $date
* @param bool|string $segment
* @return DataTable|DataTable\Map
*/
public function getTrafficType($idSite, $period, $date, $segment = false)
{
Piwik::checkUserHasViewAccess($idSite);
$archive = Archive::build($idSite, $period, $date, $segment);
$dataTable = $archive->getDataTable(TrafficTypes::RECORD_NAME);
// rows are labelled with the stored number; 0 = visits recorded without a traffic database
$dataTable->filter('AddSegmentValue', [
function ($label) {
return TrafficType::toType($label);
},
]);
$dataTable->filter('ColumnCallbackReplace', [
'label',
function ($label) {
if ($label == DataTable::LABEL_SUMMARY_ROW) {
return $label;
}
return TrafficType::label($label);
},
]);
$dataTable->queueFilter('ReplaceColumnNames');
$dataTable->queueFilter('ReplaceSummaryRowLabel');
return $dataTable;
}
}