Saturday 4 December 2010

Creating an application installation and usage tracker for Windows Phone 7



As an application developer you are generally interested in knowing how many times your application has been installed and how often it's really being used. Unfortunately WP7 and its market place don't offer this capabilities (yet?) so I decided to leverage a good old fashion website tracker.
My first idea was to use Google analytics because it has excellent reporting capabilities but unfortunately analytics only works if you integrate it with something that that runs JavaScript. It works with the WP7 Browser control but that control only works if it is visible. So to use Google analytics I had to include (two) visible browser controls in my application and suffer their overhead.
Instead I turned to http://www.statcounter.com/. They are free and offer the ability for tracking through a downloadable image that you can set to be 1x1 Pixel. I configured two counters, 1 for first start up and one for repeated startup and use the following code to call them:
private
static
void LoadUrl(string url)
{
   ThreadStart tStart = new
   ThreadStart(() =>
   {
   try
     
         HttpWebRequest trafficInfoRequest = WebRequest.CreateHttp(url);

         IAsyncResult result = (IAsyncResult)trafficInfoRequest.BeginGetResponse(new
         AsyncCallback((asynchronousResult) =>
         {
         try
            {
               HttpWebResponse trafficInforResponse = (HttpWebResponse)trafficInfoRequest.EndGetResponse(asynchronousResult);
               StreamReader counter = new
               StreamReader(trafficInforResponse.GetResponseStream());

               counter.ReadToEnd();
            }
         catch { };
      }), null);
   }
   catch { }
   });

   Thread solo = new
   Thread(tStart);
   solo.Start();
}


Nice and asynchronous.
These are the stats so far

No comments:

Post a Comment