texxasrulez/matomo_analytics 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

texxasrulez/matomo_analytics

Composer 安装命令:

composer require texxasrulez/matomo_analytics

包简介

Matomo Analytics integration plugin for Roundcube

README 文档

README

Packagist Downloads Packagist Version Github License GitHub Stars GitHub Issues GitHub Contributors GitHub Forks Donate Paypal

This plugin integrates Matomo Analytics into Roundcube by injecting the official Matomo tracking snippet on rendered pages.

Why this exists

Older Roundcube plugins targeted Piwik (Matomo's former name). This plugin is a clean Matomo-first replacement with simple configuration and privacy-aware defaults.

Features

  • Injects Matomo tracking script on all Roundcube pages.
  • Optional Do Not Track (DNT) honoring.
  • Optionally disable tracking for authenticated users.
  • Composer-installable, using composer/installers.
  • Zero changes required to Roundcube templates.

Installation

A) Composer (recommended)

From your Roundcube installation root:

composer require texxasrulez/matomo_analytics

This will install the plugin into plugins/matomo_analytics/.

B) Manual installation

  1. Download the release archive.
  2. Extract into your Roundcube plugins/ directory so it looks like:
roundcubemail/
└── plugins/
    └── matomo_analytics/
        ├── matomo_analytics.php
        ├── config.inc.php.dist
        └── composer.json

Configuration

Note on Matomo URL: You may set matomo_analytics_url to a full URL (https://analytics.example.com/matomo) or a relative path (e.g., /matomo). The plugin normalizes relative values to an absolute URL using window.location.origin. If you see .../mail/matomo.js 404s, your URL was relative without a leading slash (matomo); use /matomo or the full URL.

Copy the sample config and edit values:

cp plugins/matomo_analytics/config.inc.php.dist plugins/matomo_analytics/config.inc.php

Open plugins/matomo_analytics/config.inc.php and set:

// Matomo base URL (no trailing slash)
$config['matomo_analytics_url'] = 'https://analytics.example.com';

// Matomo site ID (integer)
$config['matomo_analytics_site_id'] = 1;

// Respect browser Do Not Track header
$config['matomo_analytics_respect_dnt'] = true;

// Disable tracking for authenticated Roundcube users
$config['matomo_analytics_disable_for_authenticated'] = false;

Enabling the plugin

Edit config/config.inc.php in your Roundcube installation and add the plugin:

$config['plugins'][] = 'matomo_analytics';

Clear Roundcube caches if necessary:

bin/cleancache.sh

How it works

The plugin hooks into Roundcube's render_page event and injects the official Matomo loader:

var _paq = window._paq = window._paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);

(function() {
  var u = '<MATOMO_URL>/';
  _paq.push(['setTrackerUrl', u+'matomo.php']);
  _paq.push(['setSiteId', '<SITE_ID>']);
  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);
})();

When respect_dnt is enabled, the plugin checks the browser's DNT flags and skips injection if enabled. When disable_for_authenticated is true, no tracking is injected for logged-in users.

Debugging

Set options in plugins/matomo_analytics/config.inc.php:

$config['matomo_analytics_debug_enabled'] = true;          // write debug entries to Roundcube logs
$config['matomo_analytics_debug_html_comments'] = true;    // add HTML comment after injection
$config['matomo_analytics_debug_log_channel'] = 'matomo_analytics'; // optional custom log channel

View logs at logs/matomo_analytics (or your custom channel). Entries are JSON-encoded with event tags like init, render_page:start, render_page:skip:*, render_page:injected, render_page:error.

Smoke test

  1. Enable the plugin and set debug_enabled = true.
  2. Load Roundcube UI and check:
    • View Source: find the Matomo snippet, and optionally the <!-- matomo_analytics: injected tracking snippet --> comment.
    • logs/matomo_analytics: verify entries for injection and config.
  3. Toggle disable_for_authenticated and respect_dnt to verify skip paths.

Debugging & Verification

Enable debug in plugins/matomo_analytics/config.inc.php:

$config['matomo_analytics_debug_enabled'] = true;
$config['matomo_analytics_debug_html_comments'] = true;
$config['matomo_analytics_debug_console'] = true;

Open the Roundcube UI:

  • View Source → Confirm the Matomo snippet and optional <!-- matomo_analytics: injected tracking snippet -->.
  • Browser Console → Look for [matomo_analytics] injecting info line.
  • Network tab → Verify matomo.js loads 200 and matomo.php requests show 200/204 with idsite=<your id>.
  • Roundcube logs (logs/matomo_analytics) → JSON events for injection/skip/errors.

Common blockers

  • Content-Security-Policy headers must allow script-src from your Matomo origin and img-src for the beacon.
  • Ad/tracking blockers can block matomo.js or matomo.php. Test in a private window with blockers disabled.
  • Mixed Content: Roundcube must be served over HTTPS if Matomo URL is HTTPS (and vice versa). Avoid protocol mismatches.
  • Wrong Site ID / URL: Confirm the Site ID matches exactly in your Matomo UI and that the URL points to the Matomo root.

Extras

  • Cross-domain/subdomain tracking:
    $config['matomo_analytics_cookie_domain'] = '.example.com';
    $config['matomo_analytics_domains'] = ['*.example.com'];
  • Time-on-page accuracy:
    $config['matomo_analytics_enable_heartbeat'] = true;
  • JS-blocked environments: enable <noscript> beacon:
    $config['matomo_analytics_fallback_img_beacon'] = true;

Requirements

  • PHP >= 7.4
  • Roundcube >= 1.4
  • A running Matomo server (URL + Site ID)

Uninstall

Composer:

composer remove texxasrulez/matomo_analytics

Manual: delete the plugins/matomo_analytics/ directory.

License

MIT

texxasrulez/matomo_analytics 适用场景与选型建议

texxasrulez/matomo_analytics 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 08 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「plugin」 「analytics」 「roundcube」 「matomo」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 texxasrulez/matomo_analytics 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 texxasrulez/matomo_analytics 我们能提供哪些服务?
定制开发 / 二次开发

基于 texxasrulez/matomo_analytics 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 12
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-19