Extension:GTag

Category:Extensions without an imageCategory:MIT licensed extensions
MediaWiki extensions manual
GTag
Release status: stableCategory:Stable extensions
Implementation User activity Category:User activity extensions
Description Add Google Analytics tracking to pages
Author(s) Skizzerztalk
Latest version 1.4.0 (2025-02-09)
Compatibility policy Master maintains backward compatibility.Category:Extensions with master compatibility policy
MediaWiki 1.39+Category:Extensions with manual MediaWiki version
Database changes No
License MIT License
Download Category:Extensions in GitHub version control
  • $wgGTagAnalyticsId
  • $wgGTagAnonymizeIP
  • $wgGTagEnableTCF
  • $wgGTagHonorDNT
  • $wgGTagTrackSensitivePages
Category:All extensions

The GTag extension lets you insert the new Google Analytics tracking tag on your MediaWiki site ("gtag.js"). It additionally supports making use of a GTM ID to insert a Google Tag Manager container instead of the gtag.js tracker, for people who make use of Google Tag Manager.

Download

Installation

  • Download and place the file(s) in a directory called GTag in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'GTag' );
    $wgGTagAnalyticsId = 'UA-xxxxxxxxx-x' or 'G-XXXXXXXX'; // replace this with your Google Analytics id
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Configuration parameters

$wgGTagAnalyticsId (string)
Google Analytics ID or Google Tag Manager container ID, for example 'GT-NNVDXRX5' or 'GTM-MG9RFZQQ'. Required.
$wgGTagAnonymizeIP (boolean, default false)
If true, anonymize the IP address sent to Google Analytics. Ignored when operating in Google Tag Manager mode.
$wgGTagEnableTCF (boolean, default false)
If true, support the IAB Transparency & Consent Framework used by many 3rd party cookie consent widgets. You will need to implement such a widget yourself into your wiki; the extension does not come with one. Ignored when operating in Google Tag Manager mode.
$wgGTagHonorDNT (boolean, default false)
If true, honor "Do Not Track" requests from browsers. If false, ignore such requests.
$wgGTagTrackSensitivePages (boolean, default true)
If true, insert tracking code into sensitive pages such as Special:UserLogin and Special:Preferences. If false, no tracking code is added to these pages.

User rights

gtag-exempt
Users granted this right will not be tracked by Google Analytics. This can be useful to exempt staff groups from being tracked, to get a better idea of what your end users are doing on the wiki.

See also

Category:Web Analytics extensions Category:Google extensions
Category:All extensions Category:BeforePageDisplay extensions Category:Extensions in GitHub version control Category:Extensions included in Canasta Category:Extensions which add rights Category:Extensions with manual MediaWiki version Category:Extensions with master compatibility policy Category:Extensions without an image Category:Google extensions Category:MIT licensed extensions Category:Stable extensions Category:User activity extensions Category:Web Analytics extensions