Du solltests ggf. noch die Anpassungen von Joachim Nickel übernehmen. Dann erwischst du auch die Besucher, die mit AdbockPlus, uBlock oder Brave unterwegs sind.
Dann sieht das Template so aus:
Oder, wenn du den Contao Tag Manager nutzen willst:
Dann sieht das Template so aus:
Code:
if ($MatomoSite > 0 && '//www.example.com/matomo/' != $MatomoPath && !$this->hasAuthenticatedBackendUser()): ?>
<script<?= $this->attr()->setIfExists('nonce', $this->nonce('script-src')) ?>>
var _paq = window._paq = window._paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u='<?= $MatomoPath ?>';
_paq.push(['setTrackerUrl', u+'js/']);
_paq.push(['setSiteId', <?= $MatomoSite ?>]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.defer=true; g.src=u+'js/'; s.parentNode.insertBefore(g,s);
})();
</script>
<?php
$this->addCspSource('script-src', $MatomoPath);
endif;
Code:
<?php
// To use this script, please fill in your Matomo site ID and Matomo URL below
$MatomoPath = '//www.example.com/';
$MatomoContainerId = '';
// DO NOT EDIT ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING!
if ($MatomoContainerId != '' && '//www.example.com/matomo/' != $MatomoPath && !$this->hasAuthenticatedBackendUser()): ?>
<script<?= $this->attr()->setIfExists('nonce', $this->nonce('script-src')) ?>>
var u='<?= $MatomoPath ?>';
var c='<?= $MatomoContainerId ?>';
var _mtm = window._mtm = window._mtm || [];
_mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'});
(function() {
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'js/container_'+c+'.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<?php
$this->addCspSource('script-src', $MatomoPath);
endif;

Comment