title: Cause Google Analytics log from non-web application (eg. via WebClient)
body: <p>I'd like to gather some stats about the usage of my application, and since I already have web stats in Google Analytics, I thought it'd be cool if I could send a request from the app that causes a hit in Analytics, eg.</p>
  
  <p>/app/v1.0/debug</p>
  
  <p>This would allow me to see how often my app is starting up (or whatever).</p>
  
  <p>I had a look online and found some examples of people doing similar things (some to workaroudn Javascript being disabled, and others doing the same as me), but none in C#. I translated the code over as best as I could, but I've called it a few times a couple of days ago, and nothing showed up in the logs :(</p>
  
  <pre><code>// Send a hit to Google Analytics so we can track which versions are being used
  Random rnd = new Random();
  int cookie = rnd.Next(10000000, 99999999);
  string statsRequest = "http://www.google-analytics.com/__utm.gif" +
      "?utmwv=4.3" +
      "&amp;utmn=" + rnd.Next(10000) + // Used only to stop browser caching
      "&amp;utmhn=myhost.com" + // Hostname
      //"&amp;utmhid=&lt;random#&gt;" +
      "&amp;utmr=-" + // Referer
      "&amp;utmp=/app/v0.4/DEBUG/Test" + // Requested page
      "&amp;utmac=UA-123456-7" + // Google Analytics ID
      "&amp;utmcc=__utma%3D" + cookie + "3B%2B__utmz%3D" + cookie + "%3B";
  
  using (var client = new WebClient())
  {
      client.DownloadData(statsRequest);
  }
  </code></pre>
  
  <p>Does anyone know what to do to make this work? It would be even better if I could store the cookie in some way, so that people are considered "returning visitors" when they run the app multiple times, but that's less important.</p>