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.
/app/v1.0/debug
This would allow me to see how often my app is starting up (or whatever).
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 :(
// 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" +
"&utmn=" + rnd.Next(10000) + // Used only to stop browser caching
"&utmhn=myhost.com" + // Hostname
//"&utmhid=<random#>" +
"&utmr=-" + // Referer
"&utmp=/app/v0.4/DEBUG/Test" + // Requested page
"&utmac=UA-123456-7" + // Google Analytics ID
"&utmcc=__utma%3D" + cookie + "3B%2B__utmz%3D" + cookie + "%3B";
using (var client = new WebClient())
{
client.DownloadData(statsRequest);
}
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.