| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using DCL; |
| | 5 | | using Newtonsoft.Json; |
| | 6 | | using UnityEngine; |
| | 7 | |
|
| | 8 | | /// <summary> |
| | 9 | | /// This class include all the analytics that we are tracking for builder-in-world, if you want to add a new one |
| | 10 | | /// Please do it inside this class and call the SendEditorEvent method to include all the default info |
| | 11 | | /// </summary> |
| | 12 | | public static class BIWAnalytics |
| | 13 | | { |
| | 14 | | #region BuilderPanel |
| | 15 | |
|
| | 16 | | public static void PlayerOpenPanel(int landsOwned, int landsOperator) |
| | 17 | | { |
| 4 | 18 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 4 | 19 | | events.Add("Lands Owned", landsOwned.ToString()); |
| 4 | 20 | | events.Add("Lands Operator", landsOperator.ToString()); |
| 4 | 21 | | SendEvent("player_open_panel", events); |
| 4 | 22 | | } |
| | 23 | |
|
| | 24 | | public static void PlayerClosesPanel(int landsOwned, int landsOperator) |
| | 25 | | { |
| 1 | 26 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 1 | 27 | | events.Add("Lands Owned", landsOwned.ToString()); |
| 1 | 28 | | events.Add("Lands Operator", landsOperator.ToString()); |
| 1 | 29 | | SendEvent("player_closes_panel", events); |
| 1 | 30 | | } |
| | 31 | |
|
| | 32 | | /// <summary> |
| | 33 | | /// When the user interact with the panel to go to a land or a scene |
| | 34 | | /// </summary> |
| | 35 | | /// <param name="source">From where it is comming: scenes, lands, projects</param> |
| | 36 | | /// <param name="mode">The button he has been pressed: Editor, Jump in</param> |
| | 37 | | /// <param name="coords">Coords of the land where the scene is deployed or land coords</param> |
| | 38 | | /// <param name="ownership">It is owner or operator</param> |
| | 39 | | public static void PlayerJumpOrEdit(string source, string mode, Vector2 coords, string ownership) |
| | 40 | | { |
| 0 | 41 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 0 | 42 | | events.Add("source", source); |
| 0 | 43 | | events.Add("mode", mode); |
| 0 | 44 | | events.Add("coords", coords.ToString()); |
| 0 | 45 | | events.Add("ownership", ownership); |
| 0 | 46 | | SendEvent("player_jump_or_edit", events); |
| 0 | 47 | | } |
| | 48 | |
|
| | 49 | | /// <summary> |
| | 50 | | /// When the user unpublished a scene |
| | 51 | | /// </summary> |
| | 52 | | /// <param name="type">What type of scene is unpublished: Builder, Builder-in-world, SDK</param> |
| | 53 | | /// <param name="coords">Coords of the land where the scene is deployed </param> |
| | 54 | | public static void PlayerUnpublishScene(string type, Vector2Int coords) |
| | 55 | | { |
| 2 | 56 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 2 | 57 | | events.Add("type", type); |
| 2 | 58 | | events.Add("coords", coords.ToString()); |
| 2 | 59 | | SendEvent("player_unpublish_scene", events); |
| 2 | 60 | | } |
| | 61 | |
|
| | 62 | | #endregion |
| | 63 | |
|
| | 64 | | #region BuilderEditor |
| | 65 | |
|
| | 66 | | /// <summary> |
| | 67 | | /// Everytime we start the flow of the editor |
| | 68 | | /// </summary> |
| | 69 | | /// <param name="source">It comes from the shortcut or from BuilderPanel</param> |
| | 70 | | public static void StartEditorFlow(string source) |
| | 71 | | { |
| 1 | 72 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 1 | 73 | | events.Add("source", source); |
| 1 | 74 | | SendEditorEvent("start_editor_flow", events); |
| 1 | 75 | | } |
| | 76 | |
|
| | 77 | | public static void EnterEditor(float loadingTime) |
| | 78 | | { |
| 2 | 79 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 2 | 80 | | events.Add("loading_time", loadingTime.ToString()); |
| 2 | 81 | | SendEditorEvent("enter_editor", events); |
| 2 | 82 | | } |
| | 83 | |
|
| | 84 | | public static void ExitEditor(float timeInvestedInTheEditor) |
| | 85 | | { |
| 1 | 86 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 1 | 87 | | events.Add("time_in_the_editor", timeInvestedInTheEditor.ToString()); |
| 1 | 88 | | SendEditorEvent("exit_editor", events); |
| 1 | 89 | | } |
| | 90 | |
|
| | 91 | | public static void StartScenePublish(SceneMetricsModel sceneLimits) |
| | 92 | | { |
| 0 | 93 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 0 | 94 | | events.Add("scene_limits", JsonConvert.SerializeObject(ConvertSceneMetricsModelToDictionary(sceneLimits))); |
| 0 | 95 | | SendEditorEvent("start_publish_of_the_scene", events); |
| 0 | 96 | | } |
| | 97 | |
|
| | 98 | | public static void EndScenePublish(SceneMetricsModel sceneLimits, string successOrError, float publicationTime) |
| | 99 | | { |
| 0 | 100 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 0 | 101 | | events.Add("success", successOrError); |
| 0 | 102 | | events.Add("publication_time", publicationTime.ToString()); |
| 0 | 103 | | events.Add("scene_limits", JsonConvert.SerializeObject(ConvertSceneMetricsModelToDictionary(sceneLimits))); |
| 0 | 104 | | SendEditorEvent("end_scene_publish", events); |
| 0 | 105 | | } |
| | 106 | |
|
| | 107 | | public static void SceneLimitsExceeded(SceneMetricsModel sceneUsage, SceneMetricsModel sceneLimits) |
| | 108 | | { |
| 0 | 109 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 0 | 110 | | events.Add("limits_passed", GetLimitsPassedArray(sceneUsage, sceneLimits)); |
| 0 | 111 | | events.Add("scene_limits", JsonConvert.SerializeObject(ConvertSceneMetricsModelToDictionary(sceneLimits))); |
| 0 | 112 | | events.Add("current_usage", JsonConvert.SerializeObject(ConvertSceneMetricsModelToDictionary(sceneUsage))); |
| 0 | 113 | | SendEditorEvent("scene_limits_exceeded", events); |
| 0 | 114 | | } |
| | 115 | |
|
| | 116 | | /// <summary> |
| | 117 | | /// When a new item is placed from the catalog |
| | 118 | | /// </summary> |
| | 119 | | /// <param name="catalogItem">The item that has been added</param> |
| | 120 | | /// <param name="source">It has been added from Categories, Asset pack, Favorites or Quick Access</param> |
| | 121 | | public static void NewObjectPlaced(CatalogItem catalogItem, string source) |
| | 122 | | { |
| 0 | 123 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 0 | 124 | | events.Add("name", catalogItem.name); |
| 0 | 125 | | events.Add("assetPack", catalogItem.assetPackName); |
| 0 | 126 | | events.Add("category", catalogItem.category); |
| 0 | 127 | | events.Add("category_name", catalogItem.categoryName); |
| 0 | 128 | | events.Add("source", source); |
| 0 | 129 | | events.Add("type", catalogItem.itemType.ToString()); |
| 0 | 130 | | SendEditorEvent("new_object_placed", events); |
| 0 | 131 | | } |
| | 132 | |
|
| | 133 | | /// <summary> |
| | 134 | | /// This will send all the items placed in a period of time in a single message |
| | 135 | | /// </summary> |
| | 136 | | /// <param name="catalogItem">The item that has been added</param> |
| | 137 | | /// <param name="source">It has been added from Categories, Asset pack, Favorites or Quick Access</param> |
| | 138 | | public static void NewObjectPlacedChunk(List<KeyValuePair<CatalogItem, string>> itemsToSendAnalytics) |
| | 139 | | { |
| 0 | 140 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 0 | 141 | | List<string> items = new List<string>(); |
| 0 | 142 | | foreach (var catalogItem in itemsToSendAnalytics) |
| | 143 | | { |
| 0 | 144 | | if (events.ContainsKey(catalogItem.Key.name)) |
| | 145 | | continue; |
| | 146 | |
|
| 0 | 147 | | Dictionary<string, string> item = new Dictionary<string, string>(); |
| 0 | 148 | | int amountOfItems = 0; |
| 0 | 149 | | foreach (var itemsToCompare in itemsToSendAnalytics) |
| | 150 | | { |
| 0 | 151 | | if (catalogItem.Key == itemsToCompare.Key) |
| 0 | 152 | | amountOfItems++; |
| | 153 | | } |
| | 154 | |
|
| 0 | 155 | | item.Add("name", catalogItem.Key.name); |
| 0 | 156 | | item.Add("amount", amountOfItems.ToString()); |
| 0 | 157 | | item.Add("assetPack", catalogItem.Key.assetPackName); |
| 0 | 158 | | item.Add("category", catalogItem.Key.category); |
| 0 | 159 | | item.Add("category_name", catalogItem.Key.categoryName); |
| 0 | 160 | | item.Add("source", catalogItem.Value); |
| 0 | 161 | | item.Add("type", catalogItem.Key.ToString()); |
| | 162 | |
|
| 0 | 163 | | items.Add( JsonConvert.SerializeObject(item)); |
| | 164 | | } |
| | 165 | |
|
| 0 | 166 | | events.Add("items", JsonConvert.SerializeObject(items)); |
| 0 | 167 | | SendEditorEvent("new_object_placed", events); |
| 0 | 168 | | } |
| | 169 | |
|
| | 170 | | public static void QuickAccessAssigned(CatalogItem catalogItem, string source) |
| | 171 | | { |
| 0 | 172 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 0 | 173 | | events.Add("name", catalogItem.name); |
| 0 | 174 | | events.Add("assetPack", catalogItem.assetPackName); |
| 0 | 175 | | events.Add("category", catalogItem.category); |
| 0 | 176 | | events.Add("category Name", catalogItem.categoryName); |
| 0 | 177 | | events.Add("source", source); |
| 0 | 178 | | events.Add("type", catalogItem.itemType.ToString()); |
| 0 | 179 | | SendEditorEvent("quick_access_assigned", events); |
| 0 | 180 | | } |
| | 181 | |
|
| | 182 | | public static void FavoriteAdded(CatalogItem catalogItem) |
| | 183 | | { |
| 1 | 184 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 1 | 185 | | events.Add("name", catalogItem.name); |
| 1 | 186 | | events.Add("assetPack", catalogItem.assetPackName); |
| 1 | 187 | | events.Add("category", catalogItem.category); |
| 1 | 188 | | events.Add("category Name", catalogItem.categoryName); |
| 1 | 189 | | events.Add("type", catalogItem.itemType.ToString()); |
| 1 | 190 | | SendEditorEvent("favorite_added", events); |
| 1 | 191 | | } |
| | 192 | |
|
| | 193 | | public static void CatalogItemSearched(string searchQuery, int resultAmount) |
| | 194 | | { |
| 0 | 195 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 0 | 196 | | events.Add("search_query", searchQuery); |
| 0 | 197 | | events.Add("result_amount", resultAmount.ToString()); |
| 0 | 198 | | SendEditorEvent("catalog_item_searched", events); |
| 0 | 199 | | } |
| | 200 | |
|
| | 201 | | private static Dictionary<string, string> ConvertSceneMetricsModelToDictionary(SceneMetricsModel sceneLimits) |
| | 202 | | { |
| 0 | 203 | | Dictionary<string, string> sceneLimitsDictionary = new Dictionary<string, string>(); |
| 0 | 204 | | sceneLimitsDictionary.Add("meshes", sceneLimits.meshes.ToString()); |
| 0 | 205 | | sceneLimitsDictionary.Add("bodies", sceneLimits.bodies.ToString()); |
| 0 | 206 | | sceneLimitsDictionary.Add("materials", sceneLimits.materials.ToString()); |
| 0 | 207 | | sceneLimitsDictionary.Add("textures", sceneLimits.textures.ToString()); |
| 0 | 208 | | sceneLimitsDictionary.Add("triangles", sceneLimits.triangles.ToString()); |
| 0 | 209 | | sceneLimitsDictionary.Add("entities", sceneLimits.entities.ToString()); |
| 0 | 210 | | sceneLimitsDictionary.Add("scene_height", sceneLimits.sceneHeight.ToString()); |
| | 211 | |
|
| 0 | 212 | | return sceneLimitsDictionary; |
| | 213 | | } |
| | 214 | |
|
| | 215 | | public static string GetLimitsPassedArray(SceneMetricsModel sceneUsage, SceneMetricsModel sceneLimits) |
| | 216 | | { |
| 0 | 217 | | string limitsPassed = "["; |
| | 218 | |
|
| 0 | 219 | | if (sceneUsage.bodies >= sceneLimits.bodies) |
| 0 | 220 | | limitsPassed += "bodies,"; |
| 0 | 221 | | if (sceneUsage.entities >= sceneLimits.entities) |
| 0 | 222 | | limitsPassed += "entities,"; |
| 0 | 223 | | if (sceneUsage.textures >= sceneLimits.textures) |
| 0 | 224 | | limitsPassed += "textures,"; |
| 0 | 225 | | if (sceneUsage.triangles >= sceneLimits.triangles) |
| 0 | 226 | | limitsPassed += "triangles,"; |
| 0 | 227 | | if (sceneUsage.materials >= sceneLimits.materials) |
| 0 | 228 | | limitsPassed += "materials,"; |
| 0 | 229 | | if (sceneUsage.meshes >= sceneLimits.meshes) |
| 0 | 230 | | limitsPassed += "meshes,"; |
| | 231 | |
|
| 0 | 232 | | limitsPassed = limitsPassed.Substring(0, limitsPassed.Length - 1); |
| 0 | 233 | | limitsPassed += "]"; |
| 0 | 234 | | return limitsPassed; |
| | 235 | | } |
| | 236 | |
|
| | 237 | | #endregion |
| | 238 | |
|
| | 239 | | #region CommonInfo |
| | 240 | |
|
| | 241 | | private static Vector2Int coords; |
| | 242 | | private static string ownership; |
| | 243 | | private static Vector2Int size; |
| | 244 | |
|
| | 245 | | public static void AddSceneInfo(Vector2Int sceneCoords, string sceneOwnership, Vector2Int sceneSize) |
| | 246 | | { |
| 0 | 247 | | coords = sceneCoords; |
| 0 | 248 | | ownership = sceneOwnership; |
| 0 | 249 | | size = sceneSize; |
| 0 | 250 | | } |
| | 251 | |
|
| | 252 | | #endregion |
| | 253 | |
|
| | 254 | | private static void SendEditorEvent(string eventName, Dictionary<string, string> events) |
| | 255 | | { |
| 5 | 256 | | events.Add("ownership", ownership); |
| 5 | 257 | | events.Add("coords", coords.ToString()); |
| 5 | 258 | | events.Add("scene_size", size.ToString()); |
| 5 | 259 | | SendEvent(eventName, events); |
| 5 | 260 | | } |
| | 261 | |
|
| | 262 | | private static void SendEvent(string eventName, Dictionary<string, string> events) |
| | 263 | | { |
| 12 | 264 | | IAnalytics analytics = DCL.Environment.i.platform.serviceProviders.analytics; |
| 12 | 265 | | analytics.SendAnalytic(eventName, events); |
| 12 | 266 | | } |
| | 267 | | } |