<?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>Web 3.0, 6 Bladed Razors, 7 Minute Abs &#187; Google Analytics</title>
	<atom:link href="http://www.zachleat.com/web/tag/google-analytics/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zachleat.com/web</link>
	<description></description>
	<lastBuildDate>Mon, 06 Feb 2012 17:09:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Speed up Including Google Analytics</title>
		<link>http://www.zachleat.com/web/speed-up-google-analytics-with-dynamic-includes/</link>
		<comments>http://www.zachleat.com/web/speed-up-google-analytics-with-dynamic-includes/#comments</comments>
		<pubDate>Fri, 02 Nov 2007 04:27:13 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Google Analytics]]></category>
		<category><![CDATA[Timers]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/2007/11/01/speed-up-google-analytics-with-dynamic-includes/</guid>
		<description><![CDATA[Have you ever noticed that your homepage hangs when including the Google Analytics JavaScript file? I think a few people have noticed a delay. Well, let&#8217;s try something different. Let&#8217;s create the script node dynamically using DOM methods and put a timeout on this creation so that it inserts just enough delay so that your [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever noticed that your homepage hangs when including the Google Analytics JavaScript file?  I think <a href="http://nutrun.com/weblog/does-google-analytics-make-your-pages-slow/">a few</a> <a href="http://resistmedia.net/blog/2007/10/02/get-rid-of-google-analytics/">people</a> have noticed a delay.  Well, let&#8217;s try something different.  Let&#8217;s create the script node dynamically using DOM methods and put a timeout on this creation so that it inserts just enough delay so that your page won&#8217;t hang (we&#8217;ll move out of the current execution path with the timeout, thus allowing your page to finish loading).  The obvious benefit here is that even when the Google servers lag a little bit serving you the JavaScript file, your page will appear as if it has already finished loading.  Given optimally performing Google Servers, this method will perform slower most of the time, but it shines in those rare instances where there is a bit of a delay.  Give it a try, and let me know if it works any better.</p>
<p>Of course, remember to put near the end of your <code>&lt;body&gt;</code>, and not directly in your <code>&lt;head&gt;</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #009900;">&#40;</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>
    setTimeout<span style="color: #009900;">&#40;</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> node <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;script&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        node.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://www.google-analytics.com/urchin.js'</span><span style="color: #339933;">;</span>
        <span style="color: #006600; font-style: italic;">//for SSL</span>
        <span style="color: #006600; font-style: italic;">//node.src = 'https://ssl.google-analytics.com/urchin.js';</span>
        node.<span style="color: #660066;">type</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'text/javascript'</span><span style="color: #339933;">;</span>
        document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;head&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>node<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> init <span style="color: #339933;">=</span> setInterval<span style="color: #009900;">&#40;</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>
            _uacct <span style="color: #339933;">=</span> <span style="color: #3366CC;">'UA-XXXXXX-X'</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// INSERT YOUR CODE HERE</span>
            <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> urchinTracker <span style="color: #339933;">!=</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                urchinTracker<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                clearInterval<span style="color: #009900;">&#40;</span>init<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</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: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p><a href="http://www.zachleat.com/Projects/googleAnalytics/">Try it on my benchmark page.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/speed-up-google-analytics-with-dynamic-includes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

