xref: /webtrees/resources/views/modules/matomo-analytics/snippet.phtml (revision 10e0649788c8d7d4974d81c048ca2b225df8f22e)
1<?php
2
3declare(strict_types=1);
4
5use Fisharebest\Webtrees\Contracts\UserInterface;
6
7/**
8 * @var UserInterface $user
9 */
10
11?>
12<script type="text/javascript">
13    var _paq = window._paq || [];
14    _paq.push(['trackPageView']);
15    _paq.push(['enableLinkTracking']);
16    (function() {
17        var u=<?= json_encode($MATOMO_URL ?? '', JSON_THROW_ON_ERROR) ?>;
18        _paq.push(['setTrackerUrl', u+'piwik.php']);
19        _paq.push(['setSiteId', <?= json_encode($MATOMO_SITE_ID ?? '', JSON_THROW_ON_ERROR) ?>]);
20        _paq.push(['setUserId', <?= json_encode($user->userName(), JSON_THROW_ON_ERROR) ?>]);
21        var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
22        g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
23    })();
24</script>
25