Browse Source

* add matomo function

* add usage in twentyfifteen template
pull/496/head
maenz.torsten 4 years ago
parent
commit
b647e8ac8c
2 changed files with 58 additions and 0 deletions
  1. +57
    -0
      system/includes/functions.php
  2. +1
    -0
      themes/twentyfifteen/layout.html.php

+ 57
- 0
system/includes/functions.php View File

@ -5,6 +5,7 @@ use \Michelf\MarkdownExtra;
use \Suin\RSSWriter\Feed;
use \Suin\RSSWriter\Channel;
use \Suin\RSSWriter\Item;
use function Composer\Autoload\includeFile;
// Get blog post path. Unsorted. Mostly used on widget.
function get_post_unsorted()
@ -2021,6 +2022,62 @@ EOF;
}
}
// Matomo
function matomo($title)
{
$matomoURL = config('matomo.url');
$matomoToken = config('matomo.token');
$matomoID = config('matomo.id');
$matomoTracking = config('matomo.tracking');
if(empty($matomoURL) || empty($matomoTracking) || empty($matomoID) || empty($matomoToken))
{
error_log("Please set all Matomo configuration values", 0);
return;
}
$script = <<<EOF
<script>
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="${matomoURL}";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '{$matomoID}']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
EOF;
if($matomoTracking == 'javascript')
{
return $script;
}
else if($matomoTracking == 'php')
{
$url = 'system/plugins/matomo/MatomoTracker.php';
require_once ($url);
MatomoTracker::$URL = $matomoURL;
// Matomo object
$matomoTracker = new MatomoTracker((int) $matomoID, $matomoURL);
// Set authentication token
$matomoTracker->setTokenAuth($matomoToken);
// Track page view
$matomoTracker->doTrackPageView($title);
}
else
{
return "nothing";
}
}
function slashUrl($url) {
return rtrim($url, '/') . '/';
}


+ 1
- 0
themes/twentyfifteen/layout.html.php View File

@ -132,6 +132,7 @@
<script type="text/javascript" src="<?php echo site_url();?>themes/twentyfifteen/js/functions.js"></script>
<script type="text/javascript" src="<?php echo site_url();?>themes/twentyfifteen/js/skip-link-focus-fix.js"></script>
<?php if (analytics()): ?><?php echo analytics() ?><?php endif; ?>
<?php if (matomo($title)): ?><?php echo matomo($title) ?><?php endif; ?>
</body>
</html>

Loading…
Cancel
Save