Skip to content

Commit

Permalink
Fix: #4842 - update the JS snippet for matomo analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
fisharebest committed Nov 7, 2023
1 parent dd75064 commit 6e80021
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
1 change: 0 additions & 1 deletion app/Module/MatomoAnalyticsModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public function analyticsParameters(): array
$matomo_site_id = $this->getPreference('MATOMO_SITE_ID');
$matomo_url = $this->getPreference('MATOMO_URL');

// Reports on the webtrees forum say that a trailing slash is required.
if (!str_ends_with($matomo_url, '/')) {
$matomo_url .= '/';
}
Expand Down
25 changes: 13 additions & 12 deletions resources/views/modules/matomo-analytics/snippet.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ declare(strict_types=1);
use Fisharebest\Webtrees\Contracts\UserInterface;

/**
* @var string $MATOMO_SITE_ID
* @var string $MATOMO_URL
* @var UserInterface $user
*/

?>
<script type="text/javascript">
var _paq = window._paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u=<?= json_encode($MATOMO_URL ?? '', JSON_THROW_ON_ERROR) ?>;
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', <?= json_encode($MATOMO_SITE_ID ?? '', JSON_THROW_ON_ERROR) ?>]);
_paq.push(['setUserId', <?= json_encode($user->userName(), JSON_THROW_ON_ERROR) ?>]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
<script>
var _paq = window._paq = window._paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u=<?= json_encode($MATOMO_URL, JSON_THROW_ON_ERROR) ?>;
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', <?= (int) $MATOMO_SITE_ID ?>]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>

0 comments on commit 6e80021

Please sign in to comment.