<?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>The Why and The How &#187; Tutorial</title> <atom:link href="http://www.thewhyandthehow.com/tag/tutorial/feed/" rel="self" type="application/rss+xml" /><link>http://www.thewhyandthehow.com</link> <description>Just another WordPress weblog</description> <lastBuildDate>Fri, 09 Jul 2010 02:32:51 +0000</lastBuildDate> <generator>http://wordpress.org/?v=2.8.4</generator> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>Poor programmer&#8217;s website monitor</title><link>http://www.thewhyandthehow.com/poor-programmers-website-monitor/</link> <comments>http://www.thewhyandthehow.com/poor-programmers-website-monitor/#comments</comments> <pubDate>Tue, 26 May 2009 15:30:19 +0000</pubDate> <dc:creator>Blake Schwendiman</dc:creator> <category><![CDATA[Development]]></category> <category><![CDATA[Networking]]></category> <category><![CDATA[Technology]]></category> <category><![CDATA[Tutorial]]></category><guid
isPermaLink="false">http://www.thewhyandthehow.com/?p=720</guid> <description><![CDATA[If you manage your own web site, it&#8217;s critical to know when there are problems, and hopefully you&#8217;ll know before your users do. There are several enterprise-grade server monitors and website monitors available ranging from free to expensive, but if you need something right now that&#8217;s simple and free, you might consider the solution I [...]]]></description> <content:encoded><![CDATA[<p>If you manage your own web site, it&#8217;s critical to know when there are problems, and hopefully you&#8217;ll know before your users do. There are several enterprise-grade server monitors and website monitors available ranging from free to expensive, but if you need something right now that&#8217;s simple and free, you might consider the solution I put together using <a
href="http://www.montastic.com/">Montastic</a>, <a
href="http://pipes.yahoo.com/pipes/">Yahoo! Pipes</a> and my cell phone.</p><p>My solution is not enterprise and it&#8217;s not real time, but it will let me know in a reasonable amount of time (Montastic says it checks every 10 minutes or so, based on load). For me, that&#8217;s good enough right now because I mostly want to avoid overnight and weekend-long outages that may occur when I&#8217;m not checking my computer regularly.</p><p>The first step is to sign up at <a
href="http://www.montastic.com/signup">Montastic</a> and set up a monitor for your web site. There&#8217;s no learning curve there &#8230; just register, type in a URL and Montastic will start monitoring right away. There&#8217;s a <a
href="http://www.montastic.com/video.html">video screen cast</a> available showing how easy it is to use. After setting up the monitors, Montastic provides a basic RSS feed &#8212; that&#8217;s where <a
href="http://pipes.yahoo.com/pipes/">Yahoo! Pipes</a> comes in.</p><p><div
id="attachment_722" class="wp-caption alignright" style="width: 150px"> <a
href="http://www.thewhyandthehow.com/wp-content/uploads/2009/05/yahoo-pipes-pipe.png"><img
src="http://www.thewhyandthehow.com/wp-content/uploads/2009/05/yahoo-pipes-pipe-150x150.png" alt="Yahoo! Pipes Configuration for Montastic" title="yahoo-pipes-pipe" width="150" height="150" class="size-thumbnail wp-image-722" /></a><p
class="wp-caption-text">Yahoo! Pipes Configuration for Montastic</p></div>If you&#8217;re not familiar with Yahoo! Pipes, you should <a
href="http://www.jumpcut.com/fullscreen?id=F4396574585311DC87A2000423CF0184&#038;type=clip">watch this video</a> for a brief introduction. For my monitor application, I built a very simple pipe that takes the output of the Montastic RSS feed, filters out all items that have the text [OK] in the title and then simply return the remaining titles. The entire pipe layout is in the attached screenshot.</p><p>The final step I took was to simply run the pipe, then tell Yahoo! to send me the output of the pipe to my cell phone whenever it changes. Since the pipe updates when there is a new failure item, I won&#8217;t get an SMS message every time Montastic checks the servers, but only when there is a new failure item.</p><p>I haven&#8217;t been running this solution for very long, but so far it looks to be a promising concept for keeping an eye on my servers &#8212; particularly when I&#8217;m going to be away for a while. I&#8217;d love to hear ideas about other ways to use Montastic or suggestions for other free website monitoring tools. What do you use?</p> ]]></content:encoded> <wfw:commentRss>http://www.thewhyandthehow.com/poor-programmers-website-monitor/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>jQuery parent(s)</title><link>http://www.thewhyandthehow.com/jquery-parents/</link> <comments>http://www.thewhyandthehow.com/jquery-parents/#comments</comments> <pubDate>Mon, 27 Apr 2009 17:08:56 +0000</pubDate> <dc:creator>Blake Schwendiman</dc:creator> <category><![CDATA[Javascript]]></category> <category><![CDATA[Tutorial]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[dom]]></category><guid
isPermaLink="false">http://www.thewhyandthehow.com/?p=597</guid> <description><![CDATA[I was recently working on an unordered list in which each item is displayed with a link that does two things: first, the metadata for the item is stored in a database via Ajax; second, the item is removed from the on-screen list so it can&#8217;t be chosen again.
For example, you might display a list [...]]]></description> <content:encoded><![CDATA[<p>I was recently working on an unordered list in which each item is displayed with a link that does two things: first, the metadata for the item is stored in a database via Ajax; second, the item is removed from the on-screen list so it can&#8217;t be chosen again.</p><p>For example, you might display a list of items in a shopping cart with a <strong>delete</strong> link for each. On delete, the item is removed from the current session&#8217;s cart (the Ajax portion) and the item is also removed from the display. In some cases the approach might be to perform the Ajax data update and return the entire list as the result of the call, thus performing the entire two-step process at once. For my recent implementation, I didn&#8217;t want to regenerate the list on the <a
href="http://www.webhostingsearch.com/dedicated-server.php">hosting server</a> each time, so I opted for the two-step process.</p><p>In the process, I learned a new jQuery method and selector option that are so cool that I had to share. The HTML for my list looked something like the following:</p><div
id="wp_codebox_msgheader"><span
class="right"><a
href="javascript:;" onclick="toggle_collapse('p5974');">[<span
id="p5974_symbol">-</span>]</a><sup><a
href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span
style="color: #99cc00">?</span></a></sup></span><span
class="left"><a
href="javascript:;" onclick="javascript:showCodeTxt('p597code4'); return false;">View Code</a> JAVASCRIPT</span><div
class="codebox_clear"></div></div><div
id="wp_codebox"><table
width="100%" ><tr
id="p5974"><td
class="code" id="p597code4"><pre class="javascript"><span style="color: #339933;">&lt;</span>ul<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>img ...<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>dl<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>dt<span style="color: #339933;">&gt;</span>Title<span style="color: #339933;">&lt;/</span>dt<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>dd<span style="color: #339933;">&gt;</span>Some additional meta data<span style="color: #339933;">&lt;/</span>dd<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>dd<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;updateDB(); ???; return false;&quot;</span><span style="color: #339933;">&gt;</span>delete<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;/</span>dd<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>dl<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>img ...<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>dl<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>dt<span style="color: #339933;">&gt;</span>Title<span style="color: #339933;">&lt;/</span>dt<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>dd<span style="color: #339933;">&gt;</span>Some additional meta data<span style="color: #339933;">&lt;/</span>dd<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>dd<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;updateDB(); ???; return false;&quot;</span><span style="color: #339933;">&gt;</span>delete<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;/</span>dd<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>dl<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;!--</span> more list items <span style="color: #000066; font-weight: bold;">in</span> the same format <span style="color: #339933;">--&gt;</span>
<span style="color: #339933;">&lt;/</span>ul<span style="color: #339933;">&gt;</span></pre></td></tr></table></div><p>The containers inside the list items provide all of the layout (via CSS), so they&#8217;re necessary to make everything look right. The click handler for the <strong>delete</strong> link calls <em>updateDB</em> which is the Ajax function that performs the actual server update. In place of the <em>???</em> I added the following code which removes the entire list item from the view:</p><div
id="wp_codebox_msgheader"><span
class="right"><a
href="javascript:;" onclick="toggle_collapse('p5975');">[<span
id="p5975_symbol">-</span>]</a><sup><a
href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span
style="color: #99cc00">?</span></a></sup></span><span
class="left"><a
href="javascript:;" onclick="javascript:showCodeTxt('p597code5'); return false;">View Code</a> JAVASCRIPT</span><div
class="codebox_clear"></div></div><div
id="wp_codebox"><table
width="100%" ><tr
id="p5975"><td
class="code" id="p597code5"><pre class="javascript">  jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">parents</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'li:eq(0)'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>The <strong><a
href="http://docs.jquery.com/API/1.2/Traversing/parents">parents()</a></strong> method returns all of the parents of an element that match the selector. Simply calling <strong>parents(&#8217;li&#8217;)</strong> for the anchor tag in the example above may have worked, but if the list happened to be embedded within another list, it&#8217;s possible that I would have inadvertently removed a series of parent items instead of just the immediate parent that I wanted. To ensure that I only acted on the immediate parent, I included the <a
href="http://docs.jquery.com/Selectors">basic filter</a>, <strong><a
href="http://docs.jquery.com/Selectors/eq#index">eq(0)</a></strong> to the selector to ensure that the subsequent calls (<em><a
href="http://docs.jquery.com/Effects/fadeOut#speedcallback">fadeOut</a></em>) only act on the first item found.</p><p>The final code looks like this:</p><div
id="wp_codebox_msgheader"><span
class="right"><a
href="javascript:;" onclick="toggle_collapse('p5976');">[<span
id="p5976_symbol">-</span>]</a><sup><a
href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span
style="color: #99cc00">?</span></a></sup></span><span
class="left"><a
href="javascript:;" onclick="javascript:showCodeTxt('p597code6'); return false;">View Code</a> JAVASCRIPT</span><div
class="codebox_clear"></div></div><div
id="wp_codebox"><table
width="100%" ><tr
id="p5976"><td
class="code" id="p597code6"><pre class="javascript"><span style="color: #339933;">&lt;</span>ul<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>img ...<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>dl<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>dt<span style="color: #339933;">&gt;</span>Title<span style="color: #339933;">&lt;/</span>dt<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>dd<span style="color: #339933;">&gt;</span>Some additional meta data<span style="color: #339933;">&lt;/</span>dd<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>dd<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;updateDB(); jQuery(this).parents('li:eq(0)').fadeOut(); return false;&quot;</span><span style="color: #339933;">&gt;</span>delete<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;/</span>dd<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>dl<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;!--</span> more list items <span style="color: #000066; font-weight: bold;">in</span> the same format <span style="color: #339933;">--&gt;</span>
<span style="color: #339933;">&lt;/</span>ul<span style="color: #339933;">&gt;</span></pre></td></tr></table></div><p>jQuery again solves the cumbersome process of traversing the DOM searching for parent elements manually by providing rich electors, methods and filters.</p> ]]></content:encoded> <wfw:commentRss>http://www.thewhyandthehow.com/jquery-parents/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>jQuery solution: selected radio button value</title><link>http://www.thewhyandthehow.com/jquery-solution-selected-radio-button-value/</link> <comments>http://www.thewhyandthehow.com/jquery-solution-selected-radio-button-value/#comments</comments> <pubDate>Mon, 20 Apr 2009 21:14:56 +0000</pubDate> <dc:creator>Blake Schwendiman</dc:creator> <category><![CDATA[Technology]]></category> <category><![CDATA[Tutorial]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[form]]></category> <category><![CDATA[radio button]]></category><guid
isPermaLink="false">http://www.thewhyandthehow.com/?p=552</guid> <description><![CDATA[The radio button element in an HTML form can be awkward to manage in Javascript. For example, assume the following form:[-]?View Code HTML&#60;form id=&#34;radio_form&#34;&#62;
&#60;fieldset&#62;
&#60;label&#62;&#60;input type=&#34;radio&#34; name=&#34;color&#34; value=&#34;red&#34; checked=&#34;checked&#34; /&#62;Red&#60;/label&#62;&#60;br /&#62;
&#60;label&#62;&#60;input type=&#34;radio&#34; name=&#34;color&#34; value=&#34;yellow&#34; /&#62;Yellow&#60;/label&#62;&#60;br /&#62;
&#60;label&#62;&#60;input type=&#34;radio&#34; name=&#34;color&#34; [...]]]></description> <content:encoded><![CDATA[<script type="text/javascript" src="/wp-content/themes/thesis/custom/js/radio_form.js"></script><p>The radio button element in an HTML form can be awkward to manage in Javascript. For example, assume the following form:</p><div
id="wp_codebox_msgheader"><span
class="right"><a
href="javascript:;" onclick="toggle_collapse('p5529');">[<span
id="p5529_symbol">-</span>]</a><sup><a
href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span
style="color: #99cc00">?</span></a></sup></span><span
class="left"><a
href="javascript:;" onclick="javascript:showCodeTxt('p552code9'); return false;">View Code</a> HTML</span><div
class="codebox_clear"></div></div><div
id="wp_codebox"><table
width="100%" ><tr
id="p5529"><td
class="code" id="p552code9"><pre>&lt;form id=&quot;radio_form&quot;&gt;
  &lt;fieldset&gt;
    &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;color&quot; value=&quot;red&quot; checked=&quot;checked&quot; /&gt;Red&lt;/label&gt;&lt;br /&gt;
    &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;color&quot; value=&quot;yellow&quot; /&gt;Yellow&lt;/label&gt;&lt;br /&gt;    
    &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;color&quot; value=&quot;blue&quot; /&gt;Blue&lt;/label&gt;&lt;br /&gt;
    &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;color&quot; value=&quot;purple&quot; /&gt;Purple&lt;/label&gt;&lt;br /&gt;
  &lt;/fieldset&gt;
&lt;/form&gt;</pre></td></tr></table></div><p>Using Javascript to determine the currently selected value of the <em>color</em> radio buttons typically involves looping through all of the input elements to find the <em>checked</em> element. <a
href="http://www.thewhyandthehow.com/setting-focus-on-first-form-element-with-jquery/">As I&#8217;ve said before, if you&#8217;re looping through the DOM in jQuery, you&#8217;re probably doing it wrong</a>.</p><p>The jQuery solution for finding the selected radio button&#8217;s value looks like this:</p><div
id="wp_codebox_msgheader"><span
class="right"><a
href="javascript:;" onclick="toggle_collapse('p55210');">[<span
id="p55210_symbol">-</span>]</a><sup><a
href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span
style="color: #99cc00">?</span></a></sup></span><span
class="left"><a
href="javascript:;" onclick="javascript:showCodeTxt('p552code10'); return false;">View Code</a> JAVASCRIPT</span><div
class="codebox_clear"></div></div><div
id="wp_codebox"><table
width="100%" ><tr
id="p55210"><td
class="code" id="p552code10"><pre class="javascript">  <span style="color: #003366; font-weight: bold;">var</span> the_value<span style="color: #339933;">;</span>
  the_value <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#radio_form input:radio:checked'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>the_value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>Test it for yourself (if you&#8217;re reading this in a news reader such as Google Reader, you&#8217;ll have to go to the <a
href="http://www.thewhyandthehow.com/jquery-solution-selected-radio-button-value/">original post</a> to test the sample):</p><form
id="radio_form" class="example"><fieldset><label><br
/> <input
type="radio" name="color" value="red" checked="checked" />Red</label><label><br
/> <input
type="radio" name="color" value="yellow" />Yellow</label><label><br
/> <input
type="radio" name="color" value="blue" />Blue</label><label><br
/> <input
type="radio" name="color" value="purple" />Purple</label><button
type="button" onclick="radio_form();">Show value</button></fieldset></form> ]]></content:encoded> <wfw:commentRss>http://www.thewhyandthehow.com/jquery-solution-selected-radio-button-value/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Tracking events with Google Analytics</title><link>http://www.thewhyandthehow.com/tracking-events-with-google-analytics/</link> <comments>http://www.thewhyandthehow.com/tracking-events-with-google-analytics/#comments</comments> <pubDate>Tue, 24 Mar 2009 12:10:50 +0000</pubDate> <dc:creator>Blake Schwendiman</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[Tutorial]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[analytics]]></category> <category><![CDATA[how-to]]></category> <category><![CDATA[Javascript]]></category> <category><![CDATA[trackevents]]></category><guid
isPermaLink="false">http://www.thewhyandthehow.com/?p=346</guid> <description><![CDATA[If you have any type of web site at all, you&#8217;ve heard about Google Analytics by now. It&#8217;s the Google solution to analyzing your web traffic. One of the more recent features in Analytics is the ability to track events that occur on your page that aren&#8217;t traditional page views. For example, if you have [...]]]></description> <content:encoded><![CDATA[<p>If you have any type of web site at all, you&#8217;ve heard about <a
href="http://www.google.com/analytics/">Google Analytics</a> by now. It&#8217;s the Google solution to analyzing your web traffic. One of the more recent features in Analytics is the ability to <a
href="http://code.google.com/apis/analytics/docs/eventTrackerGuide.html">track events</a> that occur on your page that aren&#8217;t traditional page views. For example, if you have a Flash animation on your page, you might want to track interactions with the animation using Google Analytics. I&#8217;m using event tracking to track the downloads of my <a
href="http://www.thewhyandthehow.com/building-custom-php-extensions/">eBook</a>.</p><p>Setting up event tracking with the <a
href="http://diythemes.com/thesis/?a_aid=pointe&#038;a_bid=47c5a620">Thesis theme</a> and jQuery is a cinch. Here&#8217;s how it breaks down:</p><ol><li>Make sure jQuery is loaded</li><li>Update appropriate &lt;a&gt; tags to call trackEvent()</li></ol><p>Since the <a
href="http://diythemes.com/thesis/?a_aid=pointe&#038;a_bid=47c5a620">Thesis theme</a> provides its own hooks, the code for both of these changes is implemented with two hooks and a few lines of code.</p><div
id="wp_codebox_msgheader"><span
class="right"><a
href="javascript:;" onclick="toggle_collapse('p34613');">[<span
id="p34613_symbol">-</span>]</a><sup><a
href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span
style="color: #99cc00">?</span></a></sup></span><span
class="left"><a
href="javascript:;" onclick="javascript:showCodeTxt('p346code13'); return false;">View Code</a> PHP</span><div
class="codebox_clear"></div></div><div
id="wp_codebox"><table
width="100%" ><tr
id="p34613"><td
class="code" id="p346code13"><pre class="php">add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_head'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'add_jquery'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'thesis_hook_footer'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'custom_footer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> add_jquery<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> custom_footer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
  jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>ready<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a.track-download'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><a href="http://www.php.net/each"><span style="color: #990000;">each</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      jQuery<span style="color: #009900;">&#40;</span>this<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>bind<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'click'</span><span style="color: #339933;">,</span> <span style="color: #000000; 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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>pageTracker<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          pageTracker<span style="color: #339933;">.</span>_trackEvent<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Download'</span><span style="color: #339933;">,</span> jQuery<span style="color: #009900;">&#40;</span>this<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>attr<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rel'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> jQuery<span style="color: #009900;">&#40;</span>this<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>attr<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#41;</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>
    <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>
