<?php if (!defined('MATOMO_SITE_ID')) return; ?>
<?php if (!defined('MATOMO_ENABLED') || !MATOMO_ENABLED) return; ?>
<?php
$matomoDomains = [];
$primaryDomain   = app_primary_domain();
$fakecheckDomain = app_fakecheck_domain();

$matomoDomains[] = '*.' . $primaryDomain;
$matomoDomains[] = '*.' . $fakecheckDomain;
$matomoDomains[] = '*.' . $primaryDomain . '/fakecheck';
?>

<!-- Matomo -->
<script>
    var _paq = window._paq = window._paq || [];
    _paq.push(["setDomains", <?= json_encode($matomoDomains, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) ?>]);
    _paq.push(['trackPageView']);
    _paq.push(['enableLinkTracking']);

    (function() {
        var u = "<?= rtrim(MATOMO_URL, '/') ?>/";
        _paq.push(['setTrackerUrl', u + 'matomo.php']);
        _paq.push(['setSiteId', '<?= MATOMO_SITE_ID ?>']);

        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>

<noscript>
    <p>
        <img referrerpolicy="no-referrer-when-downgrade"
             src="<?= rtrim(MATOMO_URL,'/') ?>/matomo.php?idsite=<?= MATOMO_SITE_ID ?>&amp;rec=1"
             style="border:0;" alt="" />
    </p>
</noscript>
<!-- End Matomo -->
