<?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>Navarr&#039;s Tech Side &#187; google analytics</title>
	<atom:link href="http://tech.navarr.me/tag/google-analytics/feed" rel="self" type="application/rss+xml" />
	<link>http://tech.navarr.me</link>
	<description>The Technical Side of my Life</description>
	<lastBuildDate>Tue, 07 Feb 2012 22:32:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<cloud domain='tech.navarr.me' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>Making Google Analytics Work in XHTML</title>
		<link>http://tech.navarr.me/2010/04/making-google-analytics-work-in-xhtml.html</link>
		<comments>http://tech.navarr.me/2010/04/making-google-analytics-work-in-xhtml.html#comments</comments>
		<pubDate>Sun, 04 Apr 2010 16:37:29 +0000</pubDate>
		<dc:creator>Navarr</dc:creator>
				<category><![CDATA[(X)HTML 5]]></category>
		<category><![CDATA[Google Analytics]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[google analytics]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[xhtml]]></category>
		<category><![CDATA[xhtml5]]></category>

		<guid isPermaLink="false">http://tech.gtaero.net/?p=431</guid>
		<description><![CDATA[I was moving my website, Google Voice for Outlook, over from HTML5 to XHTML5 today, and as soon as I did the basic content negotiation filters in PHP so that it would send the appropriate headers if the client supported XHTML as well as only outputting the &#60;?xml if the client supported XHTML, I checked [...]]]></description>
			<content:encoded><![CDATA[<p>I was moving my website, Google Voice for Outlook, over from HTML5 to XHTML5 today, and as soon as I did the basic content negotiation filters in PHP so that it would send the appropriate headers if the client supported XHTML as well as only outputting the &lt;?xml if the client supported XHTML, I checked my developer tools to find a JavaScript error.  It was Google Analytics, of course.  document.write doesn’t exist in XHTML, after all.</p>
<p>The fix was simple, replace the current four line inclusion code with:</p>
<pre><div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://tech.navarr.me/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://tech.navarr.me/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://tech.navarr.me/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://tech.navarr.me/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><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: #003366; font-weight: bold;">var</span> gaJsHost <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;https:&quot;</span> <span style="color: #339933;">==</span> document.<span style="color: #660066;">location</span>.<span style="color: #660066;">protocol</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">&quot;https://ssl.&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://www.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> script <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>
	script.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> gaJsHost <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;google-analytics.com/ga.js&quot;</span><span style="color: #339933;">;</span>
	script.<span style="color: #660066;">type</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;text/javascript&quot;</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>0<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>script<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></pre>
<p>This will work fine, unless of course you have no head tag.  In which case you should replace getElementsByTagName(“head”) with getElementsByTagName(“html”).</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.navarr.me/2010/04/making-google-analytics-work-in-xhtml.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Never Again (External JavaScript in the Body)</title>
		<link>http://tech.navarr.me/2010/01/never-again-external-javascript-in-the-body.html</link>
		<comments>http://tech.navarr.me/2010/01/never-again-external-javascript-in-the-body.html#comments</comments>
		<pubDate>Wed, 13 Jan 2010 02:55:22 +0000</pubDate>
		<dc:creator>Navarr</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[google analytics]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://tech.gtaero.net/2010/01/never-again-external-javascript-in-the-body.html</guid>
		<description><![CDATA[This is probably simply a personal taste, but I hate putting External JavaScript tags in the body of a web page.  It feels and looks very unsightly to me.  But as I learn more and more JavaScript, and really start to get a feel for the small language, I’ve realized that I don’t have to.  [...]]]></description>
			<content:encoded><![CDATA[<p>This is probably simply a personal taste, but I hate putting External JavaScript tags in the body of a web page.  It feels and looks very unsightly to me.  But as I learn more and more JavaScript, and really start to get a feel for the small language, I’ve realized that I don’t have to.  That it’d be just as easy to place them directly into the header after the page is ready, by manipulating the DOM.  Here is an excerpt from the beta turled website.</p>
<pre><div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://tech.navarr.me/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://tech.navarr.me/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://tech.navarr.me/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://tech.navarr.me/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</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>
	<span style="color: #006600; font-style: italic;">// Google Analytics</span>
	<span style="color: #003366; font-weight: bold;">var</span> gaJsHost <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;https:&quot;</span> <span style="color: #339933;">==</span> document.<span style="color: #660066;">location</span>.<span style="color: #660066;">protocol</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">&quot;https://ssl.&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://www.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> script <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>
	script.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> gaJsHost <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;google-analytics.com/ga.js&quot;</span><span style="color: #339933;">;</span>
	script.<span style="color: #660066;">type</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;text/javascript&quot;</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>0<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>script<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">try</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> pageTracker <span style="color: #339933;">=</span> _gat._getTracker<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;CENSORED&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		pageTracker._trackPageview<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: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>err<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009966; font-style: italic;">/* Do Nothing. */</span> <span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// Facebook Share</span>
	<span style="color: #003366; font-weight: bold;">var</span> script <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>
	script.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://static.ak.fbcdn.net/connect.php/js/FB.Share&quot;</span><span style="color: #339933;">;</span>
	script.<span style="color: #660066;">type</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;text/javascript&quot;</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>0<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>script<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></pre>
<p>As you can see, I wait until the document is loaded using jQuery’s ready method, and then create elements for both Google Analytics and Facebook Share, before appending them directly to the &lt;head&gt; of the website.  Keeping the code clean, reducing bandwidth usage for non-JavaScript users, and even making Google’s code cleaner.  (By changing Google Analytic’s default code from document.write to DOM Manipulation.</p>
<p>So, Never again will I feel the need to insert external script tags at the bottom of the &lt;body&gt; just so that the rest of the page loads before them.</p>
<p><strong>Note:</strong> If you’re not using jQuery, document.onload = function() { /* Code */ } works just as well, I promise.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.navarr.me/2010/01/never-again-external-javascript-in-the-body.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

