Extension:Google Analytics Links

This extension provides a Wiki solution for the two questions posted here and here. Use Extension Talk:Google_Analytics_Links for feedback

Syntax
Note: the third parameter is optional (the one starting with the last "|" and ending just before the "isSysop) { I'm not sure why, so I changed it to: if ($wgUser->getName != "Dave") { (Since my login name is "Dave" on my wiki, you should change this line to your name or your wiki admin's name)

Code
<?php

/*	Google Analytics Links - v1.2 (c)2007 Nik Molnar (nik.molnar@gmail.com) 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: http://www.google.com/support/analytics/bin/answer.py?answer=27242 Usage: (third parameter optional) http://yoursite.com/therealfile.pdf|Link Name|/google/friendly/path /local/path/file.ext|Link Name|/google/friendly/path http://external.com/whatever.html|Link Name|/google/friendly/path Output: Link Name

$wgExtensionFunctions[] = "wfGAnalyticsExtension";

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

//Render function function renderGAnalytics($input) { //Pase 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 return "". $args[1]. ""; }

?>

Installation
//Google Analytics Links Extension http://www.mediawiki.org/wiki/Extension:Google_Analytics_Links include_once("extensions/googa.php");
 * 1) copy the above code to a new text file called "googa.php"
 * 2) place that file in your /wiki/extensions/ folder
 * 3) edit your /wiki/LocalSettings.php file
 * 4) After the existing line: $googleAnalytics = "UA-xxxxxxx-1"; insert this line:

Examples
See examples of this extension in action at these fine wikis: kJams

Related extensions
Google Analytics