Browse Source

* remove http/https from matomo url programmatically

pull/496/head
maenz.torsten 4 years ago
parent
commit
809b8524a3
1 changed files with 30 additions and 6 deletions
  1. +30
    -6
      system/includes/functions.php

+ 30
- 6
system/includes/functions.php View File

@ -2041,14 +2041,29 @@ function matomo($title)
return;
}
$script = <<<EOF
if($matomoTracking == 'javascript')
{
$url = $matomoURL;
// remove http | https
if (startsWith($matomoURL, 'https'))
{
$url = replace_first_str('https', '', $matomoURL);
}
else if (startsWith($matomoURL, 'http'))
{
$url = replace_first_str('http', '', $matomoURL);
}
$script = <<<EOF
<script type="text/javascript">
var _paq = window._paq || [];
_paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="{$matomoURL}";
var u="{$url}";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '{$matomoID}']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
@ -2057,9 +2072,7 @@ function matomo($title)
</script>
<noscript><p><img src="{$matomoURL}matomo.php?idsite={$matomoID}&amp;rec=1" style="border:0;" alt="" /></p></noscript>
EOF;
if($matomoTracking == 'javascript')
{
return $script;
}
else if($matomoTracking == 'php')
@ -2079,7 +2092,7 @@ EOF;
$matomoTracker = new MatomoTracker((int) $matomoID, $matomoURL);
// do not wait
$matomoTracker->setRequestTimeout(1);
$matomoTracker->setRequestTimeout(1);
// Set authentication token
$matomoTracker->setTokenAuth($matomoToken);
@ -2089,6 +2102,17 @@ EOF;
}
}
function startsWith($haystack, $needle)
{
$length = strlen( $needle );
return substr( $haystack, 0, $length ) === $needle;
}
function replace_first_str($search_str, $replacement_str, $src_str)
{
return (false !== ($pos = strpos($src_str, $search_str))) ? substr_replace($src_str, $replacement_str, $pos, strlen($search_str)) : $src_str;
}
function slashUrl($url) {
return rtrim($url, '/') . '/';
}


Loading…
Cancel
Save