//private WoopraTracker() //{ // throw new NotImplementedException("Not supported yet."); //} public void Track(WoopraVisitor visitor, WoopraEvent woopraEvent) { HttpRequest(woopraEvent, visitor); }
private void HttpRequest(WoopraEvent woopraEvent, WoopraVisitor visitor) { try { var url = new StringBuilder(); url.Append(((_httpsEnable) ? "https" : "http") + "://www.woopra.com/track/"); // TODO: Warning!!!, inline IF is not supported ? // Identify or Track //Identify or Track url.Append(woopraEvent == null ? "identify/" : "ce/"); // Request Options url.Append("?host=").Append(HttpUtility.UrlEncode(domain, Encoding.UTF8)); url.Append("&app=").Append(SDK_ID); url.Append("&cookie=").Append(HttpUtility.UrlEncode(visitor.GetCookieValue(), Encoding.UTF8)); url.Append("&timeout=").Append(_idleTimeout); if (!visitor.GetIpAddress().Equals("")) { url.Append("&ip=").Append(HttpUtility.UrlEncode(visitor.GetIpAddress(), Encoding.UTF8)); } if (woopraEvent != null && woopraEvent.Timestamp > 0) { url.Append("×tamp=").Append(woopraEvent.Timestamp); } // visitor Props foreach (var item in visitor.properties) { url.Append("&cv_") .Append(HttpUtility.UrlEncode(item.Key, Encoding.UTF8)) .Append("=") .Append(HttpUtility.UrlEncode(item.Value.ToString(), Encoding.UTF8)); } // event Props if (woopraEvent != null) { url.Append("&event=").Append(HttpUtility.UrlEncode(woopraEvent.Name, Encoding.UTF8)); foreach (var item in woopraEvent.properties) { url.Append("&ce_") .Append(HttpUtility.UrlEncode(item.Key, Encoding.UTF8)) .Append("=") .Append(HttpUtility.UrlEncode(item.Value.ToString(), Encoding.UTF8)); } } //Here is a new thread using (var client = new WebClient()) { if ((visitor.GetUserAgent().Equals("") == false)) { client.Headers.Add("User-Agent", visitor.GetUserAgent()); } if (_httpAuthEnable) { // create credentials, base64 encode of username:password string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(_httpAuthUser + ":" + _httpAuthPassword)); // Inject this string as the Authorization header client.Headers[HttpRequestHeader.Authorization] = string.Format("Basic {0}", credentials); } client.DownloadStringAsync(new Uri(url.ToString())); //client.OpenRead(url.ToString()); } } //catch (JSONException e) { // // TODO Auto-generated catch block // e.printStackTrace(); //} catch (UriFormatException e) { // TODO Auto-generated catch block Trace.WriteLine(e.Message); } catch (IOException e) { // TODO Auto-generated catch block //e.printStackTrace(); Trace.WriteLine(e.Message); } catch (Exception e) { // TODO Auto-generated catch block //e.printStackTrace(); Trace.WriteLine(e.Message); } }