Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Referrers')
-rw-r--r--plugins/Referrers/Columns/Base.php56
-rw-r--r--plugins/Referrers/tests/Integration/Columns/ReferrerUrlTest.php106
2 files changed, 162 insertions, 0 deletions
diff --git a/plugins/Referrers/Columns/Base.php b/plugins/Referrers/Columns/Base.php
index 108a70a48b..b4e840656d 100644
--- a/plugins/Referrers/Columns/Base.php
+++ b/plugins/Referrers/Columns/Base.php
@@ -119,6 +119,8 @@ abstract class Base extends VisitDimension
}
}
+ $this->excludeQueryParamsFromReferrerUrl();
+
$referrerInformation = array(
'referer_type' => $this->typeReferrerAnalyzed,
'referer_name' => $this->nameReferrerAnalyzed,
@@ -137,6 +139,60 @@ abstract class Base extends VisitDimension
return $referrerInformation;
}
+ protected function excludeQueryParamsFromReferrerUrl()
+ {
+ $parametersToExclude = [];
+
+ if (!empty($this->referrerHost) && strpos($this->referrerHost, 'instagram.com') !== false) {
+ $parametersToExclude[] = 'e';
+ $parametersToExclude[] = 's';
+ }
+ if (!empty($this->referrerHost) && strpos($this->referrerHost, 'facebook.com') !== false) {
+ $parametersToExclude[] = 'h';
+ $parametersToExclude[] = 'p';
+ }
+ if (!empty($this->referrerHost) && (strpos($this->referrerHost, 'google.') !== false || strpos($this->referrerHost, 'googleusercontent.') !== false)) {
+ $parametersToExclude[] = 'ust';
+ $parametersToExclude[] = 'usg';
+ $parametersToExclude[] = 'usd';
+ $parametersToExclude[] = 'sa';
+ $parametersToExclude[] = 'sntz';
+ $parametersToExclude[] = 'ei';
+ $parametersToExclude[] = 'sa';
+ $parametersToExclude[] = 'bvm';
+ $parametersToExclude[] = 'usg';
+ $parametersToExclude[] = 'ved';
+ $parametersToExclude[] = 'client';
+ $parametersToExclude[] = 'channel';
+ }
+
+ if (!empty($this->referrerHost) && strpos($this->referrerHost, 'main.exoclick.com') !== false) {
+ $parametersToExclude[] = 'data';
+ $parametersToExclude[] = 'wpn';
+ }
+ if (!empty($this->referrerHost) && strpos($this->referrerHost, 'youtube.com') !== false) {
+ $parametersToExclude[] = 'redir_token';
+ $parametersToExclude[] = 'html_redirect';
+ $parametersToExclude[] = 'continuation';
+ $parametersToExclude[] = 'feature';
+ }
+ if (!empty($this->referrerHost) && strpos($this->referrerHost, 'bing.com') !== false) {
+ $parametersToExclude[] = 'cvid';
+ $parametersToExclude[] = 'refig';
+ $parametersToExclude[] = 'elv';
+ $parametersToExclude[] = 'plvar';
+ $parametersToExclude[] = 'setlang';
+ $parametersToExclude[] = 'qs';
+ $parametersToExclude[] = 'cc';
+ $parametersToExclude[] = 'mkt';
+ $parametersToExclude[] = 'PC';
+ $parametersToExclude[] = 'form';
+ $parametersToExclude[] = 'src';
+ }
+
+ $this->referrerUrl = PageUrl::excludeQueryParametersFromUrl($this->referrerUrl, $this->idsite, $parametersToExclude);
+ }
+
protected function getReferrerInformationFromRequest(Request $request, Visitor $visitor)
{
$referrerUrl = $request->getParam('urlref');
diff --git a/plugins/Referrers/tests/Integration/Columns/ReferrerUrlTest.php b/plugins/Referrers/tests/Integration/Columns/ReferrerUrlTest.php
new file mode 100644
index 0000000000..db02b19613
--- /dev/null
+++ b/plugins/Referrers/tests/Integration/Columns/ReferrerUrlTest.php
@@ -0,0 +1,106 @@
+<?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\Referrers\tests\Integration\Columns;
+
+use Piwik\Plugins\Referrers\Columns\ReferrerUrl;
+use Piwik\Tests\Framework\Fixture;
+use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
+use Piwik\Tracker\Cache;
+use Piwik\Tracker\Request;
+use Piwik\Tracker\Visit\VisitProperties;
+use Piwik\Tracker\Visitor;
+
+/**
+ * @group Referrers
+ * @group ReferrerUrlTest
+ * @group ReferrerUrl
+ * @group Plugins
+ */
+class ReferrerUrlTest extends IntegrationTestCase
+{
+ /**
+ * @var ReferrerUrl
+ */
+ private $referrerUrl;
+ private $idSite1 = 1;
+
+ public function setUp(): void
+ {
+ parent::setUp();
+
+ Cache::clearCacheGeneral();
+
+ $date = '2012-01-01 00:00:00';
+ $ecommerce = false;
+
+ Fixture::createWebsite($date, $ecommerce, $name = 'test1', $url = 'http://piwik.org/foo/bar');
+
+ $this->referrerUrl = new ReferrerUrl();
+ }
+
+ public function tearDown(): void
+ {
+ // clean up your test here if needed
+ Cache::clearCacheGeneral();
+
+ parent::tearDown();
+ }
+
+ /**
+ * @dataProvider getReferrerUrls
+ */
+ public function test_onNewVisit_shouldDetectCorrectReferrerUrl($referrerUrl, $expectedUrl)
+ {
+ $request = $this->getRequest(['idsite' => $this->idSite1, 'url' => 'http://piwik.org/foo/bar', 'urlref' => $referrerUrl]);
+ $detectedUrl = $this->referrerUrl->onNewVisit($request, $this->getNewVisitor(), $action = null);
+
+ $this->assertSame($expectedUrl, $detectedUrl);
+ }
+
+ public function getReferrerUrls()
+ {
+ // $referrerUrl, $expectedUrl
+ return [
+ // instagram referrer urls
+ ['https://l.instagram.com/?u=https%3A%2F%2Fexample.com%2Fexample.com&amp;e=BTPcuqWixl6Mf5hgYPp6wXIlstuaEdJssdYEvT9s8-6yme_lb275lY2Bwc-YvE-fZNtSKux4QB-v8xNk&amp;s=1',
+ 'https://l.instagram.com/?u=https%3A%2F%2Fexample.com%2Fexample.com'],
+ ['https://m.instagram.com/?u=https%3A%2F%2Fexample.com%2Fexample.com&e=BTPcuqWixl6Mf5hgYPp6wXIlstuaEdJssdYEvT9s8-6yme_lb275lY2Bwc-YvE-fZNtSKux4QB-v8xNk',
+ 'https://m.instagram.com/?u=https%3A%2F%2Fexample.com%2Fexample.com'],
+
+ // facebook referrer urls
+ ['http://l.facebook.com/l.php?u=http://www.example.com.com/&h=BL0RXrrUUyk_ZbqijDe_mVGBi3ZsyVxJEvOfIhjlUEiRy4zkKwYMDUWbuoICNzhC6pKm6zbGCPAJQP4s8e2psymaokRV3dhp7FPx4Zk6B4x0fBbYTi54xynmBsoBRFB7f5t',
+ 'http://l.facebook.com/l.php?u=http://www.example.com.com/'],
+ ['http://lm.facebook.com/l.php?u=http://example.com/foobar&h=BT2Dh3r3VDLoabL3Rb1lpmN-_s0lFtReSGzBED3kfUGnaO5fPF-x8LspJAfJN9kkee5ptpybYgyIx68yzgo9kPAN6snSZL_eNcmgu5xhuUcLXJukNKvi0XMOY78Ca9NKexnpJKxKUDeVApPcfB',
+ 'http://lm.facebook.com/l.php?u=http://example.com/foobar'],
+
+ // google referrer urls
+ ['https://www.google.com/url?q=https://example.com/foo&sa=D&ust=1689581471834000&usg=BCQjCNFw5f1S7rLgPNephpTW_4-i2KnAGA',
+ 'https://www.google.com/url?q=https://example.com/foo'],
+
+ // bing referrer urls
+ ['https://www.bing.com/search?q=foo+bar&form=EDGTCK&qs=AB&cvid=ff8399e313a74fb592b0ca1d91c42224&refig=4540178a841b46ce8de1664920449112&cc=BE&setlang=4k-NL&elv=AXXfrEiqqD9r3GuelwApuloWthKnH5oOVtTkjmeLPBeagbGxe4rwyaaV!5HJFcbCTxaO4q5w7QqvI8XbCTXyJKn1N4PzqCvVFSdBSr*sdwlB&plvar=0',
+ 'https://www.bing.com/search?q=foo+bar'],
+
+ // ensure custom url still keep those parameters
+ ['http://www.example.com/index.php?s=test&e=val&h=param&cvid=custom',
+ 'http://www.example.com/index.php?s=test&e=val&h=param&cvid=custom']
+ ];
+ }
+
+ private function getRequest($params)
+ {
+ return new Request($params);
+ }
+
+ private function getNewVisitor()
+ {
+ return new Visitor(new VisitProperties());
+ }
+
+}