Doc - Piwik / Matomo : mise à jour du script
.js
et .php
Changement de nom des fichiers Dans le changelog Matomo 3.8.0, un changement interne est annoncé cassant pour la version 4.0 :
Matomo installation will now use by default "matomo.js" and "matomo.php" as tracking endpoints. From Matomo 4.0 all installations will use "matomo.js" and "matomo.php" by default.
voir : https://gitlab.adullact.net/Adullact-prive/Entropie/issues/680
Différences entre le code de tracking actuel et celui proposé via notre instance de Matomo
<script type="text/javascript">
- var _paq = _paq || [];
+ var _paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://<serverStat>/";
- _paq.push(['setTrackerUrl', u+'piwik.php']);
+ _paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '<id_website>']);
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);
+ g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
Webperf : optimiser le chargement de piwik
L'outil de statistique ne doit en aucun cas ralentir l'affichage du site web. La solution est de charger l'outil de statistique après l’éventement onload
de la page HTML.
"Third-party scripts often use embed techniques that can block window.onload if their servers respond slowly, even if the embed is using async or defer." source : Loading Third-Party JavaScript
documentation pour Matomo :
- https://fr.matomo.org/blog/2017/04/different-ways-embedding-piwik-tracking-code-faster-website-performance/
- https://github.com/matomo-org/matomo/issues/9077
exemple :
<!-- Matomo / Embedding the tracker after the load event -->
<script type="text/javascript">
var _paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
function embedTrackingCode(){
var u="https://<serverStat>/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '<id_website>']);
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+'matomo.js'; s.parentNode.insertBefore(g,s);
}
if (window.addEventListener){ window.addEventListener("load", embedTrackingCode, false); }
else if (window.attachEvent){ window.attachEvent("onload", embedTrackingCode); }
else { embedTrackingCode(); }
</script>
<!-- End Matomo Code -->
Tâche
-
mise à jour du script en prod + doc exploitation -
mise à jour de la documentation dans le repo -
mise à jour puppet