<?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>Unfinished Website &#187; Web Traffic &amp; Analytics</title>
	<atom:link href="http://www.unfinishedwebsite.com/category/web-traffic-analytics/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.unfinishedwebsite.com</link>
	<description>This website is never finished</description>
	<lastBuildDate>Fri, 13 Jan 2012 06:55:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Google Analytics Sample code for a Third-Party Website</title>
		<link>http://www.unfinishedwebsite.com/web-traffic-analytics/google-analytics-sample-code-for-a-third-party-website/</link>
		<comments>http://www.unfinishedwebsite.com/web-traffic-analytics/google-analytics-sample-code-for-a-third-party-website/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 08:35:48 +0000</pubDate>
		<dc:creator>Tommy Unger</dc:creator>
				<category><![CDATA[Web Traffic & Analytics]]></category>
		<category><![CDATA[Google Analytics]]></category>

		<guid isPermaLink="false">http://www.unfinishedwebsite.com/?p=33</guid>
		<description><![CDATA[I&#8217;m very surprised at how there appears to be just one lone example/sample showing the use of Google Analytics for a cross-domain, third party website, or e-commerce implementation.  Or maybe I&#8217;m just a bad googler.  My scenario involves hosting content which includes a subscribe or buy now link that takes the user to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m very surprised at how there appears to be just one lone example/sample showing the use of Google Analytics for a cross-domain, third party website, or e-commerce implementation.  Or maybe I&#8217;m just a bad googler.  My scenario involves hosting content which includes a subscribe or buy now link that takes the user to a third party e-commerce site where the actual order is processed.</p>
<p>Here&#8217;s what I found.  I searched for &#8220;google analytics cross domain&#8221; and this came up as the second <img src='http://www.unfinishedwebsite.com/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> It should be first) link:<br />
<a href="http://code.google.com/apis/analytics/docs/gaJSApiDomainDirectory.html">google analytics cross domain</a>. Ok, that&#8217;s the API, but without knowing a few tricks I couldn&#8217;t get it to work.</p>
<p>So then I tried, &#8220;google analytics third party&#8221;, and once again, <span id="more-33"></span> it&#8217;s not the first result, it&#8217;s the third.  But I found a decent example with <a href="http://www.google.com/support/analytics/bin/answer.py?hl=en&#038;answer=55532">google analytics third party</a></p>
<p>The only thing missing is highlighting of the important code. Here is my new and improved example for adding google analytics code to your third-party e-commerce or other external partner site.  I&#8217;ve included a small wordpress modification which can also come in handy.</p>
<ol>
<li>Add the proper onclick code to your anchor links.<br />
<code><br />
<strong style="color: red;">onclick="pageTracker._link(this.href); return false;"</strong><br />
</code><br />
Just for the heck of it, I&#8217;ve don&#8217;t this with my Wordpress bookmark links by modifying the functions.php in the theme directory:<br />
<code><br />
function AddTrackingGA($content)<br />
{<br />
        $link = "pageTracker._link(this.href);return false;";<br />
        $content = preg_replace("/&lt;a ([^>]+)>/sim", "&lt;a $1 onclick=\"" . $link. "\">", $content);<br />
        return $content;<br />
}<br />
add_filter('wp_list_bookmarks', 'AddTrackingGA');<br />
</code><br />
Or, if you like, just add<br />
to any anchor (&lt;a>) tags that go to your third party (soon to be)tracking enabled site.</p>
<div style="height: 20px">&nbsp;</div>
</li>
<li>Put this code on your own site (or modify your current tags to add the bold code).  And of course, don&#8217;t forget to change the _getTracker call to your tracking tag.<br />
<code><br />
&lt;script type="text/javascript"><br />
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");<br />
document.write(unescape("%3Cscript src='" + gaJsHost<br />
      + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));<br />
&lt;/script><br />
&lt;script type="text/javascript"><br />
var pageTracker = _gat._getTracker("UA-xxxxxx-x");<br />
<strong style="color: red;">pageTracker._setDomainName("none");</strong><br />
<strong style="color: red;">pageTracker._setAllowLinker(true);</strong><br />
pageTracker._trackPageview();<br />
&lt;/script><br />
</code></p>
<div style="height: 20px">&nbsp;</div>
</li>
<li>Put this content on your third party, e-commerce website.  Place it on all pages which you have access to on the third party site.  In my case I put it on the subscription form as well as the thank you for your successful subscription page:<br />
<code><br />
&lt;script type="text/javascript"><br />
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");<br />
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));<br />
&lt;/script><br />
&lt;script type="text/javascript"><br />
var pageTracker = _gat._getTracker("UA-xxxxxx-x");<br />
<strong style="color: red;">pageTracker._setDomainName("none");</strong><br />
<strong style="color: red;">pageTracker._setAllowLinker(true);</strong><br />
pageTracker._trackPageview();<br />
&lt;/script><br />
</code></p>
<div style="height: 20px">&nbsp;</div>
</li>
</ul>
<p>That&#8217;s more code than I typically like to throw around in a blog post, but that will have to do.</p>
<p>Finally, I&#8217;m impatient and want to verify things are working.  Because of Google&#8217;s rather difficult 24 hour latency, I like to verify that my Google Analytics tracking code is actually working.  There are two tools that I use typically to confirm that Google Analytics is working.  I like <a href="http://www.fiddlertool.com/Fiddler2/version.asp">Fiddler for Windows</a> which is a robust http and web traffic proxy sniffer that gives me every detail about my browser&#8217;s requests and the server&#8217;s responses.  Or, the les robust, but still effective <a href="http://livehttpheaders.mozdev.org/installation.html">LiveHTTPHeaders plugin</a> for Mozilla Firefox can give you a similar confirmation.  That confirmation is a request for a little gif hosted by google-analytics.com that looks like this:<br />
<strong style="color: red">http://www.google-analytics.com/__utm.gif?utmwv= &#8230; &#8230; &#8230;</strong></p>
<p>If you see that request in Fiddler or LiveHTTPHEaders along with your website requests and third party requests, then you have successfully installed Google Analytics in a third party, multiple domain scenario.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.unfinishedwebsite.com/web-traffic-analytics/google-analytics-sample-code-for-a-third-party-website/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

