Matomo Analytics

:discourse2: Summary Matomo Analytics is a script to enable Matomo analytics on Discourse.
:hammer_and_wrench: Repository Link https://github.com/discourse/discourse-matomo-analytics
:open_book: New to Discourse Themes? Beginner’s guide to using Discourse Themes

Install this theme component

Features

Matomo is an open source analytics platform. Users can choose between self-hosting or paying for professional hosting in the cloud.

:mega: Matomo was formerly named Piwik. See Piwik is now Matomo - Announcement - Analytics Platform - Matomo for details about the name change.

To enable Matomo analytics on your Discourse forum, all you have to do is install the official theme component.

Valid for Matomo API v1.5 and newer

  1. Follow the theme installation guide to import from the following URL:

    https://github.com/discourse/discourse-matomo-analytics.git
    

    And you will see

  2. Enter the Host URL and Website ID

  3. Add the theme component “Matomo Analytics” to your active theme(s).

That’s it!

Settings

Name Description
host url Host URL without http:// or https://
website id
exclude groups Comma separated list of groups to exclude from tracking such as admins, staff
user id tracking An indentifying field name on the current user object such as id, username or external_id.
subdomain tracking Track visitors across main domain & subdomains, assuming discourse is on a subdomain.
do not track So tracking requests will not be sent if visitors do not wish to be tracked.
disable cookies Disables all first party cookies. Existing Matomo cookies for this website will be deleted on the next pageview.

Credits

Thanks to @mattab & @brahn @tagtomat and @simon


:discourse2: Hosted by us? Theme components are available to use on our Standard, Business, and Enterprise plans.

Last edited by @david 2025-01-09T09:44:19Z

Check documentPerform check on document:
38 Mi Piace

Thanks for this howto, works fine for me. :thumbsup:

In order to comply with the European laws, users must have the possibility to reject piwik’s cookie. Piwik offers a really simple solution for this, by including an IFrame.

Unfortunately, Discourse doesn’t allow iframe tags in posts… :grimacing:
Does anyone see a way to include this piwik iframe in Discourse TOS ?
Thanks.

1 Mi Piace

:wave: I just created a new “Matomo Analytics” theme component, and updated the instructions on how to set it up.

Could you give it a try? Please also remember to remove the original custom scripts.

8 Mi Piace

Looks good on first sight. No error in javascript console. Requests to piwik.php being in the webserver log again.

Statistics in Matomo are available as well.

5 Mi Piace

Is this iframe thing still a concern?

1 Mi Piace

Hey @xrav3nz :clap: your component works great - thanks!

Yes it is. Opt-out should be possible, and Matomo provides this via including an iFrame: see Matomo documentation

3 Mi Piace

This doesn’t appear to be working for me at the moment? I can add the component, and add the correct URL and siteid, but it doesn’t render anything:

I added the comments around the code to find it quicker in the page:

image

1 Mi Piace

We are on beta 6+git1 on our instance

Inline JavaScripts in themes and components are automatically extracted to an external “theme JavaScript” file.

Could you try checking the one immediately after your comments?

9954b74cfdb3c6f0230e7e9f4c6a3db0764c1373

7 Mi Piace

This is at the main page on https://discuss.pixls.us:

Edit
Hold on, I’ve got a new hash on the file on recent refresh, it looks like the code is there. Thank you @xrav3nz!

Looks like it’s working now - not sure what I was doing wrong yesterday - user error.

5 Mi Piace

So I have the JS loaded into the theme customizations, and the external “theme JavaScript file”* is linked in my test browser, just under where I inserted it like in the screenshot in a few posts earlier … BUT the requests aren’t coming through to the Matomo tracking web server.

(Tracking works fine for other non-Discourse sites, FWIW.)

Has anyone else seen that happen?


* e.g. https://discourse-cdn.example.com/standard11/theme-javascripts/{numeric_string}.js?__ws=my-discourse-forum.example.org

Grazie per il componente!

Sono confuso sul perché il codice di tracciamento stia inviando una variabile personalizzata chiamata Anonymous. Non è quella personalizzata per la tua specifica configurazione di Matomo? Non sembra che dovrebbe esserci per tutti.

_paq.push(['setCustomVariable', 1, 'Anonymous', !currentUser, 'visit']);

Ho aggiunto alcune righe in modo che potesse tracciare i visitatori tra Discourse su un sottodominio e un sito principale. Sono disponibile a inviare una pull request se lo desideri.

Devi inserire l’URL di Matomo nell’elenco consentito dell’intestazione Content-Security-Policy. Cerca l’impostazione amministrativa content_security_policy_script_src e aggiungi il tuo dominio (con https://) lì.

6 Mi Piace

Ho difficoltà a far funzionare questo sulla mia installazione. Ho installato il componente e l’ho aggiunto al mio tema, ma Matomo segnala che non ci sono dati per il sito. Credo di avere le impostazioni corrette:


image
Ma vedo questo errore nella console del browser:
image
…e quando controllo il sito in Matomo, vedo questo:

Cosa sto trascurando?

Modifica: Ulteriori indagini rivelano che l’errore nella console JavaScript appare solo in Firefox, non in Chrome (con le versioni più recenti di entrambi su Mac). Ora vedo alcuni risultati in Matomo, anche se Firefox è assente in modo evidente: tutti i visitatori, tranne uno, stanno utilizzando Chrome; l’unico eccezione sta utilizzando Safari.

Hai qualche pensiero al riguardo? Questo post:

suggerisce che potrebbe essere dovuto alle impostazioni “non tracciare” di Firefox, ma anche quando le disattivo per il mio sito, ricevo lo stesso errore nella console web con Firefox. Inoltre, Firefox non sembra considerare questo un tracker in ogni caso:

Prova a rimuovere l’ultimo / da “https://www.familybrown.org/analytics/” → “https://www.familybrown.org/analytics

1 Mi Piace

Grazie. Purtroppo, ricevo ancora lo stesso errore:
image

Potresti darmi l’URL del tuo forum?

Questi due campi devono essere compilati? Non li capisco molto bene.