Im in yr wiki, trackin yr error messages.
November 29, 2012 2:37 PM   Subscribe

I have a MediaWiki installation on new hardware to replace an old public website. Occasionally someone visits the site using a dead link and gets MediaWiki's "There is currently no text in this page". I can customize the message they get, but how can I get a notification (ideally with Google Analytics custom variables) whenever this happens, without using GA's standard Javascript?

This is probably a simple question, but I know very little PHP and even less Javascript, so here we are.

I moved my lab's website to MediaWiki (previously), where all pages are publicly viewable, but only I can edit them.

I have a Google Analytics account for the site, working seamlessly per these instructions. The problem is that I'll occasionally see someone hit the site using an old link, because the MediaWiki page that they enter on is called /~oldlabmember/info.html. I know they're seeing MediaWiki's "There is currently no text in this page." error and getting confused. (Big surprise that there's no page with that name!) I'd like to see when and where this happens so I can put up a redirect on pages where it occurs more than once.

I know that I could create a Custom Variable in Google Analytics that would show up whenever someone hits a certain page and loads a bit of Javascript. I can customize this system message, so I could insert this code, in theory. The problem is that Javascript (which the Custom Variable code uses) is blocked by MediaWiki as a security risk (and rightly so).

I can put the script in Mediawiki:Missing_Page.js or something, but I can't figure out how to only call that when a user hits a "There is currently no text..." page (i.e., not calling Missing_Page.js in Common.js on every single page load).

How do I get around this? An invisible pixel tracking system would work, but I'd really rather not sign up for another analytics account that uses 1x1 gifs for tracking. Moving over ALL the old files from the previous server is even less appealing (especially since I've already moved some into more logical locations on the new server).

posted by supercres to Computers & Internet (3 answers total)
If it were me, I would catch this at the Apache (or IIS) level and provide a static HTML page explaining that the site has been moved over to a wiki, bla bla bla. Analytics JS could be inserted into this page.

Assuming Apache and no wiki pages that start with /~, you could use RedirectMatch (/~.*) http://yourserver/oldpage.html?orig=$1 or similar.
posted by smammy at 3:03 PM on November 29, 2012

Thanks-- that's a better idea than anything I had.

It is Apache. The only problem is that it's not only old user pages (/~*) that are being caught-- there are also paths like http://myserver/files/pubs/BlahBlah.pdf that are getting pushed to a MediaWiki "new page" if they're not capitalized just right (e.g., Blahblah.pdf). That might be a separate issue, fixable separately, though.

Oh, the other problem is that I have set up redirects for more common broken landing pages, like http://myserver/~myboss can redirect to http://myserver/My_I._Boss, which is useful. I caught that one and a few more by noticing them in Analytics logs when the site had just gone live. Now a bad URL with one or two hits gets buried.
posted by supercres at 3:19 PM on November 29, 2012

In case anyone finds this:

I didn't even think of looking for 404 tracking solutions, which someone on the GA boards suggested. That search pointed me to this, which does exactly what I need.

I figured out another solution in the meantime, actually, that calls on MW syntax. My widget (using the MediaWiki "widgets" extension to get around the script restrictions) looks like this:
<script type="text/javascript">
_gaq.push(['_trackEvent', 'WikiEvents', 'LogMissing', '<!--{$pagename|escape:'quotes'}-->']);
And is called with this code:
So the page name gets inserted as one of the event fields. So it seems like either way would work to report the missing page name/URL as a GA event.
posted by supercres at 7:45 AM on January 23, 2013

« Older Which personal fitness gizmo do I want?   |   Safari Bookmark That Controls Scroll Position Newer »
This thread is closed to new comments.