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