Extension:Google Analytics Integration

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
Google Analytics Integration

Release status: stable

Implementation User activity
Description Automatically inserts Google Analytics tracking code at the bottom of MediaWiki pages
Author(s) Tim Laquatalk
Latest version 2.0.2 (2009-12-16)
MediaWiki 1.11+
Database changes No
License GNU General Public License 2.0 or later
Example Wikimini (view page source at the bottom)
  • $wgGoogleAnalyticsAccount
  • $wgGoogleAnalyticsIgnoreSysops
  • $wgGoogleAnalyticsIgnoreBots
  • $wgGoogleAnalyticsAddASAC
Hooks used


Translate the Google Analytics Integration extension if possible

Check usage and version matrix; code metrics

The Google Analytics Integration extension inserts Google Analytics tracking code in every page viewed. The extension excludes pages being viewed by users with 'protect' privileges (sysops) and users with 'bot' privileges (bots) to prevent pollution of the statistics. To use a version that also ignores logged-in users, see the 'See also' section at the end of this page.

Download[edit | edit source]

You can download the extension directly from the MediaWiki source code repository (browse code). You can get:

One of the extensions tags

Not all extensions have tags. Some extensions have tags for each release, in which case those tags have the same stability as the release. To download a tag

  • Go to the tags list
  • Click the name of the tag you want to download
  • Click "snapshot"
The latest version of one of the extensions branches

Each extension has a master branch containing the latest code (might be unstable). Extensions can have further branches as well.

  • Go to the branches list
  • Click the branch name
  • Click "snapshot"
A snapshot made during the release of a MediaWiki version.

This might be unstable and is not guaranteed to work with the associated MediaWiki version.

After you've got the code, save it into the extensions/googleAnalytics directory of your wiki.

If you are familiar with git and have shell access to your server, you can obtain the extension, with all its tags and branches, as follows:

cd extensions
git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/googleAnalytics.git

Installation[edit | edit source]

  • Download and extract the files in a directory called googleAnalytics in your extensions/ folder. If you're a developer and this extension is in a Git repository, then instead you should clone the repository.
  • Add the following code at the bottom of your LocalSettings.php:
require_once( "$IP/extensions/googleAnalytics/googleAnalytics.php" );
// Replace xxxxxxx-x with YOUR GoogleAnalytics UA number
$wgGoogleAnalyticsAccount = "UA-xxxxxxx-x"; 
// Optional Variables (both default to true)
$wgGoogleAnalyticsIgnoreSysops = false;
$wgGoogleAnalyticsIgnoreBots = false;
// If you use AdSense as well and have linked your accounts, set this to true to enable tracking
$wgGoogleAnalyticsAddASAC = false;
  • Done! Navigate to "Special:Version" on your wiki to verify that the extension is successfully installed.

Usage[edit | edit source]

  1. Create a Google Analytics account
  2. Locate your UA number
    • For the legacy code block, it can be found on the following line:
    • For the new ga.js code block, it can be found on the following line:
      var pageTracker = _gat._getTracker("UA-xxxxxxx-x");
  3. Follow Installation Instructions
  4. Google Analytics stats should start populating within 24-48 hours.

Bugs[edit | edit source]

The error message before this fix is:

MediaWiki internal error. Exception caught inside exception handler.
  • The googleAnalytics.php file will override your variables that were set in the LocalSettings.php file if you include it after you set these variables. It will appear to not work because you'll probably be logged in as a SysOp and it ignores you for the statistics by default. Solution: It should check the variables (isset)

See also[edit | edit source]

  • Google Analytics - this same extension but also allows you to ignore logged in users (new variable is used, $wgGoogleAnalyticsIgnoreUsers). This is useful since if we want true visitors statistics, we want to ignore logged-in users who are often 'wiki-workers' and perhaps we dont want to include their stats since they could have lots of page views, like sysops.(If you use the "following fix" from Bugs (above), edit line 25 from your googleAnalytics.php.)
  • User:Dantman/Analytics integration - Techniques on how to flexibly add analytics without using extensions.
  • Extension:Open Web Analytics - Similar extension using Open Web Analytics.
Language: English  • русский