Extension:GoogleAnalyticsMetrics/zh
![]() 發佈狀態: 穩定版本 |
|
---|---|
实现 | 解析器函数 |
描述 | Gets metrics from Google Analytics |
作者 | Ike Hecht (Tosfos讨论) |
维护者 | WikiTeq team |
最新版本 | 1.0.2 (2023年1月) |
兼容性政策 | 每个长期支持的MediaWiki版本,扩展都有对应的分支。 |
MediaWiki | 1.35, 1.39 |
数据库更改 | 否 |
Composer | mediawiki/google-analytics-metrics |
许可协议 | GNU通用公眾授權條款2.0或更新版本 |
下載 | |
|
|
季度下載量 | 3 (Ranked 173rd) |
翻譯GoogleAnalyticsMetrics的扩展,若在translatewiki.net可用 | |
問題 | 尚未完成的工作 · 报告錯誤 |
The GoogleAnalyticsMetrics extension gets various metrics from Google Analytics and inserts them into a wiki page using a parser function. This extension was created for WikiWorks.
The GoogleAnalyticsMetrics
extension may not be appropriate for your site if you have data security and privacy concerns.
The extensions inserts JavaScript code in each page served, and the code causes the client to contact Google services to process and aggregate data.
Your site's users will be subjected to tracking and data mining regardless of the Do Not Track or Global Privacy Control browser settings.
Installation
- Setup Google Analytics API by following Step 1 here
- Install the Google Client Library by following Step 2 here
- Enable Google Analytics Reporting API in your Google Cloud Console
- 下载文件,并将其放置在您
extensions/
文件夹中的GoogleAnalyticsMetrics
目录内。 - 只有從git安裝才运行Composer来安装PHP依赖,通过发行
composer install --no-dev
至扩展目录。 (参见任务T173141了解潜在问题。) - 将下列代码放置在您的
LocalSettings.php
的底部:wfLoadExtension( 'GoogleAnalyticsMetrics' );
完成 – 在您的wiki上导航至Special:Version,以验证已成功安装扩展。
Usage
The googleanalyticsmetrics
parser function takes three parameters, in the form of:
{{#googleanalyticsmetrics: metric=Name of metric|page=Page Name|startDate=Start date|endDate=End date}}
- Name of metric
- The name of the Google Analytics Metric that should be displayed. The full list of Google Analytics metrics is here. Omit the
ga:
prefix. - Page Name
- The name of the page. This parameter is only used when the metric is a per page metric.
- Start date
- Show the metric since this date (optional). Defaults to
2005-01-01
, which is the beginning of time according to Google Analytics. - End date
- Show the metric until this date (optional). Defaults to
today
.
Both date parameters use the form: Year-Month-Day.
Examples
This example displays the number of page views for this site, from the beginning until the end of time:
{{#googleanalyticsmetrics: metric=pageviews}}
Show the number of sessions from February 3, 2011 until today.
{{#googleanalyticsmetrics: metric=session|startDate=2011-02-03}}
Show the average session duration until February 1 2012:
{{#googleanalyticsmetrics: metric=avgSessionDuration|endDate=2012-02-01}}
Show the number of page views for last month only, with the help of the ParserFunctions extension:
{{#googleanalyticsmetrics: metric=pageviews|startDate={{#time:Y-m-d|first day of last month}}|endDate={{#time:Y-m-d|first day of this month}}}}
Or, to make that nicer:
{{formatnum:{{#googleanalyticsmetrics: metric=pageviews|startDate={{#time:Y-m-d|first day of last month}}|endDate={{#time:Y-m-d|first day of this month}}}}}}
Show the number of page views for a page, from the beginning until the end of time:
{{#googleanalyticsmetrics: metric=pageviews|page=Main_Page}}
See this page for some help with formatting this extension's output.
There is also a {{#googleanalyticstrackurl:http://urlhere|link text}}
function but it only works if the ga
js library has already been loaded.
Configuration parameters
- $wgGoogleAnalyticsMetricsAllowed
- An array containing the name of Google Analytics metrics that are allowed to be retrieved by the extension. Defaults to
*
, which allows all metrics. - $wgGoogleAnalyticsMetricsEmail
- The email address of the Google Analytics account.
- $wgGoogleAnalyticsMetricsPath
- Path to your certificate key file.
- $wgGoogleAnalyticsMetricsViewId
- Google Analytics View ID.
See also
此擴充功能包含在以下包或/和wiki農場: 這不是一份權威名單。即使一些wiki農場/託管者沒有被列在這裡,他們也可能包含這個extension。請以各wiki農場/託管者或包的狀態為準。 |