Open main menu

Extension:Google Analytics Links

MediaWiki extensions manual
OOjs UI icon advanced.svg
Google Analytics Links
Release status: unmaintained
Implementation Tag , User activity
Description Enables outbound and file link tracking
Author(s) Nik Molnar (Algaetalk)
Latest version 1.2 (2009-12-28)
MediaWiki 1.23+
PHP 5.3+
Database changes No
License GNU General Public License 2.0 or later
Download see below
Example kJams
* <googa>
Translate the Google Analytics Links extension if it is available at
Check usage and version matrix.

The Google Analytics Links extension enables outbound and file link tracking.



Note: the third parameter is optional (the one starting with the last "|" and ending just before the "</")

<googa> Link Name|/fake/analytic/path</googa>
<googa>/local/|Pretty Link Name|/fake/analytic/path</googa>


For this extension to work the Google Analytics Integration extension must be installed first.
  • Add the following code at the bottom of your LocalSettings.php:
    require_once "$IP/extensions/GoogleAnalyticsLinks/GoogleAnalyticsLinks.php";
    // Place the above line AFTER the existing line: $googleAnalytics = "UA-xxxxxxx-1";
  •   Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.



	Google Analytics Links - v1.2
	(c)2007 Nik Molnar (
	Distributed UNDER THE TERMS OF GNU GPL Licence.
	This extension allows you to easily make use of Google Analytics to track non-HTML files (PDF, AVI, etc.) via JavaScript.
	For more information:
	Usage: (third parameter optional)
		<googa>|Link Name|/google/friendly/path</googa>
		<googa>/local/path/file.ext|Link Name|/google/friendly/path</googa>
		<googa>|Link Name|/google/friendly/path</googa>
	Output: <a href="" onClick="javascript:pageTracker._trackPageview('/google/friendly/path')">Link Name</a>

$wgExtensionCredits['parserhook'][] = array(
	'name'           => 'Google Analytics Links',
	'version'        => '1.2',
	'author'         => 'Nik Molnar',
	'description'    => 'Allows you to easily make use of Google Analytics to track non-HTML files.',
	'url'            => '',
	'path'           => __FILE__,

$wgExtensionFunctions[] = "wfGAnalyticsExtension";

// Register the hook
function wfGAnalyticsExtension() {
	global $wgParser;
	$wgParser->setHook("googa", "renderGAnalytics");

// Render function
function renderGAnalytics($input) {
	// Parse the arguments
	$args = split("[|]", $input);
	// If 3rd argument is absent, use the 1st argument.
	if(!isset($args[2])) { $args[2] = $args[0]; }
	// Return the rendered output
		"<a href=\"" . $args[0] .
		"\" class=\"external text\"" .
		" title=\"" . $args[0] . "\"" .
		" onClick=\"javascript:pageTracker._trackPageview('" . $args[2] .
		"');\">" . $args[1] .

See alsoEdit