<?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>Silverlight &#124; WPF &#124; Microsoft.Net &#187; fbjs</title>
	<atom:link href="http://joel.neubeck.net/tag/fbjs/feed/" rel="self" type="application/rss+xml" />
	<link>http://joel.neubeck.net</link>
	<description>Simplifing structure without changing results</description>
	<lastBuildDate>Wed, 26 May 2010 18:43:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>FBJS and Ajax to acheive Facebook profile link tracking</title>
		<link>http://joel.neubeck.net/2007/11/fbjs-ajax-facebook/</link>
		<comments>http://joel.neubeck.net/2007/11/fbjs-ajax-facebook/#comments</comments>
		<pubDate>Sat, 24 Nov 2007 05:16:26 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Microsoft.Net 2.0]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[fbjs]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/2007/11/fbjs-ajax-facebook/</guid>
		<description><![CDATA[In interactive application development we love our ability to track and analyze the behavior of our users. Through tools like Google analytics and Urchin, web sites can monitor and analyze where their users are going, and more importantly how those users are getting there. As our company delves deeper into creating applications for the Facebook [...]]]></description>
			<content:encoded><![CDATA[<p>In interactive application development we love our ability to track and analyze the behavior of our users.   Through tools like Google analytics and Urchin, web sites can monitor and analyze where their users are going, and more importantly how those users are getting there.  </p>
<p>As our company delves deeper into creating applications for the Facebook platform, we have realized that analysis of users behavior is extremely important.  It is no secret that very few companies have mastered how to create a success Facebook application.    Those that have seen moderate success do one thing consistently, they all  leverage the social graph, but outside of that there is no clear blue print to success.   Using techniques such as user tracking we can begin to tune the way a Facebook applications evolves as a way to change its presentation based on the behaviors of its users.  </p>
<p>Integrating analytics into a  canvas view it is pretty simple, slap in some Google analytics and you can begin to monitor and tune user traffic.  The profile view is much more challenging.  In the profile view an applications FBML and images are cached and delivered from a Facebook server.  Using traditional Google analytics in the profile is not possible.   I hope someday Facebook will show us how many users view and interact with a users profile, but until then we need some way to track a users interaction with our application.  Back in October Facebook gave developers the ability to do some restricted Javascript and Ajax.  With these two features, we can begin to track what links a user click and how those clicks relate to a users interaction with the canvas view.  The following snip of FBJS will post a small JSON array to a external location, which in turn will asynchronously store that data for later analysis.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;&lt;!--</span>
    <span style="color: #003366; font-weight: bold;">var</span> uid <span style="color: #339933;">=</span> <span style="color: #3366CC;">'111111'</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">function</span> track<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> pid<span style="color: #339933;">,</span> method<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// ajax query</span>
        <span style="color: #003366; font-weight: bold;">var</span> ajax <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ajax<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        ajax.<span style="color: #660066;">responseType</span> <span style="color: #339933;">=</span> Ajax.<span style="color: #660066;">RAW</span><span style="color: #339933;">;</span>
        ajax.<span style="color: #660066;">requireLogin</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> queryParams <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;pid&quot;</span> <span style="color: #339933;">:</span> pid<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;method&quot;</span> <span style="color: #339933;">:</span> method<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;uid&quot;</span><span style="color: #339933;">:</span> uid<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;source&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;profile&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        ajax.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;http://url.com/tracker.ashx&quot;</span><span style="color: #339933;">,</span> queryParams<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #006600; font-style: italic;">//--&gt;&lt;/script&gt;</span></pre></td></tr></table></div>

<p>To enable this tracking we must add the following callback attached to that elements onclick event.  In our example we are attaching tracking to a link which provides an external vendors affiliate link for a series of consumer products.  </p>
<p>One caveat, this approach only works correctly in Firefox if your &lt;a&gt; target is set to blank.  If you  need to use the same window, the only approach I have found  is to use the anchor that is passed into the track method combined with the ajax.ondone callback to set the document.setLocation to the anchors href.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">ajax.<span style="color: #660066;">ondone</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> href <span style="color: #339933;">=</span> a.<span style="color: #660066;">getHref</span><span style="color: #009900;">&#40;</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>href.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      document.<span style="color: #660066;">setLocation</span><span style="color: #009900;">&#40;</span>a.<span style="color: #660066;">getHref</span><span style="color: #009900;">&#40;</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></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://www.amazon.com&quot;</span> onclick<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;track(this,12345,'buy');&quot;</span> <span style="color: #003366; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;buy&quot;</span> target<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;_blank&quot;</span><span style="color: #339933;">&gt;</span>BUY<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>On the back end we have a page that is waiting for this specific Ajax post, and will return a 1 for success and a 0 for failure.  It is extremely important to keep this tracking as efficient as possible.  Facebook Ajax has a <10 second maximum timeout on all requests.  In our design, the storing of the data is done using a asynchronous thread that queues up the incoming requests in hoped to avoid Facebook having to wait for us to store the data correctly.  </p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2007/11/fbjs-ajax-facebook/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
