The discussion revolves around issues with adding Matomo analytics to a Discourse forum. Antony initially tried to add the tracking code via a custom component but encountered issues with the code not being executed due to security settings.
Falco suggested using a specific script to enable Matomo analytics on Discourse, but Antony still encountered issues. Falco pointed out that the problem might be related to the Content Security Policy (CSP) setting, which was confirmed by Antony.
Tuhadj shared a similar issue and provided more details about the problem, including a screenshot of their CSP settings. pmusaraj inspected the site and found that the Matomo script was loading correctly, suggesting that the issue might be on the Matomo side.
<!-- 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://stats.xxxxxxx.xxx/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '8']);
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 -->
And all I get is html source of the page is the html comments. <script> tags seam to have been removed.
Is there a security setting to be activated as to allow scripts in those areas?
<!-- Matomo - head -->
<!-- /Matomo - head -->
[...]
<!-- Matomo -->
<!-- End Matomo Code -->
Hi @Falco I think I’ve got the same problem with Matomo not working with Discourse. It is what the support team of Matomo told me when I opened a ticket on their github :