<?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>MattKruse.com &#187; statistics</title>
	<atom:link href="http://mattkruse.com/tag/statistics/feed/" rel="self" type="application/rss+xml" />
	<link>http://mattkruse.com</link>
	<description></description>
	<lastBuildDate>Sat, 14 Aug 2010 21:08:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Generate Useful iGoogle Gadget User Statistics</title>
		<link>http://mattkruse.com/2008/12/09/generate-useful-igoogle-gadget-user-statistics/</link>
		<comments>http://mattkruse.com/2008/12/09/generate-useful-igoogle-gadget-user-statistics/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 04:59:03 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[igoogle gadgets]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[analytics]]></category>
		<category><![CDATA[gadgets]]></category>
		<category><![CDATA[igoogle]]></category>
		<category><![CDATA[statistics]]></category>

		<guid isPermaLink="false">http://mattkruse.com/?p=70</guid>
		<description><![CDATA[If you are a gadget author, you&#8217;re probably interested in knowing how many users have your gadgets installed. There are a few ways to deduce this information, but none are perfect. I&#8217;m going to show you one way to generate useful information that is probably something you&#8217;re looking for.
Gadget Directory Details
The first approach is to [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-71" style="border: 1px solid black; margin: 15px; float:left;" title="Google Analytics" src="http://mattkruse.com/wp-content/uploads/2008/12/analytics.png" alt="" width="350" height="326" />If you are a gadget author, you&#8217;re probably interested in knowing how many users have your gadgets installed. There are a few ways to deduce this information, but none are perfect. I&#8217;m going to show you one way to generate useful information that is probably something you&#8217;re looking for.</p>
<h3>Gadget Directory Details</h3>
<p>The first approach is to just look at the <a href="http://www.google.com/ig/directory?type=gadgets" target="_blank">iGoogle Gadget Directory</a> entry for your gadget. It should show how many users you have. In fact, my <a href="http://www.google.com/ig/directory?url=www.javascripttoolbox.com/gadget/gadgetmonitor/gadgetmonitor.xml" target="_blank">Gadget Monitor</a> gadget retrieves its information from here for user counts. Unfortunately, if you look at different internationalized versions of the directory, you&#8217;ll see different numbers based on how many of those users have it installed. There is no place to get a single consolidated number.</p>
<h3>Analytics</h3>
<p>A better approach is to use <a href="http://www.google.com/analytics/" target="_blank">Google Analytics</a>. In the gadget developer documentation there are <a href="http://code.google.com/apis/gadgets/docs/legacy/tools.html#Analytics" target="_blank">instructions on how to use analytics with gadgets</a>. But using it in the default way &#8211; recording one hit every time your gadget is loaded &#8211; is not all that useful because:</p>
<ul>
<li>Users may load your gadget many times in one day, and this fact isn&#8217;t really relevant like page views on a web site are</li>
<li>If you record multiple hits per person using your gadget, you still don&#8217;t know how many distinct users are using your gadget</li>
<li>Even looking at the &#8220;unique pageviews&#8221; data in Analytics can be misleading, because if the user has multiple sessions in the same day, it still gets counted more than once</li>
</ul>
<h3>New Goals</h3>
<p>The approach I use takes advantage of Analytics, but in a different way. The goals are:</p>
<ul>
<li>Get as accurate a count as possible of how many unique users interacted with your gadget in a day</li>
<li>Get a count of how many times your gadget was added by new users in a given day</li>
</ul>
<p>This approach, unfortunately, will not get you any closer to knowing how many people have your gadget on their iGoogle page and didn&#8217;t hit it one day, or maybe have it on a tab that they didn&#8217;t look at one day.</p>
<h3>A Different Approach</h3>
<p>I&#8217;ll explain this new approach by example.</p>
<p>First, in the <a href="http://code.google.com/apis/gadgets/docs/legacy/basic.html#Moduleprefs" target="_blank">ModulePrefs</a> declaration of your gadget, you need to require two features:</p>
<blockquote>
<pre>&lt;Require feature="analytics"/&gt;
&lt;Require feature="setprefs" /&gt;</pre>
</blockquote>
<p>Second, you need a hidden user preference to store some data:</p>
<blockquote>
<pre>&lt;UserPref name="today" datatype="hidden" defaultvalue="" /&gt;</pre>
</blockquote>
<p>Finally, some javascript code in your Content section:</p>
<blockquote>
<pre>// Get a reference to user preferences
var prefs = new _IG_Prefs();
// Get the user's current date/time
var now = new Date();
// Create a date string of the form yyyy-m-d
var today = (now.getFullYear?now.getFullYear():now.getYear())+'-'+(now.getMonth()+1)+'-'+now.getDate();
// Get the stored value of the "today" user preference.
var prefs_today = prefs.getString('today');

// If the "today" user preference is blank, then the user has never loaded
// this gadget. They must have just added it!
if (prefs_today=='') {
    _IG_Analytics("UA-0000000-0", "/addgadget/mygadget");
}
// If the generated date string doesn't match the one stored in the
// preferences, then this is the first time the user has loaded the
// gadget today. Record a hit and change the preferernce to be
// today's date string so it won't get recorded again.
if (prefs_today!=today) {
    prefs.set('today',today);
    _IG_Analytics("UA-0000000-0", "/gadget/mygadget");
}</pre>
</blockquote>
<p>(Note: in the above code, replace UA-0000000-0 with your Analytic account&#8217;s unique ID, and &#8216;mygadget&#8217; with a unique identifier for your specific gadget)</p>
<p>The concept here is simple. Every time the gadget loads, it will get a string representing today&#8217;s date. If the date doesn&#8217;t match the value stores in the user&#8217;s preferences (for example, if the gadget was last loaded yesterday), then record a hit for today and update the preference.</p>
<p>This way, a single user will only record one hit a day to the Analytics counter. You get a pretty accurate count of how many unique users are using your gadget in a single day.</p>
<p>Since the preference gets updated every day the user loads the gadget, if it is blank that means this must be the first time it&#8217;s being loaded. That effectively means they have just added it. In that case, record a hit to a separate url starting with /addgadget to separate that from the other url.</p>
<p>An advantage of putting each hit in a &#8220;subdirectory&#8221; in analytics is so you can effectively use the drill-down report. By looking at the numbers for the entire /addgadget directory you can get a count of gadgets added in a day across all your different gadgets. Looking at the numbers for /gadget as a whole gives you a user count of all your gadgets combined.</p>
<p>I hope this approach proves to be as useful to you as it has been for me!</p>
]]></content:encoded>
			<wfw:commentRss>http://mattkruse.com/2008/12/09/generate-useful-igoogle-gadget-user-statistics/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
