private void Hit(NoteBehaviour note) { HitType type = CalculateHitType(transform, note.transform); Color color; switch (type) { case HitType.Miss: color = Color.grey; break; case HitType.Poor: color = Color.yellow; break; case HitType.Good: color = Color.green; break; case HitType.Perfect: color = Color.magenta; break; default: color = Color.black; break; } points = 50.0f * (int)type * POINTS_MULTIPLIER; scoreManager.AddScore(points); note.Hit(type.ToString(), color); CurrentStreak++; }
private static void Track(HitType type, string category, string action, string label, int? value = null) { if (string.IsNullOrEmpty(category)) throw new ArgumentNullException("category"); if (string.IsNullOrEmpty(action)) throw new ArgumentNullException("action"); var request = (HttpWebRequest)WebRequest.Create("http://www.google-analytics.com/collect"); request.Method = "POST"; request.KeepAlive = false; // the request body we want to send var postData = new Dictionary<string, string> { { "v", "1" }, { "tid", "UA-67700554-1" }, { "cid", "555" }, { "t", type.ToString() }, { "ec", category }, { "ea", action }, }; if (!string.IsNullOrEmpty(label)) { postData.Add("el", label); } if (value.HasValue) { postData.Add("ev", value.ToString()); } var postDataString = postData .Aggregate("", (data, next) => string.Format("{0}&{1}={2}", data, next.Key, HttpUtility.UrlEncode(next.Value))) .TrimEnd('&'); // set the Content-Length header to the correct value request.ContentLength = Encoding.UTF8.GetByteCount(postDataString); // write the request body to the request using (var writer = new StreamWriter(request.GetRequestStream())) { writer.Write(postDataString); } try { var webResponse = (HttpWebResponse)request.GetResponse(); if (webResponse.StatusCode != HttpStatusCode.OK) { throw new HttpException((int)webResponse.StatusCode, "Google Analytics tracking did not return OK 200"); } webResponse.Close(); } catch (Exception) { } }
private static String GeneratePayloadData(HitType hitType, String pageName = null, String screenName = null, String category = null, String action = null, String label = null, uint? value = null, SessionControl sessionControl = SessionControl.None) { if (String.IsNullOrEmpty(TrackConfig.TrackingID)) throw new ArgumentException("TrackingID can not be empty."); if (String.IsNullOrEmpty(TrackConfig.ClientID)) throw new ArgumentException("ClientID can not be empty."); String v = PROTOCOL_VERSION; String tid = TrackConfig.TrackingID; String cid = TrackConfig.ClientID; String t = hitType.ToString().ToLower(); String sr = TrackConfig.ScreenWidth != null && TrackConfig.ScreenHeight != null ? TrackConfig.ScreenWidth + "x" + TrackConfig.ScreenHeight : null; String dp = pageName; String cd = screenName; String ec = category; String ea = action; String el = label; String ev = value != null ? value.ToString() : null; String sc = sessionControl != SessionControl.None ? sessionControl.ToString().ToLower() : null; String uid = TrackConfig.UserID; String an = TrackConfig.ApplicationName; String aid = TrackConfig.ApplicationID; String av = TrackConfig.ApplicationVersion; var payload_data = new StringBuilder(); // Required Information payload_data.Append("v=" + v); payload_data.Append("&tid=" + tid); payload_data.Append("&cid=" + cid); payload_data.Append("&t=" + t); // Tracking Information if (dp != null) payload_data.Append("&dp=" + dp); if (cd != null) payload_data.Append("&cd=" + cd); if (ec != null) payload_data.Append("&ec=" + ec); if (ea != null) payload_data.Append("&ea=" + ea); if (el != null) payload_data.Append("&el=" + el); if (ev != null) payload_data.Append("&ev=" + ev); // Session Information if (sc != null) payload_data.Append("&sc=" + sc); // Opitional Information if (uid != null) payload_data.Append("&uid=" + uid); if (sr != null) payload_data.Append("&sr=" + sr); if (an != null) payload_data.Append("&an=" + an); if (aid != null) payload_data.Append("&aid=" + aid); //if (av != null) payload_data.Append("&av=" + av); return payload_data.ToString(); }
private async Task LogHit(string trackingId, string clientId, HitType hitType, string pagePath, string ipAddress, string userAgent) { if (string.IsNullOrEmpty(trackingId)) { throw new ArgumentNullException(nameof(trackingId)); } if (string.IsNullOrEmpty(clientId)) { throw new ArgumentNullException(nameof(clientId)); } if (string.IsNullOrEmpty(pagePath)) { throw new ArgumentNullException(nameof(pagePath)); } if (string.IsNullOrEmpty(ipAddress)) { throw new ArgumentNullException(nameof(ipAddress)); } var httpClient = HttpClientFactory.Create(); var request = new HttpRequestMessage(HttpMethod.Post, GA_URI); request.Headers.Add("User-Agent", userAgent); var payload = new Dictionary <string, string> { { "v", "1" }, { TRACKING_ID, trackingId }, { CLIENT_ID, clientId }, { HIT_TYPE, hitType.ToString().ToLower() }, { PAGE_PATH, pagePath }, { IP_ADDRESS, ipAddress } }; request.Content = new FormUrlEncodedContent(payload); var response = await httpClient.SendAsync(request); if (!response.IsSuccessStatusCode) { _telemetry.TrackTrace($"The Google Measurement Protocol API did not return 2xx. Tracking ID: {trackingId}, client ID: {clientId}, IP address: {ipAddress}, page path: {pagePath}.", SeverityLevel.Error); } else { _telemetry.TrackTrace($"GA hit was logged. Tracking ID: {trackingId}, client ID: {clientId}, IP address: {ipAddress}, page path: {pagePath}.", SeverityLevel.Information); } }
private static void TrackPageview(HitType type, string page) { if (string.IsNullOrEmpty(page)) { throw new ArgumentNullException(nameof(page)); } var postData = new Dictionary <string, string> { { "v", "1" }, { "tid", TRACKER_ID }, { "cid", UserId }, { "t", type.ToString() }, { "dl", page }, }; Track(postData); }
/// <summary> /// Sends a new analytic event to the server. /// </summary> /// <param name="hitType">The type of event we have</param> /// <param name="category">The category</param> /// <param name="action">The action key</param> /// <param name="label">the label on the action</param> /// <param name="value">The value of the action</param> public static void Send(Dictionary <string, string> postData, HitType hitType) { postData["t"] = hitType.ToString().ToLower(); // Hit Type postData["v"] = AnalyticsConstants.PROTOCOL_VERSION; // Protocol Version postData["tid"] = AnalyticsConstants.TRACKING_ID; // Tracking ID postData["ds"] = InternalEditorUtility.GetFullUnityVersion(); // DataSource postData["cid"] = GetClientID(); // Client ID postData["uid"] = GetUserID(); // User ID postData["av"] = WeaverSettings.VERSION; // Application Version postData["ul"] = CultureInfo.CurrentCulture.Name; // User Language postData["an"] = "Weaver"; // Application Name // Create our request UnityWebRequest www = UnityWebRequest.Post(AnalyticsConstants.URL, postData); // Send the even t www.SendWebRequest(); }
private Dictionary <string, string> BuildRequestData(HitType type, string username, string category, string action, string clientId, string label, int?value, string exceptionDescription, int?fatal) { var postData = new Dictionary <string, string> { { "v", "1" }, { "tid", TrackingId }, { "t", type.ToString() } }; if (!string.IsNullOrEmpty(username)) { postData.Add("uid", username); } postData.Add("cid", !string.IsNullOrEmpty(clientId) ? clientId : Guid.NewGuid().ToString()); if (!string.IsNullOrEmpty(label)) { postData.Add("el", label); } if (value.HasValue) { postData.Add("ev", value.ToString()); } if (!string.IsNullOrEmpty(category)) { postData.Add("ec", category); } if (!string.IsNullOrEmpty(action)) { postData.Add("ea", action); } if (!string.IsNullOrEmpty(exceptionDescription)) { postData.Add("exd", exceptionDescription); } if (fatal.HasValue) { postData.Add("exf", fatal.ToString()); } return(postData); }
private static void TrackEvent(HitType type, string category, string action, string label) { if (string.IsNullOrEmpty(category)) { throw new ArgumentNullException(nameof(category)); } if (string.IsNullOrEmpty(action)) { throw new ArgumentNullException(nameof(action)); } var postData = new Dictionary <string, string> { { "v", "1" }, { "tid", TRACKER_ID }, { "cid", UserId }, { "t", type.ToString() }, { "ec", category }, { "ea", action }, { "el", label }, }; Track(postData); }
private void SendTrack(HitType type, Hashtable hashtable) { Hashtable values = new Hashtable(); values.Add("v", API_VERSION); values.Add("tid", TrackingId); values.Add("cid", ClientId); values.Add("uid", UserId); values.Add("ds", AppName); // Data Source values.Add("an", AppName); // Application name values.Add("av", AppVersion); // Application name values.Add("t", type.ToString()); //Event type values.Add("sr", ScreenInfo.FullResolution); //Screen resolution Example: sr=800x600 values.Add("ua", OSVersionInfo.FullName()); //User Agent Override Example: Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14 foreach (DictionaryEntry item in hashtable) { values.Add(item.Key, item.Value); } string data = ""; foreach (var key in values.Keys) { if (data != "") { data += "&"; } if (values[key] != null) { data += key.ToString() + "=" + HttpUtility.UrlEncode(values[key].ToString()); } } RequestApi(data); }
private void Track(HitType type, string category, string action, string label, int?value = null) { Task.Run(() => { try { if (string.IsNullOrEmpty(category)) { return; } if (string.IsNullOrEmpty(action)) { return; } var request = (HttpWebRequest)WebRequest.Create("http://www.google-analytics.com/collect"); request.Method = "POST"; request.KeepAlive = false; request.Timeout = 1000; // the request body we want to send var postData = new Dictionary <string, string> { { "v", "1" }, { "tid", _trackingId }, { "cid", _userGuid }, { "uid", _userGuid }, { "t", type.ToString() }, { "ec", category }, { "ea", action }, { "an", _applicationName }, { "aid", _applicationId }, { "av", _applicationVersion }, }; if (!string.IsNullOrEmpty(label)) { postData.Add("el", label); } if (value.HasValue) { postData.Add("ev", value.ToString()); } var postDataString = postData .Aggregate("", (data, next) => string.Format("{0}&{1}={2}", data, next.Key, HttpUtility.UrlEncode(next.Value))) .TrimEnd('&'); // set the Content-Length header to the correct value request.ContentLength = Encoding.UTF8.GetByteCount(postDataString); // write the request body to the request using (var writer = new StreamWriter(request.GetRequestStream())) { writer.Write(postDataString); } using (var webResponse = (HttpWebResponse)request.GetResponse()) { if (webResponse.StatusCode != HttpStatusCode.OK) { Debug.Log("Google Analytics tracking did not return OK 200"); } webResponse.Close(); } } catch (Exception e) { Debug.Log(e.Message); } }); }
private static void Track(HitType type, string category, string action, string label, int?value = null) { if (string.IsNullOrEmpty(category)) { throw new ArgumentNullException("category"); } if (string.IsNullOrEmpty(action)) { throw new ArgumentNullException("action"); } var request = (HttpWebRequest)WebRequest.Create("http://www.google-analytics.com/collect"); request.Method = "POST"; // the request body we want to send var postData = new Dictionary <string, string> { { "v", "1" }, { "tid", Google.Key.tid }, { "cid", "555" }, { "t", type.ToString() }, { "ec", category }, { "ea", action }, }; if (!string.IsNullOrEmpty(label)) { postData.Add("el", label); } if (value.HasValue) { postData.Add("ev", value.ToString()); } var postDataString = postData .Aggregate("", (data, next) => string.Format("{0}&{1}={2}", data, next.Key, HttpUtility.UrlEncode(next.Value))) .TrimEnd('&'); // set the Content-Length header to the correct value request.ContentLength = Encoding.UTF8.GetByteCount(postDataString); // write the request body to the request using (var writer = new StreamWriter(request.GetRequestStream())) { writer.Write(postDataString); } try { var webResponse = (HttpWebResponse)request.GetResponse(); if (webResponse.StatusCode != HttpStatusCode.OK) { throw new HttpException((int)webResponse.StatusCode, "Google Analytics tracking did not return OK 200"); } } catch (Exception ex) { // do what you like here, we log to Elmah // ElmahLog.LogError(ex, "Google Analytics tracking failed"); } }
private void Track(HitType type, string category, string action, string label, int? value = null) { Task.Run(() => { try { if (string.IsNullOrEmpty(category)) return; if (string.IsNullOrEmpty(action)) return; var request = (HttpWebRequest) WebRequest.Create("http://www.google-analytics.com/collect"); request.Method = "POST"; request.KeepAlive = false; request.Timeout = 1000; // the request body we want to send var postData = new Dictionary<string, string> { {"v", "1"}, {"tid", _trackingId}, {"cid", _userGuid}, {"uid", _userGuid}, {"t", type.ToString()}, {"ec", category}, {"ea", action}, {"an", _applicationName}, {"aid", _applicationId}, {"av", _applicationVersion}, }; if (!string.IsNullOrEmpty(label)) { postData.Add("el", label); } if (value.HasValue) { postData.Add("ev", value.ToString()); } var postDataString = postData .Aggregate("", (data, next) => string.Format("{0}&{1}={2}", data, next.Key, HttpUtility.UrlEncode(next.Value))) .TrimEnd('&'); // set the Content-Length header to the correct value request.ContentLength = Encoding.UTF8.GetByteCount(postDataString); // write the request body to the request using (var writer = new StreamWriter(request.GetRequestStream())) { writer.Write(postDataString); } using (var webResponse = (HttpWebResponse) request.GetResponse()) { if (webResponse.StatusCode != HttpStatusCode.OK) { Debug.Log("Google Analytics tracking did not return OK 200"); } webResponse.Close(); } } catch (Exception e) { Debug.Log(e.Message); } }); }
private static void Track(HitType type, string category, string action, string label, int?value = null) { if (string.IsNullOrEmpty(category)) { throw new ArgumentNullException("category"); } if (string.IsNullOrEmpty(action)) { throw new ArgumentNullException("action"); } var request = (HttpWebRequest)WebRequest.Create("http://www.google-analytics.com/collect"); request.Method = "POST"; request.KeepAlive = false; var postData = new Dictionary <string, string> { { "v", "1" }, { "tid", trackingId }, { "cid", "555" }, { "t", type.ToString() }, { "ec", category }, { "ea", action }, }; if (!string.IsNullOrEmpty(label)) { postData.Add("el", label); } if (value.HasValue) { postData.Add("ev", value.ToString()); } var postDataString = postData .Aggregate("", (data, next) => string.Format("{0}&{1}={2}", data, next.Key, HttpUtility.UrlEncode(next.Value))) .TrimEnd('&'); request.ContentLength = Encoding.UTF8.GetByteCount(postDataString); using (var writer = new StreamWriter(request.GetRequestStream())) { writer.Write(postDataString); } try { var webResponse = (HttpWebResponse)request.GetResponse(); if (webResponse.StatusCode != HttpStatusCode.OK) { throw new HttpException((int)webResponse.StatusCode, "Google Analytics tracking did not return OK 200"); } webResponse.Close(); } catch (Exception ex) { Console.Out.WriteLine(ex.Message); } }
public void AppendData(string protocolToken, string val, string action, int maxSize, params HitType[] supportedHitTypes) { if (supportedHitTypes.Length > 0) { bool isActionSupprted = false; foreach (HitType h in supportedHitTypes) { if (h == currentHitType) { isActionSupprted = true; } } if (!isActionSupprted) { Debug.LogWarning("Google Analytics: " + action + " not supported for hit type " + currentHitType.ToString()); return; } } string data = EscapeString(val); builder.Append("&"); builder.Append(protocolToken); builder.Append("="); builder.Append(data); if (maxSize > 0) { CheckDataLength(action, data, maxSize); } }
//-------------------------------------- // HIT PROTOCOL //-------------------------------------- public void SetHitType(HitType hit) { AppendData("t", hit.ToString().ToLower()); }