<?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>dudu&#039;s blog &#187; Javascript</title>
	<atom:link href="http://eduardo.cereto.net/category/javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://eduardo.cereto.net</link>
	<description>Web Analytics, Javascript, Python and Rum</description>
	<lastBuildDate>Thu, 02 Feb 2012 01:26:26 +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>The bugfix that could make the internet 5% faster</title>
		<link>http://eduardo.cereto.net/the-bugfix-that-could-make-the-internet-faster</link>
		<comments>http://eduardo.cereto.net/the-bugfix-that-could-make-the-internet-faster#comments</comments>
		<pubDate>Thu, 12 Jan 2012 16:01:11 +0000</pubDate>
		<dc:creator>Eduardo Cereto</dc:creator>
				<category><![CDATA[Google Analytics]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[bugfix]]></category>
		<category><![CDATA[google analytics cookie]]></category>
		<category><![CDATA[google analytics impact]]></category>
		<category><![CDATA[speed]]></category>

		<guid isPermaLink="false">http://eduardo.cereto.net/?p=176</guid>
		<description><![CDATA[I&#8217;ve been working with Google Analytics for the last 3 years. When I started working with it it was already a very huge player on the market, but I&#8217;ve seen enormous growth on these  years. Google Analytics is the most used web analytics solution &#8230; <a href="http://eduardo.cereto.net/the-bugfix-that-could-make-the-internet-faster">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://eduardo.cereto.net/the-bugfix-that-could-make-the-internet-faster"></g:plusone>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>I&#8217;ve been working with Google Analytics for the last 3 years. When I started working with it it was already a very huge player on the market, but I&#8217;ve seen enormous growth on these  years. Google Analytics is the most used web analytics solution in the world. It&#8217;s used on currently 44.67% of the top million websites on the internet. ga.js is the most popular javascript snippet in the history of the internet.</p>
<p><strong>Google Analytics Usage on top websites:</strong></p>
<div id="attachment_177" class="wp-caption aligncenter" style="width: 610px"><a href="http://trends.builtwith.com/analytics/Google-Analytics"><img class="size-medium wp-image-177" title="GA Usage" src="http://eduardo.cereto.net/wp-content/uploads/2012/01/Screen-Shot-2012-01-12-at-1.17.55-PM-600x323.png" alt="" width="600" height="323" /></a><p class="wp-caption-text">source: builtwith.com</p></div>
<p>Imagine the responsibility of the Google engineering team that maintains the ga.js javascript file. While having to deal with multiple recent changes and new features on Google Analytics still have to make sure that their code runs as fast as possible and on all browsers that exist. They must support ie5.5 and low end mobile devices, otherwise these browsers wouldn&#8217;t show up on Google analytics reports. Still they must do it while keeping the code from affecting the website performance.</p>
<p>I must say that they do a great work on keeping that code. The asynchronous syntax while confusing at first is a very clever way to push code execution and loading way down on the queue, so browsers don&#8217;t delay the page loading to register a GA pageview. It&#8217;s clear that the GA team takes great care when it comes to how fast and seamless their code is.</p>
<p>The one point that still bothers me a lot regarding performance are the Google Analytics cookies. Let&#8217;s take a look at what GA cookies look like:</p>
<pre>&gt;document.cookie
"__utma=96182344.347392035.1326382423.1326382423.1326382423.1; __utmb=96182344.1.10.1326382423; __utmc=96182344; __utmz=96182344.1326382423.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)"
&gt;document.cookie.length
188</pre>
<p>This is a minimum GA cookie. It can get longer if you use Custom Variables and Google Website Optimizer. But let&#8217;s settle down with the minimum for now.<br />
These cookies are used iternally in GA to keep state and are manipulated by the code on ga.js javascript file. Different from most other cookies you might see out there these cookies don&#8217;t need to hit your webservers never. Still they hit your website every single time an HTTP request is made.</p>
<p>According to<a href="http://dev.chromium.org/spdy/spdy-whitepaper"> Google SPDY whitepaper</a> the average HTTP request is 700-800 bytes long. That means that GA Cookies represent about 25% of that HTTP request size. The moment you notice GA is present in about 50% of top websites you notice that useless GA cookies going around the internet represent 12% of all HTTP requests.</p>
<p>I&#8217;ve posted a bug regarding this issue on <a href="http://code.google.com/p/analytics-issues/issues/detail?can=5&amp;start=0&amp;num=100&amp;q=&amp;colspec=ID%20Component%20Type%20Status%20Priority%20Stars%20Summary&amp;groupby=&amp;sort=&amp;id=143">GA-Issues</a> a while ago. The idea is to use HTML5 localStorage to store the cookies on browsers that support it. Still it has attracted no attention so far. This bug fix could easily make the average HTTP request around 5% faster. We&#8217;re talking about the average speed of the whole internet.</p>
<p>The real picture is not that bad, since this only affect HTTP requests and not HTTP responses and that&#8217;s where the real data is. Still it&#8217;s funny to see something that huge going around unnoticed.</p>
]]></content:encoded>
			<wfw:commentRss>http://eduardo.cereto.net/the-bugfix-that-could-make-the-internet-faster/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Google Analytics _setAllowHash bug</title>
		<link>http://eduardo.cereto.net/google-analytics-_setallowhash-bug</link>
		<comments>http://eduardo.cereto.net/google-analytics-_setallowhash-bug#comments</comments>
		<pubDate>Tue, 23 Feb 2010 17:40:29 +0000</pubDate>
		<dc:creator>Eduardo Cereto</dc:creator>
				<category><![CDATA[Google Analytics]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[ga.js]]></category>
		<category><![CDATA[GATC]]></category>
		<category><![CDATA[_setAllowHash]]></category>
		<category><![CDATA[_setNamespace]]></category>

		<guid isPermaLink="false">http://eduardo.cereto.net/?p=39</guid>
		<description><![CDATA[GATC (Google Analytics Tracking Code) has an annoying bug with _setAllowHash. Suppose you have something like this: Domain http://test.cereto.net/ that has a GATC for multiple sub-domains. Domain http://test2.cereto.net/ that has both our tracker and a secondary default tracker that we &#8230; <a href="http://eduardo.cereto.net/google-analytics-_setallowhash-bug">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://eduardo.cereto.net/google-analytics-_setallowhash-bug"></g:plusone>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>GATC (Google Analytics Tracking Code) has an annoying bug with _setAllowHash.</p>
<p>Suppose you have something like this:</p>
<ul>
<li>Domain http://test.cereto.net/ that has a GATC for multiple sub-domains.</li>
<li>Domain http://test2.cereto.net/ that has both our tracker and a secondary default tracker that we don&#8217;t control.</li>
</ul>
<p>If you use this configuration it should work as expected. Two sets of cookies are gonna be created. One set inside domain test2.cereto.net and the second set inside .cereto.net. GATC will know which cookie to look at on both cases.</p>
<p>But now suppose you also want to track domain www.my-other-domain.com in the same account. What you&#8217;d need to do is:</p>
<ul>
<li>Use _setAllowLinker(true) on both accounts.</li>
<li>Use _getLinkerUrl() or _link() on the links that go from one site to another and vice versa.</li>
<li>Use _setAllowHash(false) on both domains.</li>
</ul>
<p>_link() and _getLinkerUrl() will move the cookies from one domain to another. _setAllowLinker(true) is needed for GATC to look on URI for cookie parameters.</p>
<p>Q: Now why would you need _setAllowHash(false)? A: The GA cookies have a parameter that is a domain hash (in red below ). Of course the hashes from both our domains are gonna be diferent. In that case Google will trash the cookie when it sees that the hash doesn&#8217;t match the current domain. So we set _setAllowHash(false) and everything is  fine. Is it?</p>
<blockquote><p>Cookie with a domain hash<br />
__utma=<strong><span style="color: #ff0000;">253008534</span></strong>.504424944.1258547704.1258547704.1258547704.1</p>
<p>Cookie with Domain Hash disabled<br />
__utma=<span style="color: #ff0000;"><strong>1</strong></span>.504424944.1258547704.1258547704.1258547704.1</p></blockquote>
<p>But now we don&#8217;t have the Hash anymore and it&#8217;s very important to GATC. When we&#8217;re reading cookies with javascript we have no information about the cookie besides value and name. The Hash is important so GATC knows which is the right cookie for that specific GATC.</p>
<p>In our setup we&#8217;ll have two sets of cookies available from test2.directperformance.com.br. If we disable the Domain Hash on both there&#8217;s no way for GATC to get the correct one. This will lead to ga.js firing pageviews with mixed data from both the cookies. This will mix origin, user hash, custom variables and more. Generating unexpected results on Analytics Interface.</p>
<p>This is an old bug. You must avoid it but sometimes there&#8217;s no way. It&#8217;s present no matter if you use default _gat or the new <a href="http://code.google.com/apis/analytics/docs/tracking/asyncTracking.html">Async Tracker</a> _gaq.</p>
<h3>Example</h3>
<p>I created a little test to illustrate the issue:</p>
<ul>
<li>Access <a href="http://test.cereto.net/?utm_source=CampX&amp;utm_medium=blog&amp;utm_campaign=promo">first domain using a url with campaign variables</a>. This has a single tracker/single cookie</li>
<li>Now access <a href="http://test2.cereto.net/">second domain directly</a>. It has two trackers each in a diferent domain, so 2 different cookies.</li>
<li>The cookies were created accordingly, one for each tracker. The first one still has the campaign origin, and the second should be a refferal from this blog now.</li>
<li>Since you have _setAllowHash(false) on both trackers, GATC don&#8217;t know which cookie to parse.</li>
<li>You can see using <a href="https://addons.mozilla.org/en-US/firefox/addon/6647">HttpFox</a> or similar that both pageviews have the same origin.</li>
</ul>
<p>As explained GATC didn&#8217;t know which was the correct cookie, and got the first one.</p>
<h3>Solution</h3>
<p>There&#8217;s no good solution at this time, besides avoiding this setup.</p>
<p>All could be solved if _setAllowLinker(true) simply ignored the domain hash and used the hash for the current domain instead, after all it makes no sense to check the domain hash on the cookies you&#8217;re importing.</p>
<p>There&#8217;s an undocumented feature on ga.js that seems to fix it. It&#8217;s the function _setNamespace(&#8216;ns&#8217;). If you use this on one or both trackers (with different Namespace for each of course). This problem is gone. But it&#8217;s not safe to use undocumented features as it might change in the future or removed completely generating unexpected results. You won&#8217;t want to use that on your production code.</p>
<p>This post is intended to get this bug properly documented since there&#8217;s no public bug tracker for ga.js and I didn&#8217;t get proper response or position from Google on any related user groups out there;</p>
]]></content:encoded>
			<wfw:commentRss>http://eduardo.cereto.net/google-analytics-_setallowhash-bug/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Event order in different browsers</title>
		<link>http://eduardo.cereto.net/event-order-in-different-browsers</link>
		<comments>http://eduardo.cereto.net/event-order-in-different-browsers#comments</comments>
		<pubDate>Thu, 30 Jul 2009 23:30:52 +0000</pubDate>
		<dc:creator>Eduardo Cereto</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[cross-browser]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://eduardo.cereto.net/?p=20</guid>
		<description><![CDATA[I had an issue today where my event had to be triggered after another event in the onload property of body. I wasn&#8217;t sure if my event would be triggered after or before so I wrote a quick code to &#8230; <a href="http://eduardo.cereto.net/event-order-in-different-browsers">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://eduardo.cereto.net/event-order-in-different-browsers"></g:plusone>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>I had an issue today where my event had to be triggered after another event in the onload property of body. I wasn&#8217;t sure if my event would be triggered after or before so I wrote a quick code to test it. I was pretty sure, from the very start, that the results would disappoint me.</p>
<p>Here&#8217;s the code I used to test.</p>
<pre class="javascript">&lt;html&gt;
&lt;head&gt;
 &lt;title&gt;Event Tests&lt;/title&gt;
 &lt;script&gt;
 if(window.addEventListener){
 window.addEventListener('load',function(){alert('event1')},false);
 }else if(window.attachEvent){
 window.attachEvent('onload',function(){alert('event1');})
 }
 &lt;/script&gt;
 &lt;script src='jquery-min.js'&gt;&lt;/script&gt;
 &lt;script&gt;
 $(document).ready(function(){
 alert('jq1');
 });

 if(window.addEventListener){
 window.addEventListener('load',function(){alert('event2')},false);
 }else if(window.attachEvent){
 window.attachEvent('onload',function(){alert('event2');})
 }

 $(document).ready(function(){
 alert('jq2');
 });
 &lt;/script&gt;
&lt;/head&gt;
&lt;body onload='alert("event3")'&gt;
 &lt;script&gt;
 if(window.addEventListener){
 window.addEventListener('load',function(){alert('event4')},false);
 }else if(window.attachEvent){
 window.attachEvent('onload',function(){alert('event4');})
 }
 $(document).ready(function(){
 alert('jq3');
 });
 if(window.addEventListener){
 window.addEventListener('load',function(){alert('event5')},false);
 }else if(window.attachEvent){
 window.attachEvent('onload',function(){alert('event5');})
 }
 &lt;/script&gt;
 &lt;h1&gt;Event Tests&lt;/h1&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3>Firefox 3.5 &amp; Google Chrome</h3>
<p>Firefox and Chrome both worked as expected. The jQuery Events were triggered first as I suspected and I was starting to get happy. Here&#8217;s the order they executed.</p>
<ol>
<li>jq1</li>
<li>jq2</li>
<li>jq3</li>
<li>event1</li>
<li>event2</li>
<li>event3</li>
<li>event4</li>
<li>event5</li>
</ol>
<h3>Internet Explorer 8</h3>
<p>Here on the other hand things started to get ugly. My smile fade away while ie shouted the following:</p>
<ol>
<li>jq1</li>
<li>jq2</li>
<li>jq3</li>
<li>event3</li>
<li>event5</li>
<li>event4</li>
<li>event2</li>
<li>event1</li>
</ol>
<h3>Internet Explorer 6 &amp; 7</h3>
<p>Run while you can.</p>
<ol>
<li>jq1</li>
<li>jq2</li>
<li>jq3</li>
<li>event3</li>
<li>event2</li>
<li>event4</li>
<li>event5</li>
<li>event1</li>
</ol>
<p>I think these results are completely nonsense. I&#8217;d be glad if someone could shed some light on this behavior. At least jQuery can save you from this madness.</p>
<h3>Conclusion</h3>
<p>Do you want to control the way your events trigger cross-browser without insane hacks? Go with <strong>jQuery</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://eduardo.cereto.net/event-order-in-different-browsers/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

