Extension:Matomo
发行状态: 稳定版 |
|
|---|---|
| 实现 | 用户活动 |
| 描述 | 将Matomo脚本插入页面以进行跟踪 |
| 作者 | |
| 最新版本 | 5.0.0 (2023-10-27) |
| MediaWiki | 1.34+ |
| PHP | 7.2+ |
| Composer | mediawiki/matomo |
| 许可协议 | GNU通用公眾授權條款2.0或更新版本 |
| 下載 | README |
|
|
|
Matomo擴充功能(原名「Piwik Integration」)會在每個頁面的底部插入您的Matomo(原名Piwik)追蹤代碼。 它可以排除具有「機器人」權限(機器人)和「保護」權限(系統管理員)的使用者所發出的意見。
此擴充功能基於Tim Laqua所開發的擴充功能Google Analytics Integration。
此擴充功能於2019年2月更名,由「Piwik Integration」改為「Matomo」,鑒於其底層軟體已於2018年1月更名(更多說明)。
安装
- 下载文件,并将其放置在您
extensions/文件夹中的Matomo目录内。 - 請新增下列代码到您的LocalSettings.php文件的底部:
wfLoadExtension( 'Matomo' );
- 請透過設定下列在此擴充功能呼叫下方的變數,來配置Matomo的網址與網站識別碼:
$wgMatomoURL = "matomo-host.tld/dir";
$wgMatomoIDSite = "piwik_idsite";
請務必將$wgMatomoIDSite設定為您在Matomo中的網站ID。
對於第一個網站,此識別碼通常為「1」。
在Matomo中,點擊頂部選單中的「管理」連結,前往「網站」頁面。
在此頁面中,您將找到所有網站的清單。
網站ID位於此表格的左側,該表格列出了所有網站。[1]
$wgMatomoURL的協定
完成 – 請导航至您的wiki上的Special:Version,以验证此扩展已成功安装。- 您可嘗試造訪維基上的某些頁面,並檢查此造訪紀錄是否顯示於Matomo中。若未顯示,請確認您的使用者設定檔未被忽略(例如您身為系統管理員、且
$wgMatomoIgnoreSysops的設定是true),並請參閱此篇在Matomo.org上的說明文件。
升级
此擴充功能自 4.0 版本起,由「Piwik Integration」更名為「Matomo」:
- 若您以 Composer 安裝此套件,請將套件「mediawiki/piwik-integration」重新命名為「mediawiki/matomo」;
- 若您是以傳統的MediaWiki擴充功能方式安裝,請將目錄「Piwik」或「Piwik Integration」重新命名為「Matomo」。
在兩種情況中,您現在都需要以wfLoadExtension( 'Matomo' );明確地啟動此擴充功能。
配置参数
將$wgMatomoDisableCookies變數設定為true以停用Cookie。
例如:
$wgMatomoDisableCookies = true;
要在Matomo JavaScript程式碼中定義自訂的JavaScript標籤,可以透過定義$wgMatomoCustomJS變數來實現。 例如,您有一個單一的設定想要插入,請使用以下程式碼:
$wgMatomoCustomJS = "_paq.push(['trackGoal', '1']);";
若你有多個變數需要去定義,請使用陣列。 例如:
$wgMatomoCustomJS = array(
"_paq.push(['setCustomVariable', '1','environment','production']);",
"_paq.push(['setCustomVariable', '1','is_user','yes']);"
);
若您想在Matomo追蹤器內變更頁面的標題,請在您的LocalSettings.php檔案中設定$wgMatomoActionName。
萬一您想要將標題包含在內,例如「wiki/頁面標題」,可將$wgMatomoUsePageTitle設為true、且將$wgMatomoActionName設為wiki/。
此擴充功能將輸出piwik_action_name =「wiki/頁面標題」;
你可透過將$wgMatomoIgnoreSysops設定為false,讓Matomo也去統計那些擁有MediaWiki的「protect」使用者權限的使用者所產生的頁面點擊次數。
預設情況下,系統管理員用戶擁有此權限,因此——在預設情況下——他們的頁面瀏覽次數不會被計入統計。
預設:$wgMatomoIgnoreSysops = true。
你可透過將$wgMatomoIgnoreBots設定為false,讓Matomo也去統計那些擁有MediaWiki的機器人權限的使用者所產生的頁面點擊次數。
預設情況下,他們的頁面點擊次數不會被計入統計。
預設:$wgMatomoIgnoreBots = true。
當 JavaScript 被停用時,會使用某個隱藏圖片的方法作為後備方案。
您可以透過$wgMatomoProtocol設定呼叫此圖片的通訊協定(HTTP或HTTPS),選用下列任一值:'http'、'https'、'auto'(系統將根據維基使用的協定自動設定)。
若您使用的是 Matomo 2.7.0 或更高版本,可設定$wgMatomoTrackUsernames來儲存在Matomo中的已登入使用者的使用者名稱。
若您使用CDN來散播「piwik.js」檔案,則需採用合併提取要求(PR)的版本(2.4.3+),並可設定參數$wgMatomoJSFileURL = 'assets.example.org/piwik.js';(無需手動輸入協議"http://"或"https://",系統會自動添加);參數$wgMatomoURL仍須設置為收集分析數據的Matomo伺服器。
使用移动版前端进行跟踪
Due to a bug in Hooks/SkinAfterBottomScripts, Matomo will not function when 'Mobile view' mode is used with the MobileFrontend Extension.
For those desiring to track across both views, comment or delete the Matomo entries in LocalSettings.php and add to the file:
$wgUseSiteJS = true;
Then paste the Matomo tracking code generated in the Matomo dashboard into http://www.example.com/wiki/MediaWiki:Common.js. Matomo will now track users in both Desktop view and Mobile view.
Take care: This workaround currently breaks the VisualEditor Extension. (2015-10-01)
針對MediaWiki优化的Matomo配置
搜索参数
By default Matomo recognize the searches on the internal search engine (the page Special:Search), because the URL parameter used by MediaWiki ("search") is in the default recognized parameters.
This can also be slightly improved by setting the two parameters:
- "Query parameter" = "search" — this will remove some false positives compared to the default value;
- "Category parameter" = "profile" — Matomo will recognize as search category the profile on top of the MediaWiki search page.
This can be either as global parameters in Administration > Websites > Settings > Tracking Internal Site Search, but preferably in the site-specific configuration in Administration > Websites > Manage > [your wiki] > Edit and uncheck "Use default Site Search parameters" and fill the parameters.
参阅
參考資料
- Stable extensions/zh
- User activity extensions/zh
- Extensions supporting Composer/zh
- GPL licensed extensions/zh
- Extensions in GitHub version control/zh
- SkinAfterBottomScripts extensions/zh
- SpecialSearchResults extensions/zh
- SpecialSearchSetupEngine extensions/zh
- All extensions/zh
- Pages using deprecated NoteTA template
- Web Analytics extensions/zh
- Statistics extensions/zh
