<?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>Search Marketing&#187; Web Analytics Blog Posts &#8211; Epiphany Solutions Digital Marketing Blog</title>
	<atom:link href="http://www.epiphanysolutions.co.uk/blog/search-marketing/web-analytics/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.epiphanysolutions.co.uk/blog</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Wed, 08 Feb 2012 09:32:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Google Analytics Asynchronous Code Migration Tips</title>
		<link>http://www.epiphanysolutions.co.uk/blog/google-analytics-asynchronous-code-migration-tips/</link>
		<comments>http://www.epiphanysolutions.co.uk/blog/google-analytics-asynchronous-code-migration-tips/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 13:41:04 +0000</pubDate>
		<dc:creator>Daniel Peden</dc:creator>
				<category><![CDATA[Google Analytics]]></category>
		<category><![CDATA[Web Analytics]]></category>

		<guid isPermaLink="false">http://www.epiphanysolutions.co.uk/blog/?p=2569</guid>
		<description><![CDATA[In late 2009 Google officially launched its asynchronous tracking code. The new snippet addresses 3 of the larger problem areas for the web analytics industry: Page load times Data collection &#38; accuracy Error rates As a general overview Google Analytics seem to have gotten it right – yey! Google Analytics never really had a problem [...]]]></description>
			<content:encoded><![CDATA[<p>In late 2009 Google officially launched its asynchronous tracking code. The new snippet addresses 3 of the larger problem areas for the web analytics industry:</p>
<ul>
<li>Page load times</li>
<li>Data collection &amp; accuracy</li>
<li>Error rates</li>
</ul>
<p><span id="more-2569"></span><br />
As a general overview Google Analytics seem to have gotten it right – yey! Google Analytics never really had a problem with page load times but the new snippet improves the load times of even lightweight sites.</p>
<p>Data accuracy and error rates also seem to have improved…..when the code is implemented correctly – this brings me nicely to the purpose of this post. Despite a large level of information supplied by Google on how to migrate to the asynchronous code, web development departments still appear to be getting it wrong!</p>
<p>So here are some of the common problems I have witnessed and some simple code migration tips:</p>
<p><strong>Common problem #1: Leaving the older code present</strong></p>
<p>Although you might think it is silly, I have seen sites with the new asynchronous code implemented inside the HTML head and the older ga.js snippet implemented in the body.</p>
<p><strong>Tip #1: Locate all ga.js code first</strong></p>
<p>Get your site’s source code and use a decent search tool such as Notepad++ to scan each of your code files for “ga.js”, “UA-“ and “pageTracker”. This is a good way of quickly locating all the pages that contain your current Google Analytics code. Make a note of these pages as you WILL need to change them at some point. In the majority of cases you will be removing the code completely because the Google Analytics code moves from before the closing body tag to before the closing head tag. This leads me to:</p>
<p><strong>Common problem #2: Incorrect code location</strong></p>
<p>It’s amazing the number of different locations I have seen the asynchronous code located &#8211; I think my favourite was above the opening HTML tag</p>
<p>Sometimes it’s clear that web platforms have restricted the location of the code but where possible it should be placed in its correct location.</p>
<p><strong> Tip #2: The async code should be place just before the closing HEAD tag</strong></p>
<p>If you can’t get it in there get it as close to the opening body tag as possible.</p>
<p><strong>Common Problem #3: Not using the migration guide</strong></p>
<p>Ok this is a bit of a cop out, but on some sites it looks like developers just guessed what code needed to be present. Google provides the migration guide as a reference, you can look at what code you have on your current site and what the equivalent asynchronous version is. This leads me to:</p>
<p><strong>Tip #3: Use the migration guide</strong></p>
<p>The <a href="http://code.google.com/apis/analytics/docs/tracking/asyncMigrationExamples.html">migration guide from Google</a> is a great reference if you are unclear about what code should go where. The one area it doesn’t cover and our final common problem:</p>
<p><strong>Common Problem #4: Incorrect snippet order</strong></p>
<p>A standard ga.js snippet looks like:</p>
<p>&lt;script type=&#8221;text/javascript&#8221;&gt;<br />
var gaJsHost = ((&#8220;https:&#8221; == document.location.protocol) ? &#8220;https://ssl.&#8221; : &#8220;http://www.&#8221;);<br />
document.write(unescape(&#8220;%3Cscript src=&#8217;&#8221; + gaJsHost + &#8220;google-analytics.com/ga.js&#8217; type=&#8217;text/javascript&#8217;%3E%3C/script%3E&#8221;));<br />
&lt;/script&gt;</p>
<p>&lt;script type=&#8221;text/javascript&#8221;&gt;<br />
try {<br />
var pageTracker = _gat._getTracker(&#8220;UA-XXXXXX-1&#8243;);<br />
pageTracker._trackPageview();<br />
} catch(err) {}&lt;/script&gt;</p>
<p>It is essentially in 2 parts:</p>
<p>[TRACKING CODE] being:</p>
<p>&lt;script type=&#8221;text/javascript&#8221;&gt;<br />
var gaJsHost = ((&#8220;https:&#8221; == document.location.protocol) ? &#8220;https://ssl.&#8221; : &#8220;http://www.&#8221;);<br />
document.write(unescape(&#8220;%3Cscript src=&#8217;&#8221; + gaJsHost + &#8220;google-analytics.com/ga.js&#8217; type=&#8217;text/javascript&#8217;%3E%3C/script%3E&#8221;));<br />
&lt;/script&gt;</p>
<p>[TRACKING ELEMENTS] being:</p>
<p>&lt;script type=&#8221;text/javascript&#8221;&gt;<br />
try {<br />
var pageTracker = _gat._getTracker(&#8220;UA-XXXXXX-1&#8243;);<br />
pageTracker._trackPageview();<br />
} catch(err) {}&lt;/script&gt;</p>
<p>From an overview perspective the code is in the following order:</p>
<p>[TRACKING CODE]<br />
[TRACKING ELEMENTS]</p>
<p>The same is <strong>NOT</strong> true of the asynchronous code. The async code is still essentially in 2 parts but the parts are in<strong> reverse order</strong> to that of the ga.js.</p>
<p><strong>Tip #4: Ensure the code order is correct</strong></p>
<p>The async code still has the same 2 parts:</p>
<p>[TRACKING ELEMENTS] being:</p>
<p>&lt;script type=&#8221;text/javascript&#8221;&gt;</p>
<p>var _gaq = _gaq || [];<br />
_gaq.push(['_setAccount', 'UA-XXXXX-X']);<br />
_gaq.push(['_trackPageview']);</p>
<p>[TRACKING CODE] being:<br />
(function() {<br />
var ga = document.createElement(&#8216;script&#8217;); ga.type = &#8216;text/javascript&#8217;; ga.async = true;<br />
ga.src = (&#8216;https:&#8217; == document.location.protocol ? &#8216;https://ssl&#8217; : &#8216;http://www&#8217;) + &#8216;.google-analytics.com/ga.js&#8217;;<br />
var s = document.getElementsByTagName(&#8216;script&#8217;)[0]; s.parentNode.insertBefore(ga, s);<br />
})();</p>
<p>&lt;/script&gt;</p>
<p>But the orders are reversed. The tracking elements are now in front of the tracking code.</p>
<p>The order of the tracking elements is also important with the ­_trackPageview call being the last tracking element on all basic installations and the majority of advanced ones. This brings me to my final tip:</p>
<p><strong>Tip #5: Ensure tracking elements order is correct</strong></p>
<p>Having an incorrect order for the tracking elements is a sure fire way to have inaccurate stats. As a general rule the _trackPageview call will be the last of the tracking elements and the _setAccount call will generally be the first.</p>
<p>If you are in doubt, unsure or just don’t know – ask a <a href="http://www.google.com/analytics/partners.html">Google Analytics Certified Professional</a> (GACP) for advice – most (including ourselves) will offer <a href="../../../../../../ask-an-expert/">Google Analytics advice completely free</a>.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center">
<ul class="socials">
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.epiphanysolutions.co.uk/blog/google-analytics-asynchronous-code-migration-tips/&amp;title=Google+Analytics+Asynchronous+Code+Migration+Tips" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.epiphanysolutions.co.uk/blog/google-analytics-asynchronous-code-migration-tips/&amp;title=Google+Analytics+Asynchronous+Code+Migration+Tips" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.epiphanysolutions.co.uk/blog/google-analytics-asynchronous-code-migration-tips/&amp;t=Google+Analytics+Asynchronous+Code+Migration+Tips" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.epiphanysolutions.co.uk/blog/google-analytics-asynchronous-code-migration-tips/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.epiphanysolutions.co.uk/blog/google-analytics-asynchronous-code-migration-tips/&amp;title=Google+Analytics+Asynchronous+Code+Migration+Tips&amp;summary=In%20late%202009%20Google%20officially%20launched%20its%20asynchronous%20tracking%20code.%20The%20new%20snippet%20addresses%203%20of%20the%20larger%20problem%20areas%20for%20the%20web%20analytics%20industry%3A%0D%0A%0D%0A%09Page%20load%20times%0D%0A%09Data%20collection%20%26amp%3B%20accuracy%0D%0A%09Error%20rates%0D%0A%0D%0AAs%20a%20general%20overview%20Google%20Analytics%20seem%20to%20have%20gotten%20it%20right%20%E2%80&amp;source=Search Marketing" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://www.epiphanysolutions.co.uk/blog/google-analytics-asynchronous-code-migration-tips/&amp;title=Google+Analytics+Asynchronous+Code+Migration+Tips" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-sphinn">
			<a href="http://sphinn.com/index.php?c=post&amp;m=submit&amp;link=http://www.epiphanysolutions.co.uk/blog/google-analytics-asynchronous-code-migration-tips/" rel="nofollow" class="external" title="Sphinn this on Sphinn">Sphinn this on Sphinn</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.epiphanysolutions.co.uk/blog/google-analytics-asynchronous-code-migration-tips/&amp;title=Google+Analytics+Asynchronous+Code+Migration+Tips" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://www.epiphanysolutions.co.uk/blog/google-analytics-asynchronous-code-migration-tips/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Google+Analytics+Asynchronous+Code+Migration+Tips+-+http://b2l.me/adg3ma&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.epiphanysolutions.co.uk/blog/google-analytics-asynchronous-code-migration-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

