Extension:Google Analytics
From MediaWiki.org
- For a better updated extension with more features, please see: Extension:Google Analytics Integration
|
Release status: stable |
|
|---|---|
| Implementation | Tag, User activity |
| Description | Enable Google Analytics within your wiki |
| Author(s) | Naoise Golden Santos |
| Last Version | 1.0 (1-29-2007) |
| License | No license specified |
| Download | see below |
| Example | live demo |
|
check usage (experimental) |
|
Analytics is a simple extension which allows you to put a Google Analytics tracker in your MediaWiki articles, so you can obtain statistics on the articles that you are interested in.
Contents |
[edit] Usage
<analytics uacct="UA-XXXXXX-X" ></analytics>
[edit] Source code
Source code of "extensions/analytics.php":
<?php # Google Analytics MediaWiki extension # by Naoise Golden Santos (naoise at goldensantos dot com) # http://www.goldensantos.com # Usage: # <analytics uacct="UA-XXXXXX-X" ></analytics> # To install it put this file in the extensions directory # To activate the extension, include it from your LocalSettings.php # with: require("extensions/analytics.php"); $wgExtensionFunctions[] = "wfAnalytics"; function wfAnalytics() { global $wgParser; # registers the <analytics> extension with the WikiText parser $wgParser->setHook( "analytics", "renderAnalytics" ); } # The callback function for converting the input text to HTML output function renderAnalytics( $input, $argv ) { $output = '<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">'; $output .= '</script>'; $output .= '<script type="text/javascript">'; $output .= '_uacct = "'.$argv["uacct"].'";'; $output .= 'urchinTracker();'; $output .= '</script>'; return $output; } ?>
Considering that this page was not updated since January 2007, I updated it with the new Google Analytics code:
[edit] Source code
Source code of "extensions/analytics.php":
<?php # Google Analytics MediaWiki extension # by Naoise Golden Santos (naoise at goldensantos dot com) # http://www.goldensantos.com # Modified for the new Google Code # Modified by Fernando Azevedo (fazevedo at fazevedo dot org) # http://www.fazevedo.org # Usage: # <analytics uacct="UA-XXXXXX-X" ></analytics> # To install it put this file in the extensions directory # To activate the extension, include it from your LocalSettings.php # with: require("extensions/analytics.php"); $wgExtensionFunctions[] = "wfAnalytics"; function wfAnalytics() { global $wgParser; # registers the <analytics> extension with the WikiText parser $wgParser->setHook( "analytics", "renderAnalytics" ); } # The callback function for converting the input text to HTML output function renderAnalytics( $input, $argv ) { $output = '<script type="text/javascript">'; $output .= 'var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");'; $output .= 'document.write(unescape("%3Cscript src='."'".'" + gaJsHost + "google-analytics.com/ga.js'; $output .= "'".' type='."'".'text/javascript'."'".'%3E%3C/script%3E"));'; $output .= '</script>'; $output .= '<script type="text/javascript">'; $output .= 'try {'; $output .= 'var pageTracker = _gat._getTracker("'.$argv["uacct"].'");'; $output .= 'pageTracker._trackPageview();'; $output .= '} catch(err) {}</script>'; return $output; } ?>
[edit] More info
- See a live demo.
- http://www.google.com/analytics/
- It is possible to use Google Analytics in MediaWiki without tracking sysop users. However, you will need to modify the source code of your SkinTemplate.php file. For more info: http://www.pesme.net.
- You can also track outbound links and direct file downloads (requires use of previous link) more info here.
[edit] See also
- Extension:Google Analytics Integration (this extension has an option to disable tracking of sysops and bots)