blob: 93792b1d469c3a64f531ed77f91a26f195fc6547 (
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
|
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\Provider\Columns;
use Piwik\Common;
use Piwik\IP;
use Piwik\Piwik;
use Piwik\Plugin\VisitDimension;
use Piwik\Plugin\Segment;
use Piwik\Tracker\Action;
use Piwik\Tracker\Request;
use Piwik\Tracker\Visitor;
use Piwik\Plugins\PrivacyManager\Config as PrivacyManagerConfig;
use Piwik\Plugins\Provider\Provider as ProviderPlugin;
class Provider extends VisitDimension
{
protected $fieldName = 'location_provider';
protected function init()
{
$segment = new Segment();
$segment->setSegment('provider');
$segment->setCategory('Visit Location');
$segment->setName('Provider_ColumnProvider');
$segment->setAcceptedValues('comcast.net, proxad.net, etc.');
$this->addSegment($segment);
}
/**
* @param Request $request
* @param Visitor $visitor
* @param Action|null $action
* @return mixed
*/
public function onNewVisit(Request $request, Visitor $visitor, $action)
{
// if provider info has already been set, abort
$locationValue = $visitor->getVisitorColumn('location_provider');
if (!empty($locationValue)) {
return false;
}
$ip = $visitor->getVisitorColumn('location_ip');
$privacyConfig = new PrivacyManagerConfig();
if (!$privacyConfig->useAnonymizedIpForVisitEnrichment) {
$ip = $request->getIp();
}
$ip = IP::N2P($ip);
// In case the IP was anonymized, we should not continue since the DNS reverse lookup will fail and this will slow down tracking
if (substr($ip, -2, 2) == '.0') {
Common::printDebug("IP Was anonymized so we skip the Provider DNS reverse lookup...");
return false;
}
$hostname = $this->getHost($ip);
$hostnameExtension = ProviderPlugin::getCleanHostname($hostname);
// add the provider value in the table log_visit
$locationProvider = substr($hostnameExtension, 0, 100);
return $locationProvider;
}
public function getRequiredVisitFields()
{
return array('location_ip');
}
/**
* Returns the hostname given the IP address string
*
* @param string $ip IP Address
* @return string hostname (or human-readable IP address)
*/
private function getHost($ip)
{
return trim(strtolower(@IP::getHostByAddr($ip)));
}
public function getName()
{
return Piwik::translate('Provider_ColumnProvider');
}
}
|