<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Guy Rutenberg &#187; JavaScript</title>
	<atom:link href="http://www.guyrutenberg.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.guyrutenberg.com</link>
	<description>Keeping track of what I do</description>
	<lastBuildDate>Sat, 14 Jan 2012 11:30:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>LaTeX for TiddlyWiki &#8211; A MathJax Plugin</title>
		<link>http://www.guyrutenberg.com/2011/06/25/latex-for-tiddlywiki-a-mathjax-plugin/</link>
		<comments>http://www.guyrutenberg.com/2011/06/25/latex-for-tiddlywiki-a-mathjax-plugin/#comments</comments>
		<pubDate>Sat, 25 Jun 2011 14:05:31 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[LaTeX]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[MathJax]]></category>
		<category><![CDATA[TiddlyWiki]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=825</guid>
		<description><![CDATA[Some time ago I came across MathJax, a nifty, Javascript based engine for displaying TeX and LaTeX equations. It works by &#8220;translating&#8221; the equation to MathML or HTML+CSS, so it works on all modern browsers. The result isn&#8217;t a raster image, like in most LaTeX solutions (e.g. MediaWiki), so it&#8217;s scales with the text around [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago I came across <a href="http://www.mathjax.org/">MathJax</a>, a nifty, Javascript based engine for displaying TeX and LaTeX equations. It works by &#8220;translating&#8221; the equation to MathML or HTML+CSS, so it works on all modern browsers. The result isn&#8217;t a raster image, like in most LaTeX solutions (e.g. MediaWiki), so it&#8217;s scales with the text around it. Furthermore, it&#8217;s quite easy to integrate as it doesn&#8217;t require any real installation, and you could always use MathJax&#8217;s own CDN, which makes things even simpler.</p>
<p><div id="attachment_829" class="wp-caption aligncenter" style="width: 469px"><a href="http://www.guyrutenberg.com/wp-content/uploads/2011/06/mathjax1.png"><img src="http://www.guyrutenberg.com/wp-content/uploads/2011/06/mathjax1.png" alt="TiddlyWiki with the MathJaxPlugin" title="TiddlyWiki with the MathJaxPlugin" width="459" height="219" class="size-full wp-image-829" /></a><p class="wp-caption-text">A tiddler with LaTeX equations.</p></div><span id="more-825"></span></p>
<p>I quickly realized MathJax will be a perfect fit for TiddlyWiki which is also based on pure Javascript. It will allow me to enter complex formulas in tiddlers and still be able to carry my wiki anywhere with me, independent of a real TeX installation. I searched the web for an existing MathJaX plugin for TiddlyWiki but I came up empty handed (I did find some links, but they referenced pages that no longer exist). So I regarded it as a nice opportunity to begin writing some plugins for TiddlyWiki and created the MathJaxPlugin which integrates MathJax with TiddlyWiki.</p>
<p>As I don&#8217;t have an online TiddlyWiki, you&#8217;ll won&#8217;t be able to import the plugin, instead you&#8217;ll have to install it manually (which is pretty simple).</p>
<p>Start by creating a new tiddler named <code>MathJaxPlugin</code>, and tag with <code>systemConfig</code> (this tag will tell TiddlyWiki to execute the JS code in the tiddler, thus making it a plugin. Now copy the following code to the tiddler content:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/***
|''Name:''|MathJaxPlugin|
|''Description:''|Enable LaTeX formulas for TiddlyWiki|
|''Version:''|1.0.0|
|''Date:''|Jun 25, 2011|
|''Source:''|http://www.guyrutenberg.com/2011/06/25/latex-for-tiddlywiki-a-mathjax-plugin|
|''Author:''|Guy Rutenberg|
|''License:''|[[BSD open source license]]|
|''~CoreVersion:''|2.5.0|
&nbsp;
Currently the plugin supports the following delemiters:
* &quot;&quot;&quot;$$&quot;&quot;&quot;..&quot;&quot;&quot;$$&quot;&quot;&quot; - Inline equations
* &quot;&quot;&quot;\(&quot;&quot;&quot;..&quot;&quot;&quot;\)&quot;&quot;&quot; - Inline equations
* &quot;&quot;&quot;\[&quot;&quot;&quot;..&quot;&quot;&quot;\]&quot;&quot;&quot; - Display equations
***/</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//{{{</span>
config.<span style="color: #660066;">extensions</span>.<span style="color: #660066;">MathJax</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
  mathJaxScript <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML&quot;</span><span style="color: #339933;">,</span>
  <span style="color: #006600; font-style: italic;">// uncomment the following line if you want to access MathJax using SSL</span>
  <span style="color: #006600; font-style: italic;">// mathJaxScript : &quot;https://d3eoax9i5htok0.cloudfront.net/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML&quot;,</span>
  displayTiddler_old <span style="color: #339933;">:</span> story.<span style="color: #660066;">displayTiddler</span><span style="color: #339933;">,</span>
  displayTiddler<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>TiddlerName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    config.<span style="color: #660066;">extensions</span>.<span style="color: #660066;">MathJax</span>.<span style="color: #660066;">displayTiddler_old</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    MathJax.<span style="color: #660066;">Hub</span>.<span style="color: #660066;">Queue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;Typeset&quot;</span><span style="color: #339933;">,</span> MathJax.<span style="color: #660066;">Hub</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
jQuery.<span style="color: #660066;">getScript</span><span style="color: #009900;">&#40;</span>config.<span style="color: #660066;">extensions</span>.<span style="color: #660066;">MathJax</span>.<span style="color: #660066;">mathJaxScript</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    MathJax.<span style="color: #660066;">Hub</span>.<span style="color: #660066;">Config</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
      extensions<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;tex2jax.js&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
      <span style="color: #3366CC;">&quot;HTML-CSS&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> scale<span style="color: #339933;">:</span> <span style="color: #CC0000;">100</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    MathJax.<span style="color: #660066;">Hub</span>.<span style="color: #660066;">Startup</span>.<span style="color: #000066;">onload</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    story.<span style="color: #660066;">displayTiddler</span> <span style="color: #339933;">=</span> config.<span style="color: #660066;">extensions</span>.<span style="color: #660066;">MathJax</span>.<span style="color: #660066;">displayTiddler</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
config.<span style="color: #660066;">formatters</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;mathJaxFormula&quot;</span><span style="color: #339933;">,</span>
	match<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\\</span>[|<span style="color: #000099; font-weight: bold;">\\</span>$<span style="color: #000099; font-weight: bold;">\\</span>$|<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\\</span>(&quot;</span><span style="color: #339933;">,</span>
	<span style="color: #006600; font-style: italic;">//lookaheadRegExp: /(?:\\\[|\$\$)((?:.|\n)*?)(?:\\\]|$$)/mg,</span>
	handler<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>w<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span>w.<span style="color: #660066;">matchText</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>[&quot;</span><span style="color: #339933;">:</span> <span style="color: #006600; font-style: italic;">// displayed equations</span>
			<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">lookaheadRegExp</span> <span style="color: #339933;">=</span> <span style="color: #009966; font-style: italic;">/\\\[((?:.|\n)*?)(\\\])/mg</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;$$&quot;</span><span style="color: #339933;">:</span> <span style="color: #006600; font-style: italic;">// inline equations</span>
			<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">lookaheadRegExp</span> <span style="color: #339933;">=</span> <span style="color: #009966; font-style: italic;">/\$\$((?:.|\n)*?)(\$\$)/mg</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>(&quot;</span><span style="color: #339933;">:</span> <span style="color: #006600; font-style: italic;">// inline equations</span>
			<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">lookaheadRegExp</span> <span style="color: #339933;">=</span> <span style="color: #009966; font-style: italic;">/\\\(((?:.|\n)*?)(\\\))/mg</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">:</span>
			<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">lookaheadRegExp</span>.<span style="color: #660066;">lastIndex</span> <span style="color: #339933;">=</span> w.<span style="color: #660066;">matchStart</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> lookaheadMatch <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">lookaheadRegExp</span>.<span style="color: #660066;">exec</span><span style="color: #009900;">&#40;</span>w.<span style="color: #660066;">source</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>lookaheadMatch <span style="color: #339933;">&amp;&amp;</span> lookaheadMatch.<span style="color: #660066;">index</span> <span style="color: #339933;">==</span> w.<span style="color: #660066;">matchStart</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			createTiddlyElement<span style="color: #009900;">&#40;</span>w.<span style="color: #660066;">output</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;span&quot;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span>lookaheadMatch<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			w.<span style="color: #660066;">nextMatch</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">lookaheadRegExp</span>.<span style="color: #660066;">lastIndex</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//}}}</span></pre></div></div>

<p>After saving the tiddler, reload the wiki and the MathJaxPlugin should be active. You can test it by creating a new tiddler with some equations in it:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">This is an inline equation $$P(E)   = {n \choose k} p^k (1-p)^{ n-k}$$ and this is a displayed equation:
\[J_\alpha(x) = \sum_{m=0}^\infty \frac{(-1)^m}{m! \, \Gamma(m + \alpha + 1)}{\left({\frac{x}{2}}\right)}^{2 m + \alpha}\]</pre></div></div>

<p>Which should result in the tiddler that appears in the above image.</p>
<p>Update 20110819: Removed debugging code from the plugin.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2011/06/25/latex-for-tiddlywiki-a-mathjax-plugin/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>A JavaScript DOS Attack</title>
		<link>http://www.guyrutenberg.com/2007/11/23/a-javascript-dos-attack/</link>
		<comments>http://www.guyrutenberg.com/2007/11/23/a-javascript-dos-attack/#comments</comments>
		<pubDate>Thu, 22 Nov 2007 21:30:29 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/2007/11/23/a-javascript-dos-attack/</guid>
		<description><![CDATA[In this post I will present a way of creating a JavaScript based DOS attack that utilizes the bad implementation of tabs in most (if not all) web-browsers. The attack will make the browser unresponsive and force the user to kill its process. This attack is based on the following JavaScript code: &#60;script type=&#34;text/javascript&#34;&#62; while&#40;1&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will present a way of creating a JavaScript based DOS attack that utilizes the bad implementation of tabs in most (if not all) web-browsers. The attack will make the browser unresponsive and force the user to kill its process. This attack is based on the following JavaScript code:<br />
<span id="more-29"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #000066; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;DOS&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>This simple attack, can be much more annoying then it looks, due to the popularity of tab enabled web-browsers such as Firefox and IE7.<br />
In todays web-browsers, if a JavaScript alert pops-up the user must dismiss it before doing anything else. That includes things like switching tabs, closing the open tab, opening menus and etc. If you want to see how annoying this little code can be, just go to <a href="/wp-content/uploads/2007/11/alertloop.html">this page</a> (warning: this will turn your browser unresponsive and will force you to kill it).</p>
<p>As you can see this small script will turn your web-browser completely unresponsive and thus force you to kill it. The first instinct will be restore the crashed session, but it won&#8217;t be possible, as it will reopen the page with the malicious code. So you will have to start your a new session and reopen each tab manually. This small script allowed a malicious user, to force you to crash your own web-browser, while loosing data (unsent email, blog post, or any kind of unsaved form data), without you having any option to prevent it. </p>
<p>When I say you don&#8217;t have any option to prevent it, I say because this code might be in a link a friend send you as a way to annoy you, or in a legitimate web-site which been a victim of JavaScript injection attack. Yes, you can completely protect your self from this by surfing with JavaScript turned off, but many modern website won&#8217;t work, turning this option useless (you would deny yourself any service from many AJAX enabled sites).</p>
<p>To solve this situation we need to take a look at what caused it. Let&#8217;s say the malicious site has been open in its own web-browser instance. In this case you would just kill this instance and continue browsing in the other open windows. But when you open several other sites in the same instance using tabs, you will have to close all of them. This happened because there isn&#8217;t enough separation between tabs. In this case a page loaded in one effects all other opened tabs.</p>
<p>In order to fix and prevent this kind of DOS attack, browser developers need to take a new approach of separation between tabs.</p>
<ul>
<li> In under no circumstances one tab should be able to effect other tabs&#8217; status.</li>
<li> Also tab shouldn&#8217;t be able to prevent the user from closing it or switching to another tab.</li>
<li> JavaScript alerts shouldn&#8217;t be modal. They could be implemented in a way so they prevent any action within the tab until they are dismissed, but in no way they should be able to prevent actions in other tabs.
<li>
</ul>
<p>I&#8217;m no web-browser developer, but this shouldn&#8217;t be too hard to implement in order to fix such old, yet annoying problem, which becomes much more annoying in a tabbed web-browsing environment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2007/11/23/a-javascript-dos-attack/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Tracking MediaWiki External Links Statistics using Google Analytics</title>
		<link>http://www.guyrutenberg.com/2007/07/16/tracking-mediawiki-external-links-statistics-using-google-analytics/</link>
		<comments>http://www.guyrutenberg.com/2007/07/16/tracking-mediawiki-external-links-statistics-using-google-analytics/#comments</comments>
		<pubDate>Mon, 16 Jul 2007 16:06:44 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Google Analytics]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[MediaWiki]]></category>
		<category><![CDATA[Google]]></category>

		<guid isPermaLink="false">http://guy.sikumuna.com/2007/07/16/tracking-mediawiki-external-links-statistics-using-google-analytics/</guid>
		<description><![CDATA[When you track MediaWiki statistics, you usually track only internal page statistics, but tracking external links which leads out of your site is not some thing you can ignore. Unfortunately we probably can&#8217;t put actual tracking code in the pages linked to by our site&#8217;s external links. Fortunately we can track the actual clicks on [...]]]></description>
			<content:encoded><![CDATA[<p>When you track MediaWiki statistics, you usually track only internal page statistics, but tracking external links which leads out of your site is not some thing you can ignore. Unfortunately we probably can&#8217;t put actual tracking code in the pages linked to by our site&#8217;s external links. Fortunately we can track the actual clicks on those links that lead out of the site, and it&#8217;s quite easy to do when tracking statistics with Google Analytics. If you don&#8217;t already use Google Analytics with your MediaWiki site, open a new account in Google Analytics and see my previous post: <a href="/2007/07/13/track-mediawiki-statistics-using-google-analytics/">Track MediaWiki Statistics using Google Analytics</a>.</p>
<p><span id="more-7"></span>Now we have two possible ways to add the tracking code to each external link. The first one is to hack the MediaWiki internal parser for wiki code to generate additional code for each link. While this way will probably work the best it&#8217;s pretty complicated and not straightforward. The other way, which is the one will follow, is to use a small JavaScript snippet which will will iterate through the links in every page and add an &#8220;onClick&#8221; attribute to them with the tracking code.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">var</span> links <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> links.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>links<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">className</span><span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;external text&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                addtrackcode<span style="color: #009900;">&#40;</span>links<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> addtrackcode<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        obj.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'onClick'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;javascript:pageTracker._trackPageview('/outgoing/&quot;</span><span style="color: #339933;">+</span> obj.<span style="color: #660066;">href</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;://&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;');&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>This code snippet should go between you Google Analytics code and the<code> &lt;/body&gt;</code> tag, meaning you can add it to <code>/wiki/skins/monobook.php</code> if you haven&#8217;t changed the default skin for your MediaWiki. After the code is in place it may take up to 48 hours (usually you don&#8217;t have to wait at all) for the external links statistics to show up in the Google Analytics. In the Google Analytics the statistics for clicking on an external link which leads to <a href="http://www.google.com">http://www.google.com</a> will show up as view of the page /outgoing/www.google.com. This script will also track download statistics of files which are linked from the wiki pages (like pdf&#8221;s and such).</p>
<p>While this code does the job, it has a drawbacks. It only tracks the external links created by wiki code (e.g. <code>[http://example.com]</code>) as it uses CSS classes to determine what is external link. However this drawback isn&#8217;t very important and overall the script does a decent job tracking the external links in MediaWiki using Google Analytics.</p>
<p>UPDATE 2010-12-30: updated the post to reflect an Analytics API change.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2007/07/16/tracking-mediawiki-external-links-statistics-using-google-analytics/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.321 seconds -->

