Add Matomo JS
-
transform JS for lazy loading -
add lazy loading JS to theme -
identify how to manage for the prod website and the dev website?
Dev website
<!-- Matomo -->
<script type="text/javascript">
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://statistiques.adullact.org/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '14']);
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>
<!-- End Matomo Code -->
Embedding Matomo tracker after the load event
<!-- 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://statistiques.adullact.org/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '14']);
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 -->
Minify + hash for CSP
see: doc_for-developer/Security_CSP_headers/DEV_matomo-loader.txt
<!-- Matomo - Embedding JS file after load event -->
<!-- CSP hash: sha256-0dea72a0b69fffc3ae5b6ba5c3209d4f81d5d0abc310eedc7991249e44affd9c -->
<script>var_paq=window._paq||[];_paq.push(['trackPageView']);_paq.push(['enableLinkTracking']);functionembedTrackingCode(){varu='https://statistiques.adullact.org/';_paq.push(['setTrackerUrl',u+'matomo.php']);_paq.push(['setSiteId','14']);vard=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);}elseif(window.attachEvent){window.attachEvent('onload',embedTrackingCode);}else{embedTrackingCode();}</script>
<!-- END Matomo -->
Edited by Fabrice Gangler