public static void SendEvent(string eventID) { GA_Submit.CategoryType category = GA_Submit.CategoryType.GA_Event; List <GA_Submit.Item> queue = new List <GA_Submit.Item>(); Hashtable parameters = new Hashtable() { { GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.EventID], eventID }, { GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.Level], "Unity Editor" }, { GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.UserID], _userID }, { GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.SessionID], _sessionID }, { GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.Build], GA_Settings.VERSION } }; queue.Add(new GA_Submit.Item() { AddTime = 0, Count = 1, Type = category, Parameters = parameters }); Dictionary <GA_Submit.CategoryType, List <GA_Submit.Item> > dict = new Dictionary <GA_Submit.CategoryType, List <GA_Submit.Item> >(); dict.Add(category, queue); WWW www = GetEventWWW(category, parameters); GA_ContinuationManager.StartCoroutine(GA_Submit.SendWWW(www, Submitted, SubmitError, true, "", "", queue), () => www.isDone); }
/// <summary> /// Archives json data so it can be sent at a later time, when an internet connection is available. /// </summary> /// <param name='json'> /// The json data as a string /// </param> /// <param name='serviceType'> /// The category type /// </param> public void ArchiveData(string json, GA_Submit.CategoryType serviceType) { #if !UNITY_WEBPLAYER && !UNITY_NACL && !UNITY_FLASH StreamWriter fileWriter = null; string fileName = Application.persistentDataPath + "/" + FILE_NAME; if (File.Exists(fileName)) { if (new FileInfo(fileName).Length + System.Text.ASCIIEncoding.Unicode.GetByteCount(json) <= GA.SettingsGA.ArchiveMaxFileSize) { fileWriter = File.AppendText(fileName); } } else if (System.Text.ASCIIEncoding.Unicode.GetByteCount(json) <= GA.SettingsGA.ArchiveMaxFileSize) { fileWriter = File.CreateText(fileName); } if (fileWriter != null) { fileWriter.WriteLine(serviceType + " " + json); fileWriter.Close(); } #endif }
/// <summary> /// Gets a universally unique ID to represent the user. User ID should be device specific to allow tracking across different games on the same device: /// -- Android uses deviceUniqueIdentifier. /// -- iOS/PC/Mac uses the first MAC addresses available. /// -- Webplayer uses deviceUniqueIdentifier. /// Note: The unique user ID is based on the ODIN specifications. See http://code.google.com/p/odinmobile/ for more information on ODIN. /// </summary> /// <returns> /// The generated UUID <see cref="System.String"/> /// </returns> public static string GetUserUUID() { #if UNITY_IPHONE && !UNITY_EDITOR string uid = GA.SettingsGA.GetUniqueIDiOS(); if (uid == null) { return(""); } else if (uid != "OLD") { if (uid.StartsWith("VENDOR-")) { return(uid.Remove(0, 7)); } else { return(uid); } } #endif #if UNITY_ANDROID && !UNITY_EDITOR string uid = GA.SettingsGA.GetAdvertisingIDAndroid(); if (!string.IsNullOrEmpty(uid)) { return(uid); } #endif #if UNITY_WEBPLAYER || UNITY_NACL || UNITY_WP8 || UNITY_METRO || UNITY_PS3 return(SystemInfo.deviceUniqueIdentifier); #elif !UNITY_FLASH try { NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces(); string mac = ""; foreach (NetworkInterface adapter in nics) { PhysicalAddress address = adapter.GetPhysicalAddress(); if (address.ToString() != "" && mac == "") { mac = GA_Submit.CreateSha1Hash(address.ToString()); } } return(mac); } catch { return(SystemInfo.deviceUniqueIdentifier); } #else return(GetSessionUUID()); #endif }
private static WWW GetEventWWW(GA_Submit.CategoryType category, Hashtable parameters) { string url = GA_Submit.GetURL(GA_Submit.Categories[category], _publicTestKey); string json = GA_Submit.DictToJson(new List <Hashtable>() { parameters }); string jsonHash = GA_Submit.CreateMD5Hash(json + _privateTestKey); return(GA_Submit.CreateSubmitWWW(url, json, jsonHash)); }
public WWW RequestGameInfo(SubmitSuccessHandler successEvent, SubmitErrorHandler errorEvent) { if (string.IsNullOrEmpty(GA.SettingsGA.GameKey)) { GA.LogWarning("Game key not set - please setup your Game key in GA_Settings, under the Basic tab"); return(null); } if (string.IsNullOrEmpty(GA.SettingsGA.ApiKey)) { GA.LogWarning("API key not set - please setup your API key in GA_Settings, under the Advanced tab"); return(null); } string game_key = GA.SettingsGA.GameKey; string requestInfo = "game_key=" + game_key + "&keys=area%7Cevent_id%7Cbuild"; requestInfo = requestInfo.Replace(" ", "%20"); //Get the url with the request type string url = GetURL(Requests[RequestType.GA_GetHeatmapGameInfo]); url += "/?" + requestInfo; WWW www = null; #if UNITY_FLASH //Set the authorization header to contain an MD5 hash of the JSON array string + the private key Hashtable headers = new Hashtable(); headers.Add("Authorization", GA_Submit.CreateMD5Hash(requestInfo + GA.SettingsGA.ApiKey)); //Try to send the data www = new WWW(url, new byte[] { 0 }, headers); #else //Set the authorization header to contain an MD5 hash of the JSON array string + the private key #if UNITY_4_3 || UNITY_4_2 || UNITY_4_1 || UNITY_4_0_1 || UNITY_4_0 Hashtable headers = new Hashtable(); #else Dictionary <string, string> headers = new Dictionary <string, string>(); #endif headers.Add("Authorization", GA_Submit.CreateMD5Hash(requestInfo + GA.SettingsGA.ApiKey)); //Try to send the data www = new WWW(url, new byte[] { 0 }, headers); #endif GA.RunCoroutine(Request(www, RequestType.GA_GetHeatmapGameInfo, successEvent, errorEvent), () => www.isDone); return(www); }
public static void SendUserEvent() { GA_Submit.CategoryType category = GA_Submit.CategoryType.GA_User; string os = ""; string[] osSplit = SystemInfo.operatingSystem.Split(' '); if (osSplit.Length > 0) { os = osSplit[0]; } #if UNITY_IPHONE bool idfa = CheckIDFA(); #endif List <GA_Submit.Item> queue = new List <GA_Submit.Item>(); Hashtable parameters = new Hashtable() { { GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.Platform], GA_GenericInfo.GetSystem() }, { GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.Device], SystemInfo.deviceModel }, { GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.Os], os }, { GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.OsVersion], SystemInfo.operatingSystem }, { GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.Sdk], "GA Unity SDK " + GA_Settings.VERSION }, { GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.InstallPublisher], "UnityVersion:" + UnityEditorInternal.InternalEditorUtility.GetFullUnityVersion() }, #if UNITY_IPHONE { GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.InstallSite], "IDFA:" + idfa.ToString() }, { GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.InstallCampaign], "iAD:" + EditorPrefs.GetBool("GA_IAD" + "-" + Application.dataPath, GA_Settings.IAD_DEFAULT) }, #endif #if UNITY_IPHONE || UNITY_ANDROID { GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.InstallAdgroup], "Chartboost:" + EditorPrefs.GetBool("GA_CB" + "-" + Application.dataPath, GA_Settings.CB_DEFAULT) }, #endif { GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.UserID], _userID }, { GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.SessionID], _sessionID }, { GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.Build], GA_Settings.VERSION } }; queue.Add(new GA_Submit.Item() { AddTime = 0, Count = 1, Type = category, Parameters = parameters }); Dictionary <GA_Submit.CategoryType, List <GA_Submit.Item> > dict = new Dictionary <GA_Submit.CategoryType, List <GA_Submit.Item> >(); dict.Add(category, queue); WWW www = GetEventWWW(category, parameters); GA_ContinuationManager.StartCoroutine(GA_Submit.SendWWW(www, Submitted, SubmitError, true, "", "", queue), () => www.isDone); }
public WWW RequestHeatmapData(List <string> events, string area, string build, DateTime?startDate, DateTime?endDate, SubmitSuccessHandler successEvent, SubmitErrorHandler errorEvent) { string game_key = GA.SettingsGA.GameKey; string event_ids = ""; for (int i = 0; i < events.Count; i++) { if (i == events.Count - 1) { event_ids += events[i]; } else { event_ids += events[i] + "|"; } } string requestInfo = "game_key=" + game_key + "&event_ids=" + event_ids + "&area=" + area; if (!build.Equals("")) { requestInfo += "&build=" + build; } requestInfo = requestInfo.Replace(" ", "%20"); if (startDate.HasValue && endDate.HasValue) { DateTime startDT = new DateTime(startDate.Value.Year, startDate.Value.Month, startDate.Value.Day, 0, 0, 0); DateTime endDT = new DateTime(endDate.Value.Year, endDate.Value.Month, endDate.Value.Day, 0, 0, 0); requestInfo += "&start_ts=" + DateTimeToUnixTimestamp(startDT) + "&end_ts=" + DateTimeToUnixTimestamp(endDT); } //Get the url with the request type string url = GetURL(Requests[RequestType.GA_GetHeatmapData]); url += "/?" + requestInfo; WWW www = null; #if UNITY_FLASH //Set the authorization header to contain an MD5 hash of the JSON array string + the private key Hashtable headers = new Hashtable(); headers.Add("Authorization", GA_Submit.CreateMD5Hash(requestInfo + GA.SettingsGA.ApiKey)); //Try to send the data www = new WWW(url, new byte[] { 0 }, headers); #else //Set the authorization header to contain an MD5 hash of the JSON array string + the private key #if UNITY_4_3 || UNITY_4_2 || UNITY_4_1 || UNITY_4_0_1 || UNITY_4_0 Hashtable headers = new Hashtable(); #else Dictionary <string, string> headers = new Dictionary <string, string>(); #endif headers.Add("Authorization", GA_Submit.CreateMD5Hash(requestInfo + GA.SettingsGA.ApiKey)); //Try to send the data www = new WWW(url, new byte[] { 0 }, headers); #endif GA.RunCoroutine(Request(www, RequestType.GA_GetHeatmapData, successEvent, errorEvent), () => www.isDone); return(www); }
private void DeleteMeshes() { _loaded = false; if (meshSelected == null) { return; } for (int i = 0; i < meshSelected.Length; i++) { if (meshSelected[i]) { WWWForm form = new WWWForm(); form.AddField("gamekey", GA.SettingsGA.GameKey); form.AddField("authorization", GA_Submit.CreateMD5Hash(GA.SettingsGA.GameKey + meshNames[i] + ".unity3d" + GA.SettingsGA.SecretKey)); form.AddField("meshname", meshNames[i] + ".unity3d"); WWW w = new WWW("https://go.gameanalytics.com/api/heatmap/mesh/delete", form); while (!w.isDone) { } if (w.error != null) { Debug.LogWarning("Failed to delete mesh: " + meshNames[i]); } else { Hashtable data = (Hashtable)GA_MiniJSON.JsonDecode(w.text); ArrayList errorArray = data["errors"] as ArrayList; if (errorArray.Count > 0) { foreach (Hashtable ht in errorArray) { string msg = (string)ht["message"]; if (msg.Equals("404")) { Debug.LogWarning("Game key or mesh not found! Have you input the correct game key in GA_Settings?"); } else if (msg.Equals("401")) { Debug.LogWarning("Authorization failed! Have you input the correct secret key in GA_Settings?"); } else if (msg.Equals("400")) { Debug.LogWarning("Failed to delete mesh."); } else if (msg.Equals("503")) { Debug.LogWarning("Service unavailable, please try again later!"); } } } else { Debug.Log("Deleted mesh: " + meshNames[i]); } } } } UpdateMeshList(); }
public void UpdateMeshList() { WWWForm form = new WWWForm(); form.AddField("gamekey", GA.SettingsGA.GameKey); form.AddField("authorization", GA_Submit.CreateMD5Hash(GA.SettingsGA.GameKey + GA.SettingsGA.SecretKey)); WWW w = new WWW("https://go.gameanalytics.com/api/heatmap/meshes", form); while (!w.isDone) { } if (w.error != null) { Debug.LogWarning("Failed to load mesh names " + w.error); } else { try { Hashtable data = (Hashtable)GA_MiniJSON.JsonDecode(w.text); ArrayList errorArray = data["errors"] as ArrayList; ArrayList meshArray = data["results"] as ArrayList; if (errorArray.Count > 0 || meshArray.Count == 0) { foreach (Hashtable ht in errorArray) { string msg = (string)ht["message"]; if (msg.Equals("404")) { Debug.LogWarning("Game key not found! Have you input the correct game key in GA_Settings?"); } else if (msg.Equals("401")) { Debug.LogWarning("Authorization failed! Have you input the correct secret key in GA_Settings?"); } else if (msg.Equals("400")) { Debug.LogWarning("Failed to load meshes."); } else if (msg.Equals("503")) { Debug.LogWarning("Service unavailable, please try again later!"); } } _error = true; } else { meshNames = new List <string>(); meshSizes = new List <string>(); foreach (Hashtable ht in meshArray) { meshNames.Add(((string)ht["name"]).Replace(".unity3d", "")); meshSizes.Add(((string)ht["size"])); } meshSelected = new bool[meshNames.Count]; } } catch { _error = true; } _loaded = true; } }
/// <summary> /// Checks the internet connectivity, and sets INTERNETCONNECTIVITY /// </summary> public IEnumerator CheckInternetConnectivity(bool startQueue) { // Application.internetReachability returns the type of Internet reachability currently possible on the device, but does not check if the there is an actual route to the network. So we can check this instantly. if (Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork && !GA.SettingsGA.AllowRoaming) { InternetConnectivity = false; } else { //Try to ping the server WWW www = new WWW(GA_Submit.GetBaseURL(true) + "/ping"); //Wait for response yield return(www); try { if (GA_Submit.CheckServerReply(www)) { InternetConnectivity = true; } else if (!string.IsNullOrEmpty(www.error)) { InternetConnectivity = false; } else { //Get the JSON object from the response Hashtable returnParam = (Hashtable)GA_MiniJSON.JsonDecode(www.text); //If the response contains the key "status" with the value "ok" we know that we are connected if (returnParam != null && returnParam.ContainsKey("status") && returnParam["status"].ToString().Equals("ok")) { InternetConnectivity = true; } else { InternetConnectivity = false; } } } catch { InternetConnectivity = false; } } if (startQueue) { if (InternetConnectivity) { GA.Log("GA has confirmed connection to the server.."); } else { GA.Log("GA has no connection to the server.."); } //Try to add additional IDs if (AddUniqueIDs()) { #if UNITY_EDITOR //Start the submit queue for sending messages to the server GA.RunCoroutine(GA_Queue.SubmitQueue()); GA.Log("GameAnalytics: Submission queue started."); //GameObject gaTracking = new GameObject("GA_Tracking"); //gaTracking.AddComponent<GA_Tracking>(); #else while (GA.SettingsGA.CustomUserID && GA.API.GenericInfo.UserID == string.Empty) { yield return(new WaitForSeconds(5f)); } GA_Queue.ForceSubmit(); GameObject fbGameObject = new GameObject("GA_FacebookSDK"); fbGameObject.AddComponent <GA_FacebookSDK>(); #endif } else { GA.LogWarning("GA failed to add unique IDs and will not send any data. If you are using iOS or Android please see the readme file in the iOS/Android folder in the GameAnalytics/Plugins directory."); } } }
private static WWW GetEventWWW(GA_Submit.CategoryType category, Hashtable parameters) { string url = GA_Submit.GetURL(GA_Submit.Categories[category], _publicTestKey); string json = GA_Submit.DictToJson(new List<Hashtable>() { parameters }); string jsonHash = GA_Submit.CreateMD5Hash(json + _privateTestKey); return GA_Submit.CreateSubmitWWW(url, json, jsonHash); }
static void UploadAssetBunble(string path, string fileName) { byte[] meshData = File.ReadAllBytes(path); if (!fileName.EndsWith(".unity3d")) { fileName = fileName + ".unity3d"; } WWWForm form = new WWWForm(); form.AddField("gamekey", GA.SettingsGA.GameKey); form.AddField("authorization", GA_Submit.CreateMD5Hash(GA.SettingsGA.GameKey + fileName + GA.SettingsGA.SecretKey)); form.AddBinaryData("mesh", meshData, fileName, "application/vnd.unity"); WWW w = new WWW("https://go.gameanalytics.com/api/heatmap/mesh/upload", form); while (!w.isDone) { EditorUtility.DisplayProgressBar("Uploading static mesh. Please wait...", "Might take a while", w.progress); } if (w.error != null) { Debug.LogWarning("Mesh Upload Error: " + w.error); } else { Hashtable data = (Hashtable)GA_MiniJSON.JsonDecode(w.text); ArrayList errorArray = data["errors"] as ArrayList; if (errorArray.Count > 0) { foreach (Hashtable ht in errorArray) { string msg = (string)ht["message"]; if (msg.Equals("404")) { Debug.LogWarning("Game not found! Have you input the correct game key in GA_Settings?"); } else if (msg.Equals("401")) { Debug.LogWarning("Authorization failed! Have you input the correct secret key in GA_Settings?"); } else if (msg.Equals("400")) { Debug.LogWarning("Failed to upload mesh."); } else if (msg.Equals("503")) { Debug.LogWarning("Service unavailable, please try again later!"); } else if (msg.Equals("409")) { Debug.LogWarning("Mesh already exists! please try with a different name, or delete the existing mesh through the GameAnalytics > Delete AssetBundle Menu."); } } } else { Debug.Log("Mesh Upload: Completed with no errors."); } } if (File.Exists(path)) { Debug.Log("Deleting local asset bundle file after upload"); File.Delete(path); } }