Jump to content
   (3 reviews)

About This File

GTag Extension for MediaWiki

The GTag extension lets you insert the new Google Analytics tracking tag on your MediaWiki site (gtag.js).


  • MediaWiki 1.35 or later


Download the file (a free account is required) and extract the file to your extensions directory. We recommend that you "follow" the download so that you are notified of new updates via email when they are released.

To install the extension, add the following to your LocalSettings.php file:

wfLoadExtension( 'GTag' );
$wgGTagAnalyticsId = 'UA-XXXXXXXX-X or G-XXXXXXXX'; // replace with your GA id


In addition to the required $wgGTagAnalyticsId, this extension features many optional configuration variables that you may add to your LocalSettings.php file.

  • $wgGTagAnalyticsId (string): Google Analytics ID, for example 'UA-XXXXXXXX-X' or 'G-XXXXXXXX'. Required.
  • $wgGTagAnonymizeIP (boolean, default false): If true, anonymize the IP address sent to Google Analytics.
  • $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.
  • $wgGTagHonorDNT (boolean, default true): 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.

In addition to these configuration variables, you may assign the right gtag-exempt to user groups to prevent them from being tracked. This can be useful to give to staff groups so that your internal users and staff are not tracked, giving you a better idea of who is actually using your site. For example:

$wgGroupPermissions['sysop']['gtag-exempt'] = true;


Free community support is available on the mwusers.org forums. Paid support plans are available as well.


What's New in Version 1.3.0   See changelog


Add new configuration variable $wgGTagEnableTCF (default false). If enabled, implements support for the IAB Transparency & Consent Framework used by many cookie consent widgets so that analytics cookies are not set until the user provides explicit consent. You will need to implement such a widget yourself.

Now requires MediaWiki 1.35+.

User Feedback

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.



   0 of 1 member found this review helpful 0 / 1 member

Had to update it to use the non-"UA-####-##" ids, but it works great so far!

Response from the author:

Can you send me some details either via the contact form below or on GitHub of what you needed to do in order for this to work for your site? I can get the documentation and/or code updated, but I'm not familiar with the non-UA ids.

  • Sad 1
Link to review
Diamond Dog

   0 of 1 member found this review helpful 0 / 1 member

using this resulted in a HTTP 500 error

Link to review
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.