KISSMetrics .NET C# Wrapper Project

Recently one of the projects we worked on was an integration of data that was stored in a proprietary SQL Server database with the KISSMetrics business intelligence SAAS product.  A customer had evaluated the different business intelligence products and chose KISSMetrics over MixPanel and Google Analytics.  KISSMetrics is a powerful business intelligence system that provides a more customer centric view of events instead of the Google Analytics page view centric model.  The goal is to allow business owners to find out from a customer experience standpoint what is working, their churn rate, etc.  This is really a powerful tool for any SAAS company.

I looked at some of the different integration methods that KISSMetrics provides including a PHP library and an Amazon S3 integration, but decided calling the RESTful web service made the most sense.  For this project it made sense to write a wrapper class to abstract some of the details of the integration.  One example of this is KISSMetrics allows you to send historical data such as past sales, but expects the timestamp in UNIX epoch format.  The wrapper consists mainly of two functions, an add property function that allows you to add many additional properties that will get tagged with the event in KISSMetrics and Send that will send the event to KISSMetrics.  I decided it made sense for the wrapper class to inherit a generic dictionary class for the AddProperty function.  Also in order to do jQuery like chaining I return the wrapper so you can call the function multiple times in one line i.e. AddProperty(“property1”, “value1”).AddProperty(“property2”, “value2”).

Add Property Function

public KissApiWrapper AddProperty(string key, string value)
this.Add(key, value);
return this;

SendEvent Function

public void SendEvent(string eventName, string userName, DateTime? eventDate)
StringBuilder urlBuilder = new StringBuilder();
urlBuilder.Append(useSSL ? "https://" : "http://");
urlBuilder.AppendFormat("?_k={0}", apiKey);
urlBuilder.AppendFormat("&_n={0}", eventName);
urlBuilder.AppendFormat("&_d={0}", eventDate.HasValue ? "1" : "0");
urlBuilder.AppendFormat("&_p={0}", userName);
if (eventDate.HasValue)
urlBuilder.AppendFormat("&_t={0}", ConvertToTimestamp(eventDate.Value));

foreach (string key in this.Keys)
urlBuilder.AppendFormat("&{0}={1}", System.Web.HttpUtility.HtmlEncode(key), System.Web.HttpUtility.HtmlEncode(this[key]));



Below is a full link to the code. If you have any additional questions about integrating with KISSMetrics or would like the full class for your personal use, please feel free to Contact Us now.