From 2466e9f4447e2491faea1201c838657e2385cd94 Mon Sep 17 00:00:00 2001 From: Thomas Steur Date: Wed, 29 Apr 2020 10:54:09 +1200 Subject: Update visit only when needed (#15869) * update idvisitor only when needed * better implementation * fix tests --- plugins/CoreHome/Columns/VisitLastActionTime.php | 11 +- .../Integration/Column/VisitLastActionTimeTest.php | 121 +++++++++++++++++++++ ...wMultipleConversionsPerVisit__Goals.get_day.xml | 6 +- ...itTime.getVisitInformationPerServerTime_day.xml | 12 +- ...eConversionsPerVisit__VisitsSummary.get_day.xml | 10 +- ...ithLogLinkVisitActionSegment__Goals.get_day.xml | 6 +- 6 files changed, 148 insertions(+), 18 deletions(-) create mode 100644 plugins/CoreHome/tests/Integration/Column/VisitLastActionTimeTest.php (limited to 'plugins') diff --git a/plugins/CoreHome/Columns/VisitLastActionTime.php b/plugins/CoreHome/Columns/VisitLastActionTime.php index ed341ec673..802f9a1755 100644 --- a/plugins/CoreHome/Columns/VisitLastActionTime.php +++ b/plugins/CoreHome/Columns/VisitLastActionTime.php @@ -14,6 +14,7 @@ use Piwik\Tracker\Action; use Piwik\Tracker\Request; use Piwik\Tracker\Visitor; use Piwik\Metrics\Formatter; +use Piwik\Tracker\VisitorRecognizer; require_once PIWIK_INCLUDE_PATH . '/plugins/VisitTime/functions.php'; @@ -67,7 +68,15 @@ class VisitLastActionTime extends VisitDimension if ($request->getParam('ping') == 1) { return false; } - + + $originalVisit = $visitor->getVisitorColumn(VisitorRecognizer::KEY_ORIGINAL_VISIT_ROW); + + if (!empty($originalVisit['visit_last_action_time']) + && Date::factory($originalVisit['visit_last_action_time'])->getTimestamp() > $request->getCurrentTimestamp()) { + // make sure to not set visit_last_action_time to an earlier time eg if tracking requests aren't sent in order + return $originalVisit['visit_last_action_time']; + } + return $this->onNewVisit($request, $visitor, $action); } } \ No newline at end of file diff --git a/plugins/CoreHome/tests/Integration/Column/VisitLastActionTimeTest.php b/plugins/CoreHome/tests/Integration/Column/VisitLastActionTimeTest.php new file mode 100644 index 0000000000..d58e429960 --- /dev/null +++ b/plugins/CoreHome/tests/Integration/Column/VisitLastActionTimeTest.php @@ -0,0 +1,121 @@ +lastAction = new VisitLastActionTime(); + } + + public function tearDown() + { + parent::tearDown(); + } + + + private function makeRequest($request) + { + $request['idsite'] = 1; + + return new Request($request); + } + + private function getVisitor() + { + $visit = new VisitProperties(); + $visit->setProperty('idvisit', '321'); + $visit->setProperty('idvisitor', Common::hex2bin('1234567890234567')); + $visitor = new Visitor($visit, $isKnown = false); + + return $visitor; + } + + public function test_onExistingVisit_whenPing() + { + $request = $this->makeRequest(array('ping' => 1)); + $visitor = $this->getVisitor(); + $this->assertFalse($this->lastAction->onExistingVisit($request, $visitor, $action = null)); + } + + public function test_onExistingVisit_whenNewVisitReturnsTimeFromRequest() + { + $now = time() - 5; // -5 so we make sure this time is used and not actually now + $request = $this->makeRequest(array('cdt' => $now)); + $this->assertEquals($now, $request->getCurrentTimestamp()); + + $visitor = $this->getVisitor(); + + $expected = Date::factory($now)->getDatetime(); + $this->assertSame($expected, $this->lastAction->onExistingVisit($request, $visitor, $action = null)); + } + + public function test_onExistingVisit_whenKnownVisitRequestTimeIsNewer() + { + $now = time() - 5; // -5 so we make sure this time is used and not actually now + $previousTime = $now - 10; // is older + $request = $this->makeRequest(array('cdt' => $now)); + $this->assertEquals($now, $request->getCurrentTimestamp()); + + $visitor = $this->getVisitor(); + $visitor->setVisitorColumn(VisitorRecognizer::KEY_ORIGINAL_VISIT_ROW, + array('visit_last_action_time' => Date::factory($previousTime)->getDatetime()) + ); + + $expected = Date::factory($now)->getDatetime(); + $this->assertSame($expected, $this->lastAction->onExistingVisit($request, $visitor, $action = null)); + } + + public function test_onExistingVisit_whenKnownVisitAndPreviousVisitTimeIsNewer() + { + $now = time() - 5; // -5 so we make sure this time is used and not actually now + $previousTime = $now + 10; // is newer + $request = $this->makeRequest(array('cdt' => $now)); + $this->assertEquals($now, $request->getCurrentTimestamp()); + + $visitor = $this->getVisitor(); + $visitor->setVisitorColumn(VisitorRecognizer::KEY_ORIGINAL_VISIT_ROW, + array('visit_last_action_time' => Date::factory($previousTime)->getDatetime()) + ); + + $expected = Date::factory($previousTime)->getDatetime(); + // should keep existing visit last action time + $this->assertSame($expected, $this->lastAction->onExistingVisit($request, $visitor, $action = null)); + } +} diff --git a/plugins/Goals/tests/System/expected/test_trackGoals_allowMultipleConversionsPerVisit__Goals.get_day.xml b/plugins/Goals/tests/System/expected/test_trackGoals_allowMultipleConversionsPerVisit__Goals.get_day.xml index 27200051aa..3a8d1b2d0c 100644 --- a/plugins/Goals/tests/System/expected/test_trackGoals_allowMultipleConversionsPerVisit__Goals.get_day.xml +++ b/plugins/Goals/tests/System/expected/test_trackGoals_allowMultipleConversionsPerVisit__Goals.get_day.xml @@ -1,14 +1,14 @@ - 8 + 7 2 1332 100% - 6 + 4 1 1332 100% - 2 + 3 1 0 100% diff --git a/plugins/Goals/tests/System/expected/test_trackGoals_allowMultipleConversionsPerVisit__VisitTime.getVisitInformationPerServerTime_day.xml b/plugins/Goals/tests/System/expected/test_trackGoals_allowMultipleConversionsPerVisit__VisitTime.getVisitInformationPerServerTime_day.xml index 4a3f7b7062..c5be750480 100644 --- a/plugins/Goals/tests/System/expected/test_trackGoals_allowMultipleConversionsPerVisit__VisitTime.getVisitInformationPerServerTime_day.xml +++ b/plugins/Goals/tests/System/expected/test_trackGoals_allowMultipleConversionsPerVisit__VisitTime.getVisitInformationPerServerTime_day.xml @@ -6,9 +6,9 @@ 2 5 0 - 3 - 363 - 0 + 4 + 1121 + 1 2 @@ -22,8 +22,8 @@ 666 - 2 - 2 + 1 + 1 0 @@ -37,7 +37,7 @@ 0 - 8 + 7 1332 visitStartServerHour==0 diff --git a/plugins/Goals/tests/System/expected/test_trackGoals_allowMultipleConversionsPerVisit__VisitsSummary.get_day.xml b/plugins/Goals/tests/System/expected/test_trackGoals_allowMultipleConversionsPerVisit__VisitsSummary.get_day.xml index 7168091d51..bfbd730f69 100644 --- a/plugins/Goals/tests/System/expected/test_trackGoals_allowMultipleConversionsPerVisit__VisitsSummary.get_day.xml +++ b/plugins/Goals/tests/System/expected/test_trackGoals_allowMultipleConversionsPerVisit__VisitsSummary.get_day.xml @@ -5,10 +5,10 @@ 2 5 2 - 0 - 363 - 3 - 0% + 1 + 1121 + 4 + 50% 2.5 - 182 + 561 \ No newline at end of file diff --git a/plugins/Goals/tests/System/expected/test_trackGoals_allowMultipleConversionsPerVisit_withLogLinkVisitActionSegment__Goals.get_day.xml b/plugins/Goals/tests/System/expected/test_trackGoals_allowMultipleConversionsPerVisit_withLogLinkVisitActionSegment__Goals.get_day.xml index 27200051aa..3a8d1b2d0c 100644 --- a/plugins/Goals/tests/System/expected/test_trackGoals_allowMultipleConversionsPerVisit_withLogLinkVisitActionSegment__Goals.get_day.xml +++ b/plugins/Goals/tests/System/expected/test_trackGoals_allowMultipleConversionsPerVisit_withLogLinkVisitActionSegment__Goals.get_day.xml @@ -1,14 +1,14 @@ - 8 + 7 2 1332 100% - 6 + 4 1 1332 100% - 2 + 3 1 0 100% -- cgit v1.2.3 From 12babf7a694a2ecbbe15af93be2f859f9dc237a0 Mon Sep 17 00:00:00 2001 From: Stefan Giehl Date: Wed, 29 Apr 2020 18:25:12 +0200 Subject: Fix iso code of Brandenburg (#15882) --- plugins/UserCountryMap/svg/DEU.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/UserCountryMap/svg/DEU.svg b/plugins/UserCountryMap/svg/DEU.svg index dc2f760b63..4f11651182 100644 --- a/plugins/UserCountryMap/svg/DEU.svg +++ b/plugins/UserCountryMap/svg/DEU.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file -- cgit v1.2.3 From a69562453395cc3a5e56409910dbb061a9e43a99 Mon Sep 17 00:00:00 2001 From: Stefan Giehl Date: Wed, 29 Apr 2020 21:41:31 +0200 Subject: Updates device detector to 3.12.5 (#15883) --- ...ITest_browserEngine__API.getSuggestedValuesForSegment.xml | 1 + ...APITest_browserName__API.getSuggestedValuesForSegment.xml | 12 ++++++++++++ ...tAPITest_deviceType__API.getSuggestedValuesForSegment.xml | 1 + plugins/DevicesDetection/functions.php | 1 + plugins/DevicesDetection/lang/en.json | 1 + .../System/expected/test___DevicesDetection.getType_day.xml | 6 ++++++ 6 files changed, 22 insertions(+) (limited to 'plugins') diff --git a/plugins/API/tests/System/expected/test_AutoSuggestAPITest_browserEngine__API.getSuggestedValuesForSegment.xml b/plugins/API/tests/System/expected/test_AutoSuggestAPITest_browserEngine__API.getSuggestedValuesForSegment.xml index 4d3987cb15..c8113891c7 100644 --- a/plugins/API/tests/System/expected/test_AutoSuggestAPITest_browserEngine__API.getSuggestedValuesForSegment.xml +++ b/plugins/API/tests/System/expected/test_AutoSuggestAPITest_browserEngine__API.getSuggestedValuesForSegment.xml @@ -14,4 +14,5 @@ Edge NetSurf Servo + Goanna \ No newline at end of file diff --git a/plugins/API/tests/System/expected/test_AutoSuggestAPITest_browserName__API.getSuggestedValuesForSegment.xml b/plugins/API/tests/System/expected/test_AutoSuggestAPITest_browserName__API.getSuggestedValuesForSegment.xml index d4244b015f..5aa3c56cb7 100644 --- a/plugins/API/tests/System/expected/test_AutoSuggestAPITest_browserName__API.getSuggestedValuesForSegment.xml +++ b/plugins/API/tests/System/expected/test_AutoSuggestAPITest_browserName__API.getSuggestedValuesForSegment.xml @@ -1,5 +1,6 @@ + 115 Browser 2345 Browser 360 Phone Browser 360 Browser @@ -12,10 +13,13 @@ Amaya Amigo Android Browser + AOL Desktop AOL Shield Arora + Arctic Fox Amiga Voyager Amiga Aweb + Atom Atomic Web Browser Avast Secure Browser AVG Secure Browser @@ -34,6 +38,7 @@ BrowseX Camino CCleaner + Centaury Coc Coc Comodo Dragon Coast @@ -67,6 +72,7 @@ Epic Elinks Element Browser + Elements Browser eZ Browser EUI Browser GNOME Web @@ -119,6 +125,7 @@ Cheetah Browser LieBaoFast LG Browser + Light Links Lovense Browser LuaKit @@ -137,6 +144,7 @@ Minimo Mint Browser Maxthon + Mypal Nokia Browser Nokia OSS Browser Nokia Ovi Browser @@ -163,6 +171,7 @@ Opera Touch Ordissimo Oregano + Origin In-Game Overlay Origyn Web Browser Openwave Mobile Browser OmniWeb @@ -205,7 +214,9 @@ Sunrise SuperBird Super Fast Browser + surf START Internet Browser + Steam In-Game Overlay Streamy Swiftfox Seznam Browser @@ -224,6 +235,7 @@ Vivaldi vivo Browser Vision Mobile Browser + VMware AirWatch Wear Internet Browser Web Explorer WebPositive diff --git a/plugins/API/tests/System/expected/test_AutoSuggestAPITest_deviceType__API.getSuggestedValuesForSegment.xml b/plugins/API/tests/System/expected/test_AutoSuggestAPITest_deviceType__API.getSuggestedValuesForSegment.xml index c912de4505..73bbf36546 100644 --- a/plugins/API/tests/System/expected/test_AutoSuggestAPITest_deviceType__API.getSuggestedValuesForSegment.xml +++ b/plugins/API/tests/System/expected/test_AutoSuggestAPITest_deviceType__API.getSuggestedValuesForSegment.xml @@ -12,4 +12,5 @@ portable media player phablet smart speaker + wearable \ No newline at end of file diff --git a/plugins/DevicesDetection/functions.php b/plugins/DevicesDetection/functions.php index 5399309477..5d4fe3cf72 100644 --- a/plugins/DevicesDetection/functions.php +++ b/plugins/DevicesDetection/functions.php @@ -135,6 +135,7 @@ function getDeviceTypeLabel($label) 'camera' => 'DevicesDetection_Camera', 'portable media player' => 'DevicesDetection_PortableMediaPlayer', 'smart speaker' => 'DevicesDetection_SmartSpeaker', + 'wearable' => 'DevicesDetection_Wearable', ); $deviceTypes = DeviceParser::getAvailableDeviceTypes(); diff --git a/plugins/DevicesDetection/lang/en.json b/plugins/DevicesDetection/lang/en.json index e985e0c060..26d6bc7182 100644 --- a/plugins/DevicesDetection/lang/en.json +++ b/plugins/DevicesDetection/lang/en.json @@ -48,6 +48,7 @@ "TV": "Tv", "UserAgent": "User-Agent", "XVisitsFromDevices": "%1$s visits from %2$s devices", + "Wearable": "Wearable", "WidgetBrowsers": "Visitor Browser", "WidgetBrowsersDocumentation": "This report contains information about what kind of browser your visitors were using. Each browser version is listed separately." } diff --git a/plugins/DevicesDetection/tests/System/expected/test___DevicesDetection.getType_day.xml b/plugins/DevicesDetection/tests/System/expected/test___DevicesDetection.getType_day.xml index c5ea05a965..d959ebf6cb 100644 --- a/plugins/DevicesDetection/tests/System/expected/test___DevicesDetection.getType_day.xml +++ b/plugins/DevicesDetection/tests/System/expected/test___DevicesDetection.getType_day.xml @@ -148,4 +148,10 @@ deviceType==smart+speaker plugins/Morpheus/icons/dist/devices/smart_speaker.png + + + 0 + deviceType==wearable + plugins/Morpheus/icons/dist/devices/wearable.png + \ No newline at end of file -- cgit v1.2.3 From 98ef69ae7e5fdce9f0cde77515be70d6bca79b6e Mon Sep 17 00:00:00 2001 From: Thomas Steur Date: Mon, 4 May 2020 19:55:53 +1200 Subject: Fix Javascript error in JS global template causing side effects (#15901) fix https://github.com/matomo-org/wp-matomo/issues/236 fix https://wordpress.org/support/topic/security-string-token-invalid/#topic-12754303-replies --- plugins/Morpheus/templates/_jsGlobalVariables.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/Morpheus/templates/_jsGlobalVariables.twig b/plugins/Morpheus/templates/_jsGlobalVariables.twig index 7f127d5b2c..70f7710936 100644 --- a/plugins/Morpheus/templates/_jsGlobalVariables.twig +++ b/plugins/Morpheus/templates/_jsGlobalVariables.twig @@ -16,7 +16,7 @@ symbolDecimal: "{{ 'Intl_NumberSymbolDecimal'|translate }}" }; - piwik.relativePluginWebDirs = {{ relativePluginWebDirs|json_encode|raw }} + piwik.relativePluginWebDirs = {{ relativePluginWebDirs|json_encode|raw }}; {% if userLogin %}piwik.userLogin = "{{ userLogin|e('js')}}";{% endif %} -- cgit v1.2.3 From e06590688c8751a889595e300fc49e2653215d91 Mon Sep 17 00:00:00 2001 From: Thomas Steur Date: Tue, 5 May 2020 19:16:13 +1200 Subject: Add link to shopify (#15910) --- plugins/SitesManager/templates/_trackingCodeEmail.twig | 1 + plugins/SitesManager/templates/siteWithoutData.twig | 1 + 2 files changed, 2 insertions(+) (limited to 'plugins') diff --git a/plugins/SitesManager/templates/_trackingCodeEmail.twig b/plugins/SitesManager/templates/_trackingCodeEmail.twig index be2a0e2362..06712f1bce 100644 --- a/plugins/SitesManager/templates/_trackingCodeEmail.twig +++ b/plugins/SitesManager/templates/_trackingCodeEmail.twig @@ -15,6 +15,7 @@ Squarespace: https://matomo.org/faq/new-to-piwik/how-do-i-integrate-matomo-with- Wix: https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-analytics-tracking-code-on-wix/ SharePoint: https://matomo.org/faq/how-to-install/faq_19424/ Joomla: https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-analytics-tracking-code-on-joomla/ +Shopify: https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-my-shopify-store/ ** {{ 'SitesManager_Integrations'|translate }} {{ 'CoreAdminHome_JSTrackingIntro3a'|translate('', '') }} diff --git a/plugins/SitesManager/templates/siteWithoutData.twig b/plugins/SitesManager/templates/siteWithoutData.twig index 19e831c00e..a1215dd8c5 100644 --- a/plugins/SitesManager/templates/siteWithoutData.twig +++ b/plugins/SitesManager/templates/siteWithoutData.twig @@ -49,6 +49,7 @@ | Wix | SharePoint | Joomla + | Shopify

{{ 'SitesManager_ExtraInformationNeeded'|translate }} -- cgit v1.2.3 From bd9aa9db1a95e6f1ef74b45e3723849fab2f292c Mon Sep 17 00:00:00 2001 From: Stefan Giehl Date: Thu, 7 May 2020 22:27:07 +0200 Subject: Exclude some url parameters from referrer urls (#15905) --- ...esSystemTest__Live.getLastVisitsDetails_day.xml | 2 +- plugins/Referrers/Columns/Base.php | 56 +++++++++++ .../tests/Integration/Columns/ReferrerUrlTest.php | 106 +++++++++++++++++++++ 3 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 plugins/Referrers/tests/Integration/Columns/ReferrerUrlTest.php (limited to 'plugins') diff --git a/plugins/CustomVariables/tests/System/expected/test_CustomVariablesSystemTest__Live.getLastVisitsDetails_day.xml b/plugins/CustomVariables/tests/System/expected/test_CustomVariablesSystemTest__Live.getLastVisitsDetails_day.xml index 6a723dbbbe..c7d0d56976 100644 --- a/plugins/CustomVariables/tests/System/expected/test_CustomVariablesSystemTest__Live.getLastVisitsDetails_day.xml +++ b/plugins/CustomVariables/tests/System/expected/test_CustomVariablesSystemTest__Live.getLastVisitsDetails_day.xml @@ -108,7 +108,7 @@ Google this keyword should be ranked 1 - http://www.google.com/url?sa=t&source=web&cd=1&ved=0CB4QFjAA&url=http://piwik.org/&rct=j&q=this keyword should be ranked&ei=V8WfTePkKKLfiALrpZWGAw&usg=AFQjCNF_MGJRqKPvaKuUokHtZ3VvNG9ALw&sig2=BvKAdCtNixsmfNWXjsNyMw + http://www.google.com/url?source=web&cd=1&url=http://piwik.org/&rct=j&q=this keyword should be ranked&sig2=BvKAdCtNixsmfNWXjsNyMw http://google.com plugins/Morpheus/icons/dist/searchEngines/google.com.png diff --git a/plugins/Referrers/Columns/Base.php b/plugins/Referrers/Columns/Base.php index 41e846b028..3d6d27b158 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..0c96f8451e --- /dev/null +++ b/plugins/Referrers/tests/Integration/Columns/ReferrerUrlTest.php @@ -0,0 +1,106 @@ +referrerUrl = new ReferrerUrl(); + } + + public function tearDown() + { + // 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&e=BTPcuqWixl6Mf5hgYPp6wXIlstuaEdJssdYEvT9s8-6yme_lb275lY2Bwc-YvE-fZNtSKux4QB-v8xNk&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()); + } + +} -- cgit v1.2.3