diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2018-11-29 10:22:15 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-29 10:22:15 +0300 |
commit | 73010596f01b9660899267305fe0cf5064428753 (patch) | |
tree | 367851f6c476d10f51c0a2a8756f02d260583d83 /plugins/SitesManager/API.php | |
parent | 970883b106229f11a071c5470538bfb29dc83871 (diff) |
Make matomo.js and matomo.php the default Tracking API endpoints used (#13596)
* Make matomo.js and matomo.php the default Tracking API endpoints used
* few fixes
* fix few tests
* update matomo php tracker in composer
* make sure to record install version
* do not overwrite ever install version
* trying to fix test
* more tweaks and fix tests
* prefer matomo endpoint in the ui, fix some tests
* file was still needed
* apply review feedback
* fix ui tests
Diffstat (limited to 'plugins/SitesManager/API.php')
-rw-r--r-- | plugins/SitesManager/API.php | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/plugins/SitesManager/API.php b/plugins/SitesManager/API.php index a6256d7ab5..94ad508d27 100644 --- a/plugins/SitesManager/API.php +++ b/plugins/SitesManager/API.php @@ -101,13 +101,14 @@ class API extends \Piwik\Plugin\API * @param bool $doNotTrack * @param bool $disableCookies * @param bool $trackNoScript + * @param bool $forceMatomoEndpoint Whether the Matomo endpoint should be forced if Matomo was installed prior 3.7.0. * @return string The Javascript tag ready to be included on the HTML pages */ public function getJavascriptTag($idSite, $piwikUrl = '', $mergeSubdomains = false, $groupPageTitlesByDomain = false, $mergeAliasUrls = false, $visitorCustomVariables = false, $pageCustomVariables = false, $customCampaignNameQueryParam = false, $customCampaignKeywordParam = false, $doNotTrack = false, $disableCookies = false, $trackNoScript = false, - $crossDomain = false) + $crossDomain = false, $forceMatomoEndpoint = false) { Piwik::checkUserHasViewAccess($idSite); @@ -124,6 +125,10 @@ class API extends \Piwik\Plugin\API $customCampaignKeywordParam = Common::unsanitizeInputValue($customCampaignKeywordParam); $generator = new TrackerCodeGenerator(); + if ($forceMatomoEndpoint) { + $generator->forceMatomoEndpoint(); + } + $code = $generator->generate($idSite, $piwikUrl, $mergeSubdomains, $groupPageTitlesByDomain, $mergeAliasUrls, $visitorCustomVariables, $pageCustomVariables, $customCampaignNameQueryParam, $customCampaignKeywordParam, @@ -139,9 +144,10 @@ class API extends \Piwik\Plugin\API * @param string $piwikUrl The domain and URL path to the Matomo installation. * @param int $idGoal An ID for a goal to trigger a conversion for. * @param int $revenue The revenue of the goal conversion. Only used if $idGoal is supplied. + * @param bool $forceMatomoEndpoint Whether the Matomo endpoint should be forced if Matomo was installed prior 3.7.0. * @return string The HTML tracking code. */ - public function getImageTrackingCode($idSite, $piwikUrl = '', $actionName = false, $idGoal = false, $revenue = false) + public function getImageTrackingCode($idSite, $piwikUrl = '', $actionName = false, $idGoal = false, $revenue = false, $forceMatomoEndpoint = false) { $urlParams = array('idsite' => $idSite, 'rec' => 1); @@ -168,7 +174,13 @@ class API extends \Piwik\Plugin\API */ Piwik::postEvent('SitesManager.getImageTrackingCode', array(&$piwikUrl, &$urlParams)); - $url = (ProxyHttp::isHttps() ? "https://" : "http://") . $piwikUrl . '/piwik.php?' . Url::getQueryStringFromParameters($urlParams); + $trackerCodeGenerator = new TrackerCodeGenerator(); + if ($forceMatomoEndpoint) { + $trackerCodeGenerator->forceMatomoEndpoint(); + } + $matomoPhp = $trackerCodeGenerator->getPhpTrackerEndpoint(); + + $url = (ProxyHttp::isHttps() ? "https://" : "http://") . rtrim($piwikUrl, '/') . '/'.$matomoPhp.'?' . Url::getQueryStringFromParameters($urlParams); $html = "<!-- Matomo Image Tracker--> <img src=\"" . htmlspecialchars($url, ENT_COMPAT, 'UTF-8') . "\" style=\"border:0\" alt=\"\" /> <!-- End Matomo -->"; |