Script to enable Matomo analytics on Discourse

theme-component

(Erlend Sogge Heggen) #1

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

Note: 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

    05%20AM

  2. Enter the Host URL and Website ID

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

That’s it!

Thanks to @mattab & @brahn for updates
Updated by @tagtomat after @Simon_Cossar helped setting it up on our forum


Support for Piwik Analytics as an alternative to Google Analytics
How to anonymize Google Analytics?
showOpLikes - How to enable?
Support for Piwik Analytics as an alternative to Google Analytics
Sidekiq: Uncaught TypeError: Cannot read property 'current' of undefined
Javascript inserted into Footer from Discourse UI not working
Protect user privacy by using Matomo, dumping Google Analytics?
Matomo analytics is not working after recent update
Matomo analytics is not working after recent update
Matomo analytics is not working after recent update
Accessibility: Signal changes to screen readers on navigation
(Christoph Blechschmitt) #22

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.


#30

: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.


#31

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.


(Sam Saffron) #32

Is this iframe thing still a concern?


(Christoph Blechschmitt) #33

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


(Pat David) #34

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


(Darix) #35

We are on beta 6+git1 on our instance


#36

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


(Pat David) #37

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.