Skip to content

Commit

Permalink
Merge pull request #3276 from betagouv/lucien/matomo
Browse files Browse the repository at this point in the history
Ajoute le nouveau tag Matomo en parallèle de l'ancien
  • Loading branch information
LucienMLD authored Dec 19, 2023
2 parents 57e6f6d + d72f9e8 commit 5af1fab
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions app/views/shared/_matomo.html.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
<%= javascript_tag 'data-turbo-eval': false, nonce: true do -%>
var _paq = _paq || [];
// Configure Matomo analytics
var _paq = window._paq = window._paq || [];

// Load script from Matomo
_paq.push(['setCookieSameSite', 'None']);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
_paq.push(['setCookieSameSite', 'None']);

// Load script from Matomo
(function() {
var u="//stats.data.gouv.fr/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', '80']);
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);
var u="//stats.beta.gouv.fr/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '74']);
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);
})();

// Also send all the tracking data to the old stats.data.gouv.fr Matomo server
var secondaryTracker = 'https://stats.data.gouv.fr/matomo.php';
var secondaryWebsiteId = '80';
_paq.push(['addTracker', secondaryTracker, secondaryWebsiteId]);

// Send Matomo a new event when navigating to a new page using turbo
// (see https://developer.matomo.org/guides/spa-tracking)
addEventListener('turbo:load', function(event) {
Expand Down

0 comments on commit 5af1fab

Please sign in to comment.