Extension:Google Analytics Links

From MediaWiki.org

Jump to: navigation, search
Manual on MediaWiki Extensions
List of MediaWiki Extensions
Google Analytics Links

Release status: stable

Implementation Tag, User activity
Description Enable outbound and file link tracking
Author(s) Nik Molnar
Version 1.2 (16-April-2007)
MediaWiki 1.5. X
Download see below

This extension provides a Wiki solution for the two questions posted here and here.
Use Extension talk:Google Analytics Links for feedback

Contents

[edit] Syntax

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

<googa>http://whatever.com/whatever/|Pretty Link Name|/fake/analytic/path</googa>
<googa>/local/link.xyz|Pretty Link Name|/fake/analytic/path</googa>

[edit] Requirements

For this extension to function, it requires that another extension be installed first that includes urchin.js from google:

Note: If you already have the other version installed, you must uninstall it first!

The extension found over on free.fr titled MediawikiEtGoogleAnalytics is using a deprecated function:

if (!$wgUser->isSysop()) {

isSysop() has been deprecated and should be changed to the following

if (!$wgUser->isAllowed('protect')) {

[edit] 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)
                <googa>http://yoursite.com/therealfile.pdf|Link Name|/google/friendly/path</googa>
                <googa>/local/path/file.ext|Link Name|/google/friendly/path</googa>
                <googa>http://external.com/whatever.html|Link Name|/google/friendly/path</googa>
        Output: <a href="http://yoursite.com/therealfile.pdf" onClick="javascript:urchinTracker('/google/friendly/path')">Link Name</a>
*/
 
$wgExtensionCredits['parserhook'][] = array(
        'name' => 'Google Analytics Links',
        'author' => 'Nik Molnar',
        'url' => 'http://www.mediawiki.org/wiki/Extension:Google_Analytics_Links',
        'description' => 'Allows you to easily make use of Google Analytics to track non-HTML files.',
);
 
$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
                "<a href=\"" . $args[0] .
                "\" class=\"external text\"" .
                " title=\"" . $args[0] . "\"" .
                " onClick=\"javascript:urchinTracker('" . $args[2] .
                "');\">" . $args[1] .
                "</a>";
}

[edit] Installation

  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 LocalSettings.php file
  4. After the existing line: $googleAnalytics = "UA-xxxxxxx-1"; insert this line:
//Google Analytics Links Extension http://www.mediawiki.org/wiki/Extension:Google_Analytics_Links
require_once("extensions/googa.php");

[edit] Examples

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

[edit] Related extensions

Personal tools