Matomo 分析

||||
-|-|
:discourse2: | 简介 | Matomo Analytics 是一个用于在 Discourse 上启用 Matomo 分析功能的脚本。
:hammer_and_wrench: | 仓库链接 | https://github.com/discourse/discourse-matomo-analytics
:open_book: |Discourse 主题新手? | Discourse 主题使用入门指南

安装此主题组件

功能

Matomo 是一个开源分析平台。用户可以选择自行托管或付费使用云端的官方托管服务。

:mega: Matomo 以前名为 Piwik。有关名称变更的详细信息,请参阅 Piwik is now Matomo - Announcement - Analytics Platform - Matomo

要在您的 Discourse 论坛中启用 Matomo 分析,只需安装官方主题组件即可。

适用于 Matomo API v1.5 及更高版本

  1. 按照主题安装指南从以下 URL 导入:

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

    您将看到

  2. 输入 Host URLWebsite ID

  3. 将主题组件 “Matomo Analytics” 添加到您的活动主题中。

就这样!

设置

名称 描述
host url 不包含 http:// 或 https:// 的主机 URL
website id
exclude groups 逗号分隔的排除跟踪的组列表,例如 admins、staff
user id tracking 当前用户对象上的标识字段名称,例如 id、username 或 external_id。
subdomain tracking 跟踪主域名和子域上的访问者,假设 Discourse 位于子域名上。
do not track 如果访问者不希望被跟踪,则不发送跟踪请求。
disable cookies 禁用所有第一方 Cookie。下次页面浏览时,该网站的现有 Matomo Cookie 将被删除。

致谢

感谢 @mattab@brahn@tagtomat@simon


:discourse2: 由我们托管? 主题组件可在我们的 Standard、Business 和 Enterprise 计划中使用。

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

感谢提供这个组件!

我不太明白为什么追踪代码会发送一个名为“Anonymous”的自定义变量。这难道不是针对您特定的 Matomo 设置的吗?看起来它不应该对所有人都存在。

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

添加了几行代码,以便在子域名的 Discourse 和主站点之间追踪访客。如果您需要,我很乐意提交拉取请求。

您需要在内容安全策略(Content-Security-Policy)标头中将您的 Matomo URL 列入白名单。搜索管理设置 content_security_policy_script_src,并在其中添加您的域名(包含 https://)。

6 个赞

我在我的安装环境中遇到无法正常工作的问题。我已经安装了该组件,并将其添加到我的主题中,但 Matomo 提示该站点没有数据。我认为我的设置是正确的:


image
但在我的浏览器控制台中看到了这个错误:
image
…当我在 Matomo 中查看该站点时,看到的是这个:

我遗漏了什么?

编辑:进一步调查后发现,JavaScript 控制台中的错误仅在 Firefox 中出现,而在 Chrome 中则没有(在 Mac 上使用的是两者的最新版本)。现在我在 Matomo 中看到了一些结果,但 Firefox 明显缺失——所有访客中只有一人未使用 Chrome;该例外访客使用的是 Safari。

对此有什么看法吗?这篇帖子:

指出这可能是 Firefox 的“不追踪”设置所致,但即使我为我的网站禁用了该设置,在 Firefox 的网页控制台中仍然出现相同的错误。而且无论如何,Firefox 似乎并没有将其视为追踪器:

请尝试移除“https://www.familybrown.org/analytics/”末尾的斜杠 /,将其改为“https://www.familybrown.org/analytics”

1 个赞

谢谢。不幸的是,我仍然收到相同的错误:
image

能告诉我您论坛的网址吗?

这两个字段需要填写吗?我不是很理解它们。