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개의 좋아요

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개의 좋아요

: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개의 좋아요

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개의 좋아요

Is this iframe thing still a concern?

1개의 좋아요

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개의 좋아요

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:

1개의 좋아요

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?

7개의 좋아요

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개의 좋아요

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

Thanks for the component!

I’m confused why the tracking code is sending a custom variable called Anonymous. Isn’t that custom for your particular Matomo setup? It doesn’t seem like it should be there for everyone.

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

I added a few lines so that it would track visitors between discourse on a subdomain and a main site. Happy to send a pull request if you want it.

Content-Security-Policy 헤더 내에 Matomo URL을 화이트리스트에 추가해야 합니다. 관리자 설정에서 content_security_policy_script_src를 검색하고 해당 위치에 도메인(https:// 포함)을 추가하세요.

6개의 좋아요

내 설치 환경에서 이 기능을 작동시키는 데 어려움을 겪고 있습니다. 구성 요소를 설치하고 테마에 추가했는데, Matomo에서는 해당 사이트에 데이터가 없다고 표시하고 있습니다. 설정은 올바르게 한 것 같은데:


image
하지만 브라우저 콘솔에서 다음과 같은 오류를 확인했습니다:
image
…그리고 Matomo에서 사이트를 확인하면 다음과 같은 화면이 표시됩니다:

무엇이 빠져 있나요?

수정: 추가 조사를 해보니 자바스크립트 콘솔의 오류는 Firefox에서만 발생하고 Chrome에서는 발생하지 않는다는 것을 알게 되었습니다(맥에서 각각 최신 버전을 사용 중입니다). 그리고 이제 Matomo에서 일부 결과를 확인하고 있지만, Firefox는 눈에 띄게 빠져 있습니다. 방문자 중 하나를 제외한 나머지는 모두 Chrome을 사용 중이며, 유일한 예외는 Safari를 사용 중입니다.

이 문제에 대해 어떤 생각이 있으신가요? 이 포스트:

에는 Firefox의 “추적하지 않기” 설정 때문일 수 있다고 제안하고 있지만, 제 사이트에 대해 이 설정을 비활성화해도 Firefox 웹 콘솔에서 동일한 오류가 발생합니다. 그리고 Firefox는 애초에 이걸 트래커로 인식하지도 않는 것 같습니다:

"https://www.familybrown.org/analytics/"의 마지막 /를 제거해 보세요 → “https://www.familybrown.org/analytics”

1개의 좋아요

감사합니다. 불행히도 여전히 같은 오류가 발생합니다:
image

포럼 URL을 알려 주시겠어요?

이 두 필드를 채워야 하나요? 정확히 무엇을 의미하는지 잘 모르겠네요.