Search code examples
c#winformsanalyticsweb-analyticsweb-statistics

Can 'Clicky Web Analytics' be used in a C# WinForms environment?


Can 'Clicky Web Analytics' be utilized in a C# WinForms environment?

The only thing I can spot is a HTML code snippet for websites.

They also accept HTTP requests, but I believe they are just for polling data, not for pushing new events/stats to Clicky.

I realize it is probably called 'Clicky Web Analytics' for a reason (i.e. only website/web app based stat tracking), but I could really use a C# solution right about now.


Solution

  • Here is how to track custom events from C# to your clicky site:

        private static void TrackStatWithClicky(string eventValue)
        {
            // Prepare HTTP request
            WebRequest request = WebRequest.Create
           (
               "http://in.getclicky.com/in.php?" +
               "site_id=" + ClickySiteID +  //click site id , found in preferences
               "&sitekey_admin=" + ClickySiteAdminKey + //clicky site admin key, found in preferences
               "&ip_address=" + GetLocalIPAddressString() + //ip address of the user - used for mapping action trails
               "&type=custom" +
               "&href=" + eventValue.Replace(" ", "_") + //string that contains whatever event you want to track/log
               "&title=APPNAME Action" +
               "&type=click"
           );
    
            request.Method = "GET";
    
            // Get response
            WebResponse response = request.GetResponse();
            response.Close();
        }
    
        public static string GetLocalIPAddressString()
        {
            if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
            {
                return "";
            }
    
            IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
    
            return host.AddressList.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork).ToString();
        }
    

    Some of the information here was usefull in figuring it out: https://clicky.com/help/custom/manual#internal