< Summary

Class:BIWAnalytics
Assembly:BIWAnalytics
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/BuilderMode/Analytics/BIWAnalytics.cs
Covered lines:24
Uncovered lines:94
Coverable lines:118
Total lines:238
Line coverage:20.3% (24 of 118)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PlayerOpenPanel(...)0%2100%
PlayerClosesPanel(...)0%110100%
PlayerJumpOrEdit(...)0%2100%
PlayerUnpublishScene(...)0%110100%
StartEditorFlow(...)0%2100%
EnterEditor(...)0%2100%
ExitEditor(...)0%2100%
StartScenePublish(...)0%2100%
EndScenePublish(...)0%2100%
SceneLimitsOverPassed(...)0%2100%
NewObjectPlaced(...)0%2100%
NewObjectPlacedChunk(...)0%30500%
QuickAccessAssigned(...)0%2100%
FavoriteAdded(...)0%110100%
CatalogItemSearched(...)0%2100%
ConvertSceneMetricsModelToDictionary(...)0%2100%
AddSceneInfo(...)0%2100%
SendEditorEvent(...)0%110100%
SendEvent(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/BuilderMode/Analytics/BIWAnalytics.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using DCL;
 4using Newtonsoft.Json;
 5using 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>
 11public static class BIWAnalytics
 12{
 13
 14    #region BuilderPanel
 15
 16    public static void PlayerOpenPanel(int landsOwned, int landsOperator)
 17    {
 018        Dictionary<string, string> events = new Dictionary<string, string>();
 019        events.Add("Lands Owned", landsOwned.ToString());
 020        events.Add("Lands Operator", landsOperator.ToString());
 021        SendEvent("player_open_panel", events);
 022    }
 23
 24    public static void PlayerClosesPanel(int landsOwned, int landsOperator)
 25    {
 126        Dictionary<string, string> events = new Dictionary<string, string>();
 127        events.Add("Lands Owned", landsOwned.ToString());
 128        events.Add("Lands Operator", landsOperator.ToString());
 129        SendEvent("player_closes_panel", events);
 130    }
 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    {
 041        Dictionary<string, string> events = new Dictionary<string, string>();
 042        events.Add("source", source);
 043        events.Add("mode", mode);
 044        events.Add("coords", coords.ToString());
 045        events.Add("ownership", ownership);
 046        SendEvent("player_jump_or_edit", events);
 047    }
 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    {
 256        Dictionary<string, string> events = new Dictionary<string, string>();
 257        events.Add("type", type);
 258        events.Add("coords", coords.ToString());
 259        SendEvent("player_unpublish_scene", events);
 260    }
 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    {
 072        Dictionary<string, string> events = new Dictionary<string, string>();
 073        events.Add("source", source);
 074        SendEditorEvent("start_editor_flow", events);
 075    }
 76
 77    public static void EnterEditor(float loadingTime)
 78    {
 079        Dictionary<string, string> events = new Dictionary<string, string>();
 080        events.Add("loading_time", loadingTime.ToString());
 081        SendEditorEvent("enter_editor", events);
 082    }
 83
 84    public static void ExitEditor(float timeInvestedInTheEditor)
 85    {
 086        Dictionary<string, string> events = new Dictionary<string, string>();
 087        events.Add("time_in_the_editor", timeInvestedInTheEditor.ToString());
 088        SendEditorEvent("exit_editor", events);
 089    }
 90
 91    public static void StartScenePublish(SceneMetricsModel sceneLimits)
 92    {
 093        Dictionary<string, string> events = new Dictionary<string, string>();
 094        events.Add("scene_limits", JsonConvert.SerializeObject(ConvertSceneMetricsModelToDictionary(sceneLimits)));
 095        SendEditorEvent("start_publish_of_the_scene", events);
 096    }
 97
 98    public static void EndScenePublish(SceneMetricsModel sceneLimits, string successOrError, float publicationTime)
 99    {
 0100        Dictionary<string, string> events = new Dictionary<string, string>();
 0101        events.Add("success", successOrError);
 0102        events.Add("publication_time", publicationTime.ToString());
 0103        events.Add("scene_limits", JsonConvert.SerializeObject(ConvertSceneMetricsModelToDictionary(sceneLimits)));
 0104        SendEditorEvent("end_scene_publish", events);
 0105    }
 106
 107    public static void SceneLimitsOverPassed(SceneMetricsModel sceneLimits)
 108    {
 0109        Dictionary<string, string> events = new Dictionary<string, string>();
 0110        events.Add("scene_limits", JsonConvert.SerializeObject(ConvertSceneMetricsModelToDictionary(sceneLimits)));
 0111        SendEditorEvent("scene_limits_over_passed", events);
 0112    }
 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    {
 0121        Dictionary<string, string> events = new Dictionary<string, string>();
 0122        events.Add("name", catalogItem.name);
 0123        events.Add("assetPack", catalogItem.assetPackName);
 0124        events.Add("category", catalogItem.category);
 0125        events.Add("category_name", catalogItem.categoryName);
 0126        events.Add("source", source);
 0127        events.Add("type", catalogItem.itemType.ToString());
 0128        SendEditorEvent("new_object_placed", events);
 0129    }
 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    {
 0138        Dictionary<string, string> events = new Dictionary<string, string>();
 0139        List<string> items = new List<string>();
 0140        foreach (var catalogItem in itemsToSendAnalytics)
 141        {
 0142            if (events.ContainsKey(catalogItem.Key.name))
 143                continue;
 144
 0145            Dictionary<string, string> item = new Dictionary<string, string>();
 0146            int amountOfItems = 0;
 0147            foreach (var itemsToCompare in itemsToSendAnalytics)
 148            {
 0149                if (catalogItem.Key == itemsToCompare.Key)
 0150                    amountOfItems++;
 151            }
 152
 0153            item.Add("name", catalogItem.Key.name);
 0154            item.Add("amount", amountOfItems.ToString());
 0155            item.Add("assetPack", catalogItem.Key.assetPackName);
 0156            item.Add("category", catalogItem.Key.category);
 0157            item.Add("category_name", catalogItem.Key.categoryName);
 0158            item.Add("source", catalogItem.Value);
 0159            item.Add("type", catalogItem.Key.ToString());
 160
 0161            items.Add( JsonConvert.SerializeObject(item));
 162        }
 0163        events.Add("items", JsonConvert.SerializeObject(items));
 0164        SendEditorEvent("new_object_placed", events);
 0165    }
 166
 167    public static void QuickAccessAssigned(CatalogItem catalogItem, string source)
 168    {
 0169        Dictionary<string, string> events = new Dictionary<string, string>();
 0170        events.Add("name", catalogItem.name);
 0171        events.Add("assetPack", catalogItem.assetPackName);
 0172        events.Add("category", catalogItem.category);
 0173        events.Add("category Name", catalogItem.categoryName);
 0174        events.Add("source", source);
 0175        events.Add("type", catalogItem.itemType.ToString());
 0176        SendEditorEvent("quick_access_assigned", events);
 0177    }
 178
 179    public static void FavoriteAdded(CatalogItem catalogItem)
 180    {
 1181        Dictionary<string, string> events = new Dictionary<string, string>();
 1182        events.Add("name", catalogItem.name);
 1183        events.Add("assetPack", catalogItem.assetPackName);
 1184        events.Add("category", catalogItem.category);
 1185        events.Add("category Name", catalogItem.categoryName);
 1186        events.Add("type", catalogItem.itemType.ToString());
 1187        SendEditorEvent("favorite_added", events);
 1188    }
 189
 190    public static void CatalogItemSearched(string searchQuery, int resultAmount)
 191    {
 0192        Dictionary<string, string> events = new Dictionary<string, string>();
 0193        events.Add("search_query", searchQuery);
 0194        events.Add("result_amount", resultAmount.ToString());
 0195        SendEditorEvent("catalog_item_searched", events);
 0196    }
 197
 198    private static Dictionary<string, string> ConvertSceneMetricsModelToDictionary(SceneMetricsModel sceneLimits)
 199    {
 0200        Dictionary<string, string> sceneLimitsDictionary = new Dictionary<string, string>();
 0201        sceneLimitsDictionary.Add("meshes", sceneLimits.meshes.ToString());
 0202        sceneLimitsDictionary.Add("bodies", sceneLimits.bodies.ToString());
 0203        sceneLimitsDictionary.Add("materials", sceneLimits.materials.ToString());
 0204        sceneLimitsDictionary.Add("textures", sceneLimits.textures.ToString());
 0205        sceneLimitsDictionary.Add("triangles", sceneLimits.triangles.ToString());
 0206        sceneLimitsDictionary.Add("entities", sceneLimits.entities.ToString());
 0207        sceneLimitsDictionary.Add("scene_height", sceneLimits.sceneHeight.ToString());
 208
 0209        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    {
 0222        coords = sceneCoords;
 0223        ownership = sceneOwnership;
 0224        size = sceneSize;
 0225    }
 226
 227    #endregion
 228
 229    private static void SendEditorEvent(string eventName, Dictionary<string, string> events)
 230    {
 1231        events.Add("ownership", ownership);
 1232        events.Add("coords", coords.ToString());
 1233        events.Add("scene_size", size.ToString());
 1234        SendEvent(eventName, events);
 1235    }
 236
 8237    private static void SendEvent(string eventName, Dictionary<string, string> events) { Analytics.i.SendAnalytic(eventN
 238}