| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using DCL; |
| | 4 | | using Newtonsoft.Json; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | /// <summary> |
| | 8 | | /// This class include all the analytics that we are tracking for builder-in-world, if you want to add a new one |
| | 9 | | /// Please do it inside this class and call the SendEditorEvent method to include all the default info |
| | 10 | | /// </summary> |
| | 11 | | public static class BIWAnalytics |
| | 12 | | { |
| | 13 | |
|
| | 14 | | #region BuilderPanel |
| | 15 | |
|
| | 16 | | public static void PlayerOpenPanel(int landsOwned, int landsOperator) |
| | 17 | | { |
| 0 | 18 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 0 | 19 | | events.Add("Lands Owned", landsOwned.ToString()); |
| 0 | 20 | | events.Add("Lands Operator", landsOperator.ToString()); |
| 0 | 21 | | SendEvent("player_open_panel", events); |
| 0 | 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 | | { |
| 0 | 72 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 0 | 73 | | events.Add("source", source); |
| 0 | 74 | | SendEditorEvent("start_editor_flow", events); |
| 0 | 75 | | } |
| | 76 | |
|
| | 77 | | public static void EnterEditor(float loadingTime) |
| | 78 | | { |
| 0 | 79 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 0 | 80 | | events.Add("loading_time", loadingTime.ToString()); |
| 0 | 81 | | SendEditorEvent("enter_editor", events); |
| 0 | 82 | | } |
| | 83 | |
|
| | 84 | | public static void ExitEditor(float timeInvestedInTheEditor) |
| | 85 | | { |
| 0 | 86 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 0 | 87 | | events.Add("time_in_the_editor", timeInvestedInTheEditor.ToString()); |
| 0 | 88 | | SendEditorEvent("exit_editor", events); |
| 0 | 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 SceneLimitsOverPassed(SceneMetricsModel sceneLimits) |
| | 108 | | { |
| 0 | 109 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 0 | 110 | | events.Add("scene_limits", JsonConvert.SerializeObject(ConvertSceneMetricsModelToDictionary(sceneLimits))); |
| 0 | 111 | | SendEditorEvent("scene_limits_over_passed", events); |
| 0 | 112 | | } |
| | 113 | |
|
| | 114 | | /// <summary> |
| | 115 | | /// When a new item is placed from the catalog |
| | 116 | | /// </summary> |
| | 117 | | /// <param name="catalogItem">The item that has been added</param> |
| | 118 | | /// <param name="source">It has been added from Categories, Asset pack, Favorites or Quick Access</param> |
| | 119 | | public static void NewObjectPlaced(CatalogItem catalogItem, string source) |
| | 120 | | { |
| 0 | 121 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 0 | 122 | | events.Add("name", catalogItem.name); |
| 0 | 123 | | events.Add("assetPack", catalogItem.assetPackName); |
| 0 | 124 | | events.Add("category", catalogItem.category); |
| 0 | 125 | | events.Add("category_name", catalogItem.categoryName); |
| 0 | 126 | | events.Add("source", source); |
| 0 | 127 | | events.Add("type", catalogItem.itemType.ToString()); |
| 0 | 128 | | SendEditorEvent("new_object_placed", events); |
| 0 | 129 | | } |
| | 130 | |
|
| | 131 | | /// <summary> |
| | 132 | | /// This will send all the items placed in a period of time in a single message |
| | 133 | | /// </summary> |
| | 134 | | /// <param name="catalogItem">The item that has been added</param> |
| | 135 | | /// <param name="source">It has been added from Categories, Asset pack, Favorites or Quick Access</param> |
| | 136 | | public static void NewObjectPlacedChunk(List<KeyValuePair<CatalogItem, string>> itemsToSendAnalytics) |
| | 137 | | { |
| 0 | 138 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 0 | 139 | | List<string> items = new List<string>(); |
| 0 | 140 | | foreach (var catalogItem in itemsToSendAnalytics) |
| | 141 | | { |
| 0 | 142 | | if (events.ContainsKey(catalogItem.Key.name)) |
| | 143 | | continue; |
| | 144 | |
|
| 0 | 145 | | Dictionary<string, string> item = new Dictionary<string, string>(); |
| 0 | 146 | | int amountOfItems = 0; |
| 0 | 147 | | foreach (var itemsToCompare in itemsToSendAnalytics) |
| | 148 | | { |
| 0 | 149 | | if (catalogItem.Key == itemsToCompare.Key) |
| 0 | 150 | | amountOfItems++; |
| | 151 | | } |
| | 152 | |
|
| 0 | 153 | | item.Add("name", catalogItem.Key.name); |
| 0 | 154 | | item.Add("amount", amountOfItems.ToString()); |
| 0 | 155 | | item.Add("assetPack", catalogItem.Key.assetPackName); |
| 0 | 156 | | item.Add("category", catalogItem.Key.category); |
| 0 | 157 | | item.Add("category_name", catalogItem.Key.categoryName); |
| 0 | 158 | | item.Add("source", catalogItem.Value); |
| 0 | 159 | | item.Add("type", catalogItem.Key.ToString()); |
| | 160 | |
|
| 0 | 161 | | items.Add( JsonConvert.SerializeObject(item)); |
| | 162 | | } |
| 0 | 163 | | events.Add("items", JsonConvert.SerializeObject(items)); |
| 0 | 164 | | SendEditorEvent("new_object_placed", events); |
| 0 | 165 | | } |
| | 166 | |
|
| | 167 | | public static void QuickAccessAssigned(CatalogItem catalogItem, string source) |
| | 168 | | { |
| 0 | 169 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 0 | 170 | | events.Add("name", catalogItem.name); |
| 0 | 171 | | events.Add("assetPack", catalogItem.assetPackName); |
| 0 | 172 | | events.Add("category", catalogItem.category); |
| 0 | 173 | | events.Add("category Name", catalogItem.categoryName); |
| 0 | 174 | | events.Add("source", source); |
| 0 | 175 | | events.Add("type", catalogItem.itemType.ToString()); |
| 0 | 176 | | SendEditorEvent("quick_access_assigned", events); |
| 0 | 177 | | } |
| | 178 | |
|
| | 179 | | public static void FavoriteAdded(CatalogItem catalogItem) |
| | 180 | | { |
| 1 | 181 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 1 | 182 | | events.Add("name", catalogItem.name); |
| 1 | 183 | | events.Add("assetPack", catalogItem.assetPackName); |
| 1 | 184 | | events.Add("category", catalogItem.category); |
| 1 | 185 | | events.Add("category Name", catalogItem.categoryName); |
| 1 | 186 | | events.Add("type", catalogItem.itemType.ToString()); |
| 1 | 187 | | SendEditorEvent("favorite_added", events); |
| 1 | 188 | | } |
| | 189 | |
|
| | 190 | | public static void CatalogItemSearched(string searchQuery, int resultAmount) |
| | 191 | | { |
| 0 | 192 | | Dictionary<string, string> events = new Dictionary<string, string>(); |
| 0 | 193 | | events.Add("search_query", searchQuery); |
| 0 | 194 | | events.Add("result_amount", resultAmount.ToString()); |
| 0 | 195 | | SendEditorEvent("catalog_item_searched", events); |
| 0 | 196 | | } |
| | 197 | |
|
| | 198 | | private static Dictionary<string, string> ConvertSceneMetricsModelToDictionary(SceneMetricsModel sceneLimits) |
| | 199 | | { |
| 0 | 200 | | Dictionary<string, string> sceneLimitsDictionary = new Dictionary<string, string>(); |
| 0 | 201 | | sceneLimitsDictionary.Add("meshes", sceneLimits.meshes.ToString()); |
| 0 | 202 | | sceneLimitsDictionary.Add("bodies", sceneLimits.bodies.ToString()); |
| 0 | 203 | | sceneLimitsDictionary.Add("materials", sceneLimits.materials.ToString()); |
| 0 | 204 | | sceneLimitsDictionary.Add("textures", sceneLimits.textures.ToString()); |
| 0 | 205 | | sceneLimitsDictionary.Add("triangles", sceneLimits.triangles.ToString()); |
| 0 | 206 | | sceneLimitsDictionary.Add("entities", sceneLimits.entities.ToString()); |
| 0 | 207 | | sceneLimitsDictionary.Add("scene_height", sceneLimits.sceneHeight.ToString()); |
| | 208 | |
|
| 0 | 209 | | return sceneLimitsDictionary; |
| | 210 | | } |
| | 211 | |
|
| | 212 | | #endregion |
| | 213 | |
|
| | 214 | | #region CommonInfo |
| | 215 | |
|
| | 216 | | private static Vector2Int coords; |
| | 217 | | private static string ownership; |
| | 218 | | private static Vector2Int size; |
| | 219 | |
|
| | 220 | | public static void AddSceneInfo(Vector2Int sceneCoords, string sceneOwnership, Vector2Int sceneSize) |
| | 221 | | { |
| 0 | 222 | | coords = sceneCoords; |
| 0 | 223 | | ownership = sceneOwnership; |
| 0 | 224 | | size = sceneSize; |
| 0 | 225 | | } |
| | 226 | |
|
| | 227 | | #endregion |
| | 228 | |
|
| | 229 | | private static void SendEditorEvent(string eventName, Dictionary<string, string> events) |
| | 230 | | { |
| 1 | 231 | | events.Add("ownership", ownership); |
| 1 | 232 | | events.Add("coords", coords.ToString()); |
| 1 | 233 | | events.Add("scene_size", size.ToString()); |
| 1 | 234 | | SendEvent(eventName, events); |
| 1 | 235 | | } |
| | 236 | |
|
| 8 | 237 | | private static void SendEvent(string eventName, Dictionary<string, string> events) { Analytics.i.SendAnalytic(eventN |
| | 238 | | } |