<?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>Travis Beck &#187; mootools</title>
	<atom:link href="http://travisjbeck.com/blog/tag/mootools/feed/" rel="self" type="application/rss+xml" />
	<link>http://travisjbeck.com/blog</link>
	<description>The Modern Web</description>
	<lastBuildDate>Mon, 14 Jun 2010 05:36:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>MooTools HideThisMessage plugin</title>
		<link>http://travisjbeck.com/blog/javascript/mootools-hidethismessage-plugin/</link>
		<comments>http://travisjbeck.com/blog/javascript/mootools-hidethismessage-plugin/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 05:07:00 +0000</pubDate>
		<dc:creator>Travis</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[mootools]]></category>

		<guid isPermaLink="false">http://travisjbeck.com/blog/?p=74</guid>
		<description><![CDATA[I&#8217;ve written another MooTools plugin (class) for facilitating the hiding of various help messages you may have scattered throughout your app. Download the script and demoView the demoDownload the MooTools framework What does it do? The basic premise is that you have a help message on one or more of your site&#8217;s pages which are [...]]]></description>
			<content:encoded><![CDATA[<p>
I&#8217;ve written another MooTools plugin (class) for facilitating the hiding of various help messages you may have scattered throughout your app.
</p>
<p><span id="more-74"></span></p>
<p>
<a onclick="javascript: pageTracker._trackPageview('/files/hidethismessage.zip'); " href="/files/HideThisMessage.zip">Download the script and demo</a><br/><a href="/demos/hidethismessage/">View the demo</a><br/><a href="http://mootools.net/download">Download the MooTools framework</a></p>
<p><h2>What does it do?</h2>
<p>The basic premise is that you have a help message on one or more of your site&#8217;s pages which are incredibly useful the first few times the user visits that section.  However, once the user understands how that page works, that once useful help message is now just in the way.   So to solve this problem you might put a &#8220;Close this message&#8221; or &#8220;Hide this message&#8221; link in there so that your users can get it off their screen since it&#8217;s no longer needed. That&#8217;s where HideThisMessage comes in.
</p>
<p>
HideThisMessage finds all the elements with the className you specify, hides them (with or without a snazzy animation) when the user clicks on the link within that element with the className you specify, and remembers via cookies which elements should be shown and which should be hidden/removed.  Each element needs its own unique id and the user must have cookies enabled.
</p>
<h2>Linking the required JavaScript files</h2>
<p>
You need to link the appropriate JavaScript files in the head of your document. HideThisMessage requires <a href="http://mootools.net/download">MooTools 1.2</a> or MooTools 1.11.  I&#8217;ve created classes for both versions. It also requires the <a href="http://mootools.net/docs/Plugins/Hash.Cookie">Hash.Cookie</a> Plugin for MooTools which i&#8217;ve included  in my download package for your convenience. Place the following lines before the closing<code> head </code> tag in the top of your document.
</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/path_to/mootools.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/path_to/hidethismessage.min.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></div></div>

<p>
Make sure you call the hidethismessage script AFTER mootols or it won&#8217;t work
</p>
<h2>Initializing HideThisMessage</h2>
<p>
Now you need to call the HideThisMessageclass passing to it the variables needed to get the plugin working. HideThisMessage takes 2 required and 1 optional arguments.
</p>
<ul class="argumentsList">
<li>
     <code>elementClass:</code> REQUIRED (String)(default: &#8216;hideWindow&#8217;) &#8211; The ClassName of the element that is to be hid.
   </li>
<li>
   <code>hideBtnClass:</code> REQUIRED (String)(default: &#8216;hideWindowBtn&#8217;)   &#8211; The ClassName of the link contained within elementClass that, when clicked, hides the window.
   </li>
<li>
<code>animate:</code> OPTIONAL (Boolean)(default: true)  &#8211; Whether or not the window animates closed when the hideBtnClass link is clicked.
</li>
</ul>
<p>
Now lets create a new instance of our HideThisMessage class.
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">         window.<span style="color: #660066;">addEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'domready'</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>
            <span style="color: #003366; font-weight: bold;">var</span> myMessageHider <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> HideThisMessage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
               elementClass<span style="color: #339933;">:</span> <span style="color: #3366CC;">'hideWindow'</span><span style="color: #339933;">,</span>   
               hideBtnClass<span style="color: #339933;">:</span> <span style="color: #3366CC;">'hideWindowBtn'</span><span style="color: #339933;">,</span>
               animate<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span>                 
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Public Methods</h2>
<p>
HideThisMessage only has 1 public method
</p>
<ul class="argumentsList">
<li><code>reset()</code> Resets the hidden status of all hidden windows.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://travisjbeck.com/blog/javascript/mootools-hidethismessage-plugin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The ImageSlider MooTools class</title>
		<link>http://travisjbeck.com/blog/javascript/the-imageslider-mootools-class/</link>
		<comments>http://travisjbeck.com/blog/javascript/the-imageslider-mootools-class/#comments</comments>
		<pubDate>Mon, 06 Oct 2008 15:30:07 +0000</pubDate>
		<dc:creator>Travis</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[mootools]]></category>

		<guid isPermaLink="false">http://travisjbeck.com/blog/?p=53</guid>
		<description><![CDATA[I&#8217;ve written a proper MooTools class for the slider I made for the portfolio page that slides the thumbnails back and forth. Here&#8217;s how it works. Download the script and demo View the demo Download the MooTools framework Setting up your Markup In order for the script to work you need to setup your document [...]]]></description>
			<content:encoded><![CDATA[<p>
I&#8217;ve written a proper MooTools class for the slider I made for the <a href="http://travisjbeck.com/portfolio.html">portfolio </a>page that slides the thumbnails back and forth.  Here&#8217;s how it works.
</p>
<p><span id="more-53"></span></p>
<p>
<a href="/files/ImageSlider.zip" onclick="javascript: pageTracker._trackPageview('/files/ImageSlider.zip'); ">Download the script and demo</a><br />
<a href="/demos/imageslider/">View the demo</a><br />
<a href="http://mootools.net/download">Download the MooTools framework</a></p>
<p><h2>Setting up your Markup</h2>
<p>
In order for the script to work you need to setup your document to mask out the elements you&#8217;re sliding.  here&#8217;s a diagram of what I&#8217;m talking about:
</p>
<p>
<img src="http://travisjbeck.com/blog/wp-content/uploads/2008/10/imageslider-markup-setup.gif" alt="" title="imageslider-markup-setup" width="500" height="289" class="aligncenter size-full wp-image-55" />
</p>
<p>Example markup:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;maskDiv&quot;</span>&gt;</span>
         <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sliderContainer&quot;</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sliderElement&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Element 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sliderElement&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Element 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sliderElement&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Element 3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sliderElement&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Element 4<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sliderElement&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Element 5<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sliderElement&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Element 6<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sliderElement&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Element 7<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
         <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
         <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;leftBtn&quot;</span>&gt;</span>move left<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
         <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rightBtn&quot;</span>&gt;</span>move right<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>
Example CSS:
</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#maskDiv</span><span style="color: #00AA00;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">300px</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#sliderContainer</span><span style="color: #00AA00;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">50px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
.sliderElement<span style="color: #00AA00;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">70px</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">15px</span> <span style="color: #933;">15px</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">70px</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<h2>Linking the required JavaScript files</h2>
<p>
Now that your document is setup correctly to use the ImageSlider, you need to link the appropriate javascript files in the head of your document.  ImageSlider requires <a href="http://mootools.net/download">MooTools 1.2</a>. Place the following lines before the closing <code>head</code> tag in the top of your document.
</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/path_to/mootools.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/path_to/imageslider.min.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></div></div>

<p>
Make sure that you call the ImageSlider script AFTER Mootools or it won&#8217;t work.
</p>
<h2>Initializing the ImageSlider</h2>
<p>
Now you need to call the ImageSlider class passing to it the variables needed to get the ImageSlider working. ImageSlider takes 5 required and 3 optional arguments.
</p>
<ul class="argumentsList">
<li><code>objToSlide:</code> REQUIRED (String)   &#8211; The id of the holder element that will be sliding.</li>
<li><code>sliderElements:</code> REQUIRED (String)   &#8211; The type of elements contained within the slider can be any html element(div, p, a, span).</li>
<li><code>numOfElementsToSlide:</code> OPTIONAL (Number)   &#8211; Number of elements to slide.</li>
<li><code>numOfElementsShown:</code> REQUIRED (Number)   &#8211; Number of elements visible or unmasked</li>
<li><code>leftBtn:</code> REQUIRED (String)   &#8211; The ID of the element that when clicked will slide your imageslider left.</li>
<li><code>rightBtn:</code> REQUIRED (String)   &#8211; The ID of the element that when clicked will slide your imageslider right.</li>
<li><code>easing:</code> OPTIONAL (Function) &#8211; The type of easing to use on transition (<a href="http://mootools.net/docs/Fx/Fx.Transitions#Fx-Transitions">more info on easing</a>).</li>
<li><code>onSlideComplete:</code> OPTIONAL (Function) &#8211; Callback Function to fire once sliding is completed. returns index.</li>
</ul>
<p>
Now lets create a new ImageSlider using our markup example above:
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">window.<span style="color: #660066;">addEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'domready'</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>
  <span style="color: #003366; font-weight: bold;">var</span> mySlider <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> ImageSlider<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
      objToSlide<span style="color: #339933;">:</span> <span style="color: #3366CC;">'sliderContainer'</span><span style="color: #339933;">,</span>
      sliderElements<span style="color: #339933;">:</span> <span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span>
      numOfElementsToSlide<span style="color: #339933;">:</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> 
      numOfElementsShown<span style="color: #339933;">:</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">,</span> 
      leftBtn<span style="color: #339933;">:</span> <span style="color: #3366CC;">'leftBtn'</span><span style="color: #339933;">,</span>
      rightBtn<span style="color: #339933;">:</span> <span style="color: #3366CC;">'rightBtn'</span><span style="color: #339933;">,</span>
      onSlideComplete<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>index<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         <span style="color: #006600; font-style: italic;">//callback function stuff here</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: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>
You&#8217;ll notice that I&#8217;m using the <code>domready</code> Event to instantiate our new ImageSlider.  This is a custom MooTools Event which will execute when the DOM has loaded. To ensure that DOM elements exist when the code attempting to access them is executed, they should be placed within the &#8216;<a href="http://mootools.net/docs/Utilities/DomReady">domready</a>&#8216; event.
</p>
<p>
<a href="/demos/imageslider/">View the demo</a> of our newly created ImageSlider.
</p>
<h2>Public Methods</h2>
<p>
ImageSlider only has 1 public method.
</p>
<ul class="argumentsList">
<li><code>slideTo(position:Number)</code> This will slide to the position you specify where position is the number of the element you want to show up within the masked area.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://travisjbeck.com/blog/javascript/the-imageslider-mootools-class/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Tracking Ajax calls in Google Analytics</title>
		<link>http://travisjbeck.com/blog/javascript/tracking-ajax-calls-in-google-analytics/</link>
		<comments>http://travisjbeck.com/blog/javascript/tracking-ajax-calls-in-google-analytics/#comments</comments>
		<pubDate>Mon, 29 Sep 2008 01:40:58 +0000</pubDate>
		<dc:creator>Travis</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[analytics]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[mootools]]></category>

		<guid isPermaLink="false">http://travisjbeck.com/blog/?p=45</guid>
		<description><![CDATA[I&#8217;m addicted to analytics. I check them constantly. Like most people, I use Google Analytics. Google Analytics is a great, free, incredibly powerful, analytics platform. It offers many advanced tracking options and data, most of which, few people will ever use. As great as Google Analytics is, it does not track ajax request out-of-the-box. But [...]]]></description>
			<content:encoded><![CDATA[<p>
I&#8217;m addicted to analytics.  I check them constantly. Like most people, I use <a href="http://www.google.com/analytics/">Google Analytics</a>.  Google Analytics is a great, free, incredibly powerful, analytics platform.  It offers many advanced tracking options and data, most of which, few people will ever use.
</p>
<p><span id="more-45"></span></p>
<p>
As great as Google Analytics is, it does not track ajax request out-of-the-box.  But don&#8217;t fear, tracking Ajax calls with Google Analytics is easier than you think.  I&#8217;m not going to go over how to set up Google&#8217;s tracking code on your site, I&#8217;m going to assume you&#8217;ve already got analytics up and running.
</p>
<h2>Method 1<br />
<h2>
<h3>The fast and dirty way</h3>
<p>
First off, I&#8217;m going to assume you&#8217;re using some sort of JavaScript framework. I prefer <a href="http://mootools.net">MooTools</a>, but this method should work with any framework. Every framework&#8217;s Ajax request methods have a built in &#8220;successful request&#8221; callback.  This method is usually and appropriately called <code>onSuccess</code>. This callback method means that your request has completed and returned a successful response. You&#8217;re probably already familiar with Google Analytic&#8217;s <code>pageTracker._trackPageview();</code> code, since you have it in every page you are already tracking. That method also takes an optional string argument, usually the name of the page you are tracking.  By default that argument is the current page that the code is on.  We&#8217;re going to use that optional argument in our <code>onSuccess</code> callback to track our request. Here&#8217;s a simplified version of the Ajax request code from the contact form on this site using MooTools 1.2.
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'send'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
   onSuccess<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #006600; font-style: italic;">//a successful request</span>
   <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
   onFailure<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #006600; font-style: italic;">//a failed request</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: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>
For this particular example we want to track a successful contact form submittal using a unique string that will show up in our analytics page. I decided to use &#8220;/contactFormSubmitted&#8221;.  This is the name of the &#8220;page&#8221; that will show up in Google Analytics. You can use the actual page name that the request is submitted to or any identifier you want. So lets add the code to our success callback
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'send'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
   onSuccess<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #006600; font-style: italic;">//a successful request</span>
      pageTracker._trackPageview<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/contactFormSubmitted'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
   onFailure<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #006600; font-style: italic;">//a failed request</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: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>
Now anytime someone successfully fills out and submits the contact form on my site, i&#8217;ll see it show up in the content section on Google Analytics, as seen here.<br />
<img src="http://travisjbeck.com/blog/wp-content/uploads/2008/09/analytics-ajax.gif" alt="" title="analytics-ajax" class="aligncenter size-full wp-image-47" /><br />
I know, the numbers are overwhelming, but the point is, my Ajax request is being correctly tracked.
</p>
<h2>Method 2</h2>
<h3>Extending the Request Class to automatically track the requested url</h3>
<p>
So another way to do this would be to extend the Request class itself and have it track the URL automatically after a successful request. Once again, this is specific to MooTools 1.2. What i want to do is overwrite the default <code>Request.onSuccess</code> method with our new functionality while maintaining the original functionality. This method eliminates the need to add the tracking code to every single success callback in you code base.  Very useful for retrofitting large sites with lots of Ajax calls or just getting free functionality.
</p>
<p>
To implement, simply add the following lines somewhere in your JavaScript file.  Just make sure the file you&#8217;re adding it to is embedded after MooTools.
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Request.<span style="color: #660066;">implement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
   onSuccess<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>
      <span style="color: #006600; font-style: italic;">//google pageview code</span>
      pageTracker._trackPageview<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #006600; font-style: italic;">//default onSuccess code</span>
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">fireEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'complete'</span><span style="color: #339933;">,</span> arguments<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fireEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'success'</span><span style="color: #339933;">,</span> arguments<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">callChain</span><span style="color: #009900;">&#40;</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: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>
This overwrites the default <code>onSuccess</code> method for the Request Class, keeping the original functionality in tact but adding the tracking code for every Ajax call in your application. The URL of the request will show up on your analytics page.</p>
]]></content:encoded>
			<wfw:commentRss>http://travisjbeck.com/blog/javascript/tracking-ajax-calls-in-google-analytics/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
