域名已变更 请手动修改文章中域名指向carlzeng.com

Docker搭建站点统计程序Matomo

开源的网站统计程序Matomo

有什么用

一款非常好用的网站统计程序,Matomo. Matomo的前身是著名的Piwik. 作为一款免费开源的统计程序,它不仅能够对每一条访问提供准确及时的访问记录,还能够自动生成极其专业的统计报表,包括根据地理位置生成的全球访问热点地图,实时访问图景,每一条访问的每一个点击操作详细分析,页面跳转率,来路分析,访客浏览器,访客硬件设备,关键词,等等等等……您还可以使用API,将统计功能整合在客户端、小程序等场景。虽然功能非常丰富,但是Mamoto非常轻量,几乎不需要占用什么资源。

实现方法

cd /www/server/panel/data/compose/matomo


<!-- Matomo -->
<script>
  var _paq = window._paq = window._paq || [];
  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  _paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
  _paq.push(["setCookieDomain", "*.carlzeng.top"]);
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//192.168.6.116:8597/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '1']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<noscript><p><img src="//192.168.6.116:8597/matomo.php?idsite=1&amp;rec=1" style="border:0;" alt="" /></p></noscript>
<!-- End Matomo Code -->

docker-compose up

  1. Database Server: type in mariadb
  2. Login: type in root
  3. Password: leave blank
  4. Database Name: type in matomodb

Tracking code for Carl Notes

<!-- Matomo -->
<script>
  var _paq = window._paq = window._paq || [];
  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//192.168.192.3/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '1']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<!-- End Matomo Code -->

开启防火墙的8597

NPM 新建
https://statcounter.carlzeng.top:4443

https://statcounter.carlzeng.top:4443/?module=Login
Error: The form security failed because of invalid origin. If you previously connected using HTTPS, please ensure you are connecting over a secure (SSL/TLS) connection and try again.

docker-compose down
docker-compose up


<!-- Matomo -->
<script>
  var _paq = window._paq = window._paq || [];
  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  _paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
  _paq.push(["setCookieDomain", "*.carlzeng.top"]);
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//statcounter.carlzeng.top:4443/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '1']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<noscript><p><img src="//statcounter.carlzeng.top:4443/matomo.php?idsite=1&amp;rec=1" style="border:0;" alt="" /></p></noscript>
<!-- End Matomo Code -->

设置

UI语言

登录Matomo(之前叫Piwik)
点击右上角的齿轮小图标,进入设置界面
点击左菜单:Personal ==> settings.
设置中文(Language表单项,如下图)

访客IP不正确,访客IP全部变成了代理IP

[General]
assume_secure_protocol = 1

参见 http://www.matomo.net.cn/2019/03/setup-matomo-in-proxy-env/

; Uncomment line below if you use a standard proxy
proxy_client_headers[] = HTTP_X_FORWARDED_FOR
proxy_host_headers[] = HTTP_X_FORWARDED_HOST

疑惑

mamoto NPM failed to login:statcounter.carlzeng.top:4443

Error: The form security failed because of invalid origin. If you previously connected using HTTPS, please ensure you are connecting over a secure (SSL/TLS) connection and try again.

[done]本地局域网访问假如在config.ini.php中开启下面这条配置,会导致无法登录
;assume_secure_protocol = 1

Next

灵感来源

How to Install Matomo on Your Synology NAS

Matomo will always cost you nothing to use, but that doesn't mean it costs us nothing to make.
Matomo needs your continued support to grow and thrive.

Run Matomo – Google Analytics Alternative – in Docker

可能是世界上最牛逼的网站统计程序——Matomo

posted @ 2023-12-02 14:41  CarlZeng  阅读(81)  评论(0编辑  收藏  举报
域名已变更 请手动修改文章中域名指向carlzeng.com