< Summary

Class:BIWAnalytics
Assembly:BIWAnalytics
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/Analytics/BIWAnalytics.cs
Covered lines:43
Uncovered lines:95
Coverable lines:138
Total lines:267
Line coverage:31.1% (43 of 138)
Covered branches:0
Total branches:0

Metrics

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

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/Analytics/BIWAnalytics.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using DCL;
 5using Newtonsoft.Json;
 6using 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>
 12public static class BIWAnalytics
 13{
 14    #region BuilderPanel
 15
 16    public static void PlayerOpenPanel(int landsOwned, int landsOperator)
 17    {
 418        Dictionary<string, string> events = new Dictionary<string, string>();
 419        events.Add("Lands Owned", landsOwned.ToString());
 420        events.Add("Lands Operator", landsOperator.ToString());
 421        SendEvent("player_open_panel", events);
 422    }
 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    {
 172        Dictionary<string, string> events = new Dictionary<string, string>();
 173        events.Add("source", source);
 174        SendEditorEvent("start_editor_flow", events);
 175    }
 76
 77    public static void EnterEditor(float loadingTime)
 78    {
 279        Dictionary<string, string> events = new Dictionary<string, string>();
 280        events.Add("loading_time", loadingTime.ToString());
 281        SendEditorEvent("enter_editor", events);
 282    }
 83
 84    public static void ExitEditor(float timeInvestedInTheEditor)
 85    {
 186        Dictionary<string, string> events = new Dictionary<string, string>();
 187        events.Add("time_in_the_editor", timeInvestedInTheEditor.ToString());
 188        SendEditorEvent("exit_editor", events);
 189    }
 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 SceneLimitsExceeded(SceneMetricsModel sceneUsage, SceneMetricsModel sceneLimits)
 108    {
 0109        Dictionary<string, string> events = new Dictionary<string, string>();
 0110        events.Add("limits_passed", GetLimitsPassedArray(sceneUsage, sceneLimits));
 0111        events.Add("scene_limits", JsonConvert.SerializeObject(ConvertSceneMetricsModelToDictionary(sceneLimits)));
 0112        events.Add("current_usage", JsonConvert.SerializeObject(ConvertSceneMetricsModelToDictionary(sceneUsage)));
 0113        SendEditorEvent("scene_limits_exceeded", events);
 0114    }
 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    {
 0123        Dictionary<string, string> events = new Dictionary<string, string>();
 0124        events.Add("name", catalogItem.name);
 0125        events.Add("assetPack", catalogItem.assetPackName);
 0126        events.Add("category", catalogItem.category);
 0127        events.Add("category_name", catalogItem.categoryName);
 0128        events.Add("source", source);
 0129        events.Add("type", catalogItem.itemType.ToString());
 0130        SendEditorEvent("new_object_placed", events);
 0131    }
 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    {
 0140        Dictionary<string, string> events = new Dictionary<string, string>();
 0141        List<string> items = new List<string>();
 0142        foreach (var catalogItem in itemsToSendAnalytics)
 143        {
 0144            if (events.ContainsKey(catalogItem.Key.name))
 145                continue;
 146
 0147            Dictionary<string, string> item = new Dictionary<string, string>();
 0148            int amountOfItems = 0;
 0149            foreach (var itemsToCompare in itemsToSendAnalytics)
 150            {
 0151                if (catalogItem.Key == itemsToCompare.Key)
 0152                    amountOfItems++;
 153            }
 154
 0155            item.Add("name", catalogItem.Key.name);
 0156            item.Add("amount", amountOfItems.ToString());
 0157            item.Add("assetPack", catalogItem.Key.assetPackName);
 0158            item.Add("category", catalogItem.Key.category);
 0159            item.Add("category_name", catalogItem.Key.categoryName);
 0160            item.Add("source", catalogItem.Value);
 0161            item.Add("type", catalogItem.Key.ToString());
 162
 0163            items.Add( JsonConvert.SerializeObject(item));
 164        }
 165
 0166        events.Add("items", JsonConvert.SerializeObject(items));
 0167        SendEditorEvent("new_object_placed", events);
 0168    }
 169
 170    public static void QuickAccessAssigned(CatalogItem catalogItem, string source)
 171    {
 0172        Dictionary<string, string> events = new Dictionary<string, string>();
 0173        events.Add("name", catalogItem.name);
 0174        events.Add("assetPack", catalogItem.assetPackName);
 0175        events.Add("category", catalogItem.category);
 0176        events.Add("category Name", catalogItem.categoryName);
 0177        events.Add("source", source);
 0178        events.Add("type", catalogItem.itemType.ToString());
 0179        SendEditorEvent("quick_access_assigned", events);
 0180    }
 181
 182    public static void FavoriteAdded(CatalogItem catalogItem)
 183    {
 1184        Dictionary<string, string> events = new Dictionary<string, string>();
 1185        events.Add("name", catalogItem.name);
 1186        events.Add("assetPack", catalogItem.assetPackName);
 1187        events.Add("category", catalogItem.category);
 1188        events.Add("category Name", catalogItem.categoryName);
 1189        events.Add("type", catalogItem.itemType.ToString());
 1190        SendEditorEvent("favorite_added", events);
 1191    }
 192
 193    public static void CatalogItemSearched(string searchQuery, int resultAmount)
 194    {
 0195        Dictionary<string, string> events = new Dictionary<string, string>();
 0196        events.Add("search_query", searchQuery);
 0197        events.Add("result_amount", resultAmount.ToString());
 0198        SendEditorEvent("catalog_item_searched", events);
 0199    }
 200
 201    private static Dictionary<string, string> ConvertSceneMetricsModelToDictionary(SceneMetricsModel sceneLimits)
 202    {
 0203        Dictionary<string, string> sceneLimitsDictionary = new Dictionary<string, string>();
 0204        sceneLimitsDictionary.Add("meshes", sceneLimits.meshes.ToString());
 0205        sceneLimitsDictionary.Add("bodies", sceneLimits.bodies.ToString());
 0206        sceneLimitsDictionary.Add("materials", sceneLimits.materials.ToString());
 0207        sceneLimitsDictionary.Add("textures", sceneLimits.textures.ToString());
 0208        sceneLimitsDictionary.Add("triangles", sceneLimits.triangles.ToString());
 0209        sceneLimitsDictionary.Add("entities", sceneLimits.entities.ToString());
 0210        sceneLimitsDictionary.Add("scene_height", sceneLimits.sceneHeight.ToString());
 211
 0212        return sceneLimitsDictionary;
 213    }
 214
 215    public static string GetLimitsPassedArray(SceneMetricsModel sceneUsage, SceneMetricsModel sceneLimits)
 216    {
 0217        string limitsPassed = "[";
 218
 0219        if (sceneUsage.bodies >= sceneLimits.bodies)
 0220            limitsPassed += "bodies,";
 0221        if (sceneUsage.entities >= sceneLimits.entities)
 0222            limitsPassed += "entities,";
 0223        if (sceneUsage.textures >= sceneLimits.textures)
 0224            limitsPassed += "textures,";
 0225        if (sceneUsage.triangles >= sceneLimits.triangles)
 0226            limitsPassed += "triangles,";
 0227        if (sceneUsage.materials >= sceneLimits.materials)
 0228            limitsPassed += "materials,";
 0229        if (sceneUsage.meshes >= sceneLimits.meshes)
 0230            limitsPassed += "meshes,";
 231
 0232        limitsPassed = limitsPassed.Substring(0, limitsPassed.Length - 1);
 0233        limitsPassed += "]";
 0234        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    {
 0247        coords = sceneCoords;
 0248        ownership = sceneOwnership;
 0249        size = sceneSize;
 0250    }
 251
 252    #endregion
 253
 254    private static void SendEditorEvent(string eventName, Dictionary<string, string> events)
 255    {
 5256        events.Add("ownership", ownership);
 5257        events.Add("coords", coords.ToString());
 5258        events.Add("scene_size", size.ToString());
 5259        SendEvent(eventName, events);
 5260    }
 261
 262    private static void SendEvent(string eventName, Dictionary<string, string> events)
 263    {
 12264        IAnalytics analytics = DCL.Environment.i.platform.serviceProviders.analytics;
 12265        analytics.SendAnalytic(eventName, events);
 12266    }
 267}