<span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div><p>As you can see, I load jQuery from the <a
href="http://code.google.com/apis/ajaxlibs/documentation/index.html#jquery">Google API content delivery network</a>. I like this method because it uses Google&#8217;s servers for delivery (not my bandwidth) and it increases the chance that the browser has already cached the jQuery code.</p><p>The actual jQuery code is a very simple method that locates all <strong>anchor</strong> tags with the class <strong>track-download</strong> and binds a new click method. The method itself simply calls the analytics method <strong>_trackEvent</strong> with the parameters:</p><ul><li>&#8216;Download&#8217; (the category)</li><li>the <em>rel</em> attribute of the anchor tag (action)</li><li>the <em>title</em> attribute of the anchor (optional_label)</li></ul><p>In the page that contains the download links, the code looks like this:</p><div
id="wp_codebox_msgheader"><span
class="right"><a
href="javascript:;" onclick="toggle_collapse('p34614');">[<span
id="p34614_symbol">-</span>]</a><sup><a
href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span
style="color: #99cc00">?</span></a></sup></span><span
class="left"><a
href="javascript:;" onclick="javascript:showCodeTxt('p346code14'); return false;">View Code</a> HTML</span><div
class="codebox_clear"></div></div><div
id="wp_codebox"><table
width="100%" ><tr
id="p34614"><td
class="code" id="p346code14"><pre>&lt;a class=&quot;track-download&quot; href=&quot;http://www.thewhyandthehow.com/wp-content/uploads/2009/02/building-custom-php-extensions.pdf&quot; alt=&quot;Download Building Custom PHP Extensions PDF&quot; rel=&quot;PDF&quot; title=&quot;Building Custom PHP Extensions&quot;&gt;PDF Version&lt;/a&gt;&lt;br /&gt;
&lt;a class=&quot;track-download&quot; href='http://www.thewhyandthehow.com/wp-content/uploads/2009/02/building-custom-php-extensions.doc' alt=&quot;Download Building Custom PHP Extensions Word Doc&quot; rel=&quot;DOC&quot; title=&quot;Building Custom PHP Extensions&quot;&gt;MS Word DOC version&lt;/a&gt;&lt;br /&gt;
&lt;a class=&quot;track-download&quot; href='http://www.thewhyandthehow.com/wp-content/uploads/2009/02/building-custom-php-extensions.odt' alt=&quot;Download Building Custom PHP Extensions Open Office odt&quot; rel=&quot;ODT&quot; title=&quot;Building Custom PHP Extensions&quot;&gt;Open Office ODT version&lt;/a&gt;&lt;/p&gt;</pre></td></tr></table></div><p>As you can see, a very simple change to the &lt;a&gt; tag structure on my pages now provides me with a richer depth of analytic information. Adding new downloadable items with analytics is as easy as adding a <em>class</em>, a <em>rel</em> and a <em>title</em> attribute to the new anchor tag.</p><p><a
href="http://www.thewhyandthehow.com/wp-content/uploads/2009/03/analytics-event-tracking.png"><img
src="http://www.thewhyandthehow.com/wp-content/uploads/2009/03/analytics-event-tracking-300x179.png" alt="analytics-event-tracking" title="analytics-event-tracking" width="300" height="179" class="alignleft size-medium wp-image-350" /></a></p><p>The screen grab here shows the event tracking overview page in Google Analytics. You can see that Google Analytics breaks down the event tracking by event by category and action (for me, that&#8217;s &#8216;Download&#8217; and file type). There are sub-reports available for each action as you would expect from Google Analytics.</p><p>Notwithstanding the pathetic numbers in my example (I obviously need some marketing help), you can see that event tracking can be a valuable addition to general page view tracking for a web site if you have custom actions that can be triggered using JavaScript.</p> ]]></content:encoded> <wfw:commentRss>http://www.thewhyandthehow.com/tracking-events-with-google-analytics/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> </channel> </rss><!--
This site's performance optimized by W3 Total Cache:

W3 Total Cache improves the user experience of your blog by caching
frequent operations, reducing the weight of various files and providing
transparent content delivery network integration.

Learn more about our WordPress Plugins: http://www.w3-edge.com/wordpress-plugins/

Minified using memcached
Page Caching using memcached
Database Caching 8/15 queries in 0.008 seconds using memcached

Served from: a2.c0.354a.static.theplanet.com @ 2010-09-10 03:17:09 -->