Extension:Google Analytics Integration

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

Release status: stable

Implementation User activity
Description Automatically inserts Google Universal Analytics (and/or other web analytics) tracking code at the bottom of MediaWiki pages
Author(s) Tim Laqua, Dāvis Mošenkovs
Latest version 3.0.1 (2015-03-14)
MediaWiki 1.11+
Database changes No
License GNU General Public License 2.0 or later
Example Projects by Davis Mosenkovs (view page source at the bottom)
  • $wgGoogleAnalyticsAccount
  • $wgGoogleAnalyticsOtherCode
  • $wgGoogleAnalyticsAnonymizeIP
  • $wgGoogleAnalyticsIgnoreNsIDs
  • $wgGoogleAnalyticsIgnorePages
  • $wgGoogleAnalyticsIgnoreSpecials
Added rights
  • noanalytics
Hooks used

Translate the Google Analytics Integration extension if it is available at translatewiki.net

Check usage and version matrix; code metrics

The Google Analytics Integration extension inserts Google Universal Analytics (and/or other web analytics) tracking code in every page viewed. Exclusion of specific pages, namespaces, special pages and all pages for specific groups of users is configurable.

Installation[edit | edit source]

  • Download and place the file(s) in a directory called googleAnalytics in your extensions/ folder.
  • 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'; 
// Add HTML code for any additional web analytics (can be used alone or with $wgGoogleAnalyticsAccount)
$wgGoogleAnalyticsOtherCode = '<script type="text/javascript" src="https://analytics.example.com/tracking.js"></script>';

// Optional configuration (for defaults see googleAnalytics.php)
// Store full IP address in Google Universal Analytics (see https://support.google.com/analytics/answer/2763052?hl=en for details)
$wgGoogleAnalyticsAnonymizeIP = false; 
// Array with NUMERIC namespace IDs where web analytics code should NOT be included.
$wgGoogleAnalyticsIgnoreNsIDs = array(500);
// Array with page names (see magic word Extension:Google Analytics Integration) where web analytics code should NOT be included.
$wgGoogleAnalyticsIgnorePages = array('ArticleX', 'Foo:Bar');
// Array with special pages where web analytics code should NOT be included.
$wgGoogleAnalyticsIgnoreSpecials = array( 'Userlogin', 'Userlogout', 'Preferences', 'ChangePassword', 'OATH');
// Use 'noanalytics' permission to exclude specific user groups from web analytics, e.g.
$wgGroupPermissions['sysop']['noanalytics'] = true;
$wgGroupPermissions['bot']['noanalytics'] = true;
// To exclude all logged in users give 'noanalytics' permission to 'user' group, i.e.
$wgGroupPermissions['user']['noanalytics'] = true;
  • YesY Done - Navigate to Special:Version on your wiki to verify that the extension is successfully installed.
The following options were removed in version 3.0.0:
  • $wgGoogleAnalyticsAddASAC
  • $wgGoogleAnalyticsIgnoreSysops
  • $wgGoogleAnalyticsIgnoreBots

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 that settings are not working. Solution: Check the variables.

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.) fork of version 2.0.1 of this extension.
  • User:Dantman/Analytics integration - Techniques on how to flexibly add analytics without using extensions. This technique does not work on MobileFrontend.
  • Extension:Open Web Analytics - Similar extension using Open Web Analytics.
Language: English  • русский