Extension:GoogleAnalyticsMetrics/zh

This extension is professionally maintained by the WikiTeq team.
WikiTeq provides official support for MediaWiki LTS releases only. It may work with other MediaWiki releases.
Category:Extensions by WikiTeq/zh Category:GPL licensed extensions/zh
GoogleAnalyticsMetrics
Category:Stable extensions/zh
Category:Parser function extensions/zh
描述 Gets metrics from Google Analytics
作者 Ike Hecht (Tosfos留言)
WikiTeq team
最新版本 1.0.2 (2023年1月)
MediaWiki 1.35, 1.39Category:Extensions with manual MediaWiki version
GNU通用公眾授權條款2.0或更新版本
下載 Category:Extensions in Wikimedia version control/zh
  • $wgGoogleAnalyticsMetricsViewId
  • $wgGoogleAnalyticsMetricsExpiry
  • $wgGoogleAnalyticsMetricsAllowed
季度下載量 2 (Ranked 94th)
前往translatewiki.net翻譯GoogleAnalyticsMetrics
問題 开启的任务 ·
Category:All extensions/zh

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 clicking the button here
  • Install the Google Client Library for PHP by following the installation instructions here: here
  • Enable Google Analytics Reporting API in your Google Cloud Console
    • Grant Analytics API rights to a project
    • Create credentials in the project, adding a service account
    • Within the service account, create a new key in JSON format. Store the key file on your server on a path not accessible to the public.
    • Save the service account details in appropriate configuration parameters at the bottom of LocalSettings.php
  • 下载,并将解压后的GoogleAnalyticsMetrics移动到extensions/目录中。
    开发者和代码贡献人员应从Git安装扩展,输入:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/GoogleAnalyticsMetrics
  • 只有從git安裝才Composer来安装PHP依赖,发行composer install --no-dev目录。 (参见T173141了解潜在问题。)Category:Extensions requiring Composer with git/zh
  • 将下列放置在您的LocalSettings.php 的底部:
    wfLoadExtension( 'GoogleAnalyticsMetrics' );
    
  • Yes 完成 – 在您的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

Category:Google extensions/zh Category:Web Analytics extensions/zh Category:Statistics extensions/zh
Category:All extensions/zh Category:Extensions by WikiTeq/zh Category:Extensions in Wikimedia version control/zh Category:Extensions included in Canasta/zh Category:Extensions requiring Composer with git/zh Category:Extensions with manual MediaWiki version Category:GPL licensed extensions/zh Category:Google extensions/zh Category:ParserFirstCallInit extensions/zh Category:Parser function extensions/zh Category:Stable extensions/zh Category:Statistics extensions/zh Category:Web Analytics extensions/zh