| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | namespace ExploreV2Analytics |
| | 6 | | { |
| | 7 | | public interface IExploreV2Analytics |
| | 8 | | { |
| | 9 | | void SendStartMenuVisibility(bool isVisible, ExploreUIVisibilityMethod method); |
| | 10 | | void SendStartMenuSectionVisibility(ExploreSection section, bool isVisible); |
| | 11 | | void SendEventTeleport(string eventId, string eventName, bool isWorld, Vector2Int coords, ActionSource source = |
| | 12 | | void SendClickOnEventInfo(string eventId, string eventName, bool isWorld, int resultPosition = -1, ActionSource |
| | 13 | | void SendPlaceTeleport(string placeId, string placeName, Vector2Int coords, ActionSource source = ActionSource.F |
| | 14 | | void SendWorldTeleport(string worldId, string worldName, ActionSource source = ActionSource.FromExplore); |
| | 15 | | void SendClickOnPlaceInfo(string placeId, string placeName, int resultPosition = -1, ActionSource source = Actio |
| | 16 | | void SendClickOnWorldInfo(string worldId, string worldName, int resultPosition = -1, ActionSource source = Actio |
| | 17 | | void SendParticipateEvent(string eventId, bool isWorld, ActionSource source = ActionSource.FromExplore); |
| | 18 | | void SendRemoveParticipateEvent(string eventId, bool isWorld, ActionSource source = ActionSource.FromExplore); |
| | 19 | | void TeleportToPlaceFromFavorite(string placeUUID, string placeName); |
| | 20 | | void SendSearchEvents(string searchString, Vector2Int[] firstResultsCoordinates, string[] firstResultsIds); |
| | 21 | | void SendSearchPlaces(string searchString, Vector2Int[] firstResultsCoordinates, string[] firstResultsIds, Actio |
| | 22 | | void SendSearchWorlds(string searchString, string[] firstResultsIds); |
| | 23 | | void SendPlacesTabOpen(); |
| | 24 | | void SendWorldsTabOpen(); |
| | 25 | | void SendEventsTabOpen(); |
| | 26 | | void SendFavoritesTabOpen(); |
| | 27 | | void SendFilterEvents(FilterType filterType, string filterValue = ""); |
| | 28 | | void SendClickedNavmapSearchResult(Vector2Int coordinatesOfResult); |
| | 29 | | void SendToggleMapLayer(string layerName, bool isActive); |
| | 30 | | void SendOpenGenesisCityUrl(); |
| | 31 | | void SendCenterMapToHome(); |
| | 32 | | void SendCenterMapToPlayer(); |
| | 33 | | } |
| | 34 | |
|
| | 35 | | public class ExploreV2Analytics : IExploreV2Analytics |
| | 36 | | { |
| | 37 | | private const string START_MENU_VISIBILITY = "start_menu_visibility"; |
| | 38 | | private const string START_MENU_SECTION_VISIBILITY = "start_menu_section_visibility"; |
| | 39 | | private const string EXPLORE_EVENT_TELEPORT = "explore_event_teleport"; |
| | 40 | | private const string EXPLORE_CLICK_EVENT_INFO = "explore_click_event_info"; |
| | 41 | | private const string EXPLORE_SEARCH_EVENTS = "explore_search_events"; |
| | 42 | | private const string EXPLORE_SEARCH_PLACES = "explore_search_places"; |
| | 43 | | private const string EXPLORE_SEARCH_WORLDS = "explore_search_worlds"; |
| | 44 | | private const string EXPLORE_PARTICIPATE_EVENT = "explore_participate_event"; |
| | 45 | | private const string EXPLORE_REMOVE_PARTICIPATE_EVENT = "explore_remove_participate_event"; |
| | 46 | | private const string EXPLORE_PLACE_TELEPORT = "explore_place_teleport"; |
| | 47 | | private const string EXPLORE_WORLD_TELEPORT = "explore_world_teleport"; |
| | 48 | | private const string EXPLORE_CLICK_PLACE_INFO = "explore_click_place_info"; |
| | 49 | | private const string EXPLORE_CLICK_WORLD_INFO = "explore_click_world_info"; |
| | 50 | | private const string TELEPORT_FAVORITE_PLACE = "player_teleport_to_favorite_place"; |
| | 51 | | private const string EXPLORE_PLACES_TAB_OPEN = "explore_places_tab_open"; |
| | 52 | | private const string EXPLORE_WORLDS_TAB_OPEN = "explore_worlds_tab_open"; |
| | 53 | | private const string EXPLORE_EVENTS_TAB_OPEN = "explore_events_tab_open"; |
| | 54 | | private const string EXPLORE_FAVORITES_TAB_OPEN = "explore_favorites_tab_open"; |
| | 55 | | private const string FILTER_EVENTS = "player_filter_events"; |
| | 56 | | private const string SELECT_NAVMAP_HISTORY_RESULT = "clicked_navmap_search_result"; |
| | 57 | | private const string TOGGLE_MAP_LAYER = "toggle_map_layer"; |
| | 58 | | private const string MAP_CENTER_HOME = "map_center_home"; |
| | 59 | | private const string MAP_CENTER_TO_PLAYER = "map_center_to_player"; |
| | 60 | | private const string MAP_OPEN_GENESIS_CITY_URL = "map_open_genesis_city_url"; |
| | 61 | |
|
| | 62 | | private static DateTime? exploreMainMenuSetVisibleTimeStamp = null; |
| | 63 | | private static DateTime? exploreSectionSetVisibleTimeStamp = null; |
| | 64 | | private static DateTime? eventTimeFilterTimeStamp = null; |
| | 65 | |
|
| | 66 | | private const int MIN_TIME_TO_SEND_EVENT_TIME_FILTER_METRIC = 5; |
| | 67 | |
|
| | 68 | | public void SendStartMenuVisibility(bool isVisible, ExploreUIVisibilityMethod method) |
| | 69 | | { |
| 0 | 70 | | Dictionary<string, string> data = new Dictionary<string, string>(); |
| 0 | 71 | | data.Add("visible", isVisible.ToString()); |
| 0 | 72 | | data.Add("method", method.ToString()); |
| | 73 | |
|
| 0 | 74 | | if (isVisible) |
| 0 | 75 | | exploreMainMenuSetVisibleTimeStamp = DateTime.Now; |
| | 76 | | else |
| | 77 | | { |
| 0 | 78 | | if (exploreMainMenuSetVisibleTimeStamp.HasValue) |
| | 79 | | { |
| 0 | 80 | | data.Add("open_duration_ms", (DateTime.Now - exploreMainMenuSetVisibleTimeStamp.Value).TotalMillisec |
| 0 | 81 | | exploreMainMenuSetVisibleTimeStamp = null; |
| | 82 | | } |
| | 83 | | } |
| | 84 | |
|
| 0 | 85 | | GenericAnalytics.SendAnalytic(START_MENU_VISIBILITY, data); |
| 0 | 86 | | } |
| | 87 | |
|
| | 88 | | public void SendStartMenuSectionVisibility(ExploreSection section, bool isVisible) |
| | 89 | | { |
| 0 | 90 | | Dictionary<string, string> data = new Dictionary<string, string>(); |
| 0 | 91 | | data.Add("section", section.ToString()); |
| 0 | 92 | | data.Add("visible", isVisible.ToString()); |
| | 93 | |
|
| 0 | 94 | | if (isVisible) |
| 0 | 95 | | exploreSectionSetVisibleTimeStamp = DateTime.Now; |
| | 96 | | else |
| | 97 | | { |
| 0 | 98 | | if (exploreSectionSetVisibleTimeStamp.HasValue) |
| | 99 | | { |
| 0 | 100 | | data.Add("open_duration_ms", (DateTime.Now - exploreSectionSetVisibleTimeStamp.Value).TotalMilliseco |
| 0 | 101 | | exploreSectionSetVisibleTimeStamp = null; |
| | 102 | | } |
| | 103 | | } |
| | 104 | |
|
| 0 | 105 | | GenericAnalytics.SendAnalytic(START_MENU_SECTION_VISIBILITY, data); |
| 0 | 106 | | } |
| | 107 | |
|
| | 108 | | public void SendEventTeleport(string eventId, string eventName, bool isWorld, Vector2Int coords, ActionSource so |
| | 109 | | { |
| 0 | 110 | | Dictionary<string, string> data = new Dictionary<string, string>(); |
| 0 | 111 | | data.Add("event_id", eventId); |
| 0 | 112 | | data.Add("event_name", eventName); |
| 0 | 113 | | data.Add("isWorld", isWorld.ToString()); |
| 0 | 114 | | data.Add("event_coords_x", coords.x.ToString()); |
| 0 | 115 | | data.Add("event_coords_y", coords.y.ToString()); |
| 0 | 116 | | data.Add("source", source.ToString()); |
| 0 | 117 | | GenericAnalytics.SendAnalytic(EXPLORE_EVENT_TELEPORT, data); |
| 0 | 118 | | } |
| | 119 | |
|
| | 120 | | public void SendParticipateEvent(string eventId, bool isWorld, ActionSource source = ActionSource.FromExplore) |
| | 121 | | { |
| 0 | 122 | | Dictionary<string, string> data = new Dictionary<string, string>(); |
| 0 | 123 | | data.Add("event_id", eventId); |
| 0 | 124 | | data.Add("isWorld", isWorld.ToString()); |
| 0 | 125 | | data.Add("source", source.ToString()); |
| 0 | 126 | | GenericAnalytics.SendAnalytic(EXPLORE_PARTICIPATE_EVENT, data); |
| 0 | 127 | | } |
| | 128 | |
|
| | 129 | | public void SendRemoveParticipateEvent(string eventId, bool isWorld, ActionSource source = ActionSource.FromExpl |
| | 130 | | { |
| 0 | 131 | | Dictionary<string, string> data = new Dictionary<string, string>(); |
| 0 | 132 | | data.Add("event_id", eventId); |
| 0 | 133 | | data.Add("isWorld", isWorld.ToString()); |
| 0 | 134 | | data.Add("source", source.ToString()); |
| 0 | 135 | | GenericAnalytics.SendAnalytic(EXPLORE_REMOVE_PARTICIPATE_EVENT, data); |
| 0 | 136 | | } |
| | 137 | |
|
| | 138 | | public void SendClickOnEventInfo(string eventId, string eventName, bool isWorld, int resultPosition = -1, Action |
| | 139 | | { |
| 0 | 140 | | Dictionary<string, string> data = new Dictionary<string, string>(); |
| 0 | 141 | | data.Add("event_id", eventId); |
| 0 | 142 | | data.Add("event_name", eventName); |
| 0 | 143 | | data.Add("isWorld", isWorld.ToString()); |
| 0 | 144 | | data.Add("source", source.ToString()); |
| 0 | 145 | | data.Add("result_position", resultPosition.ToString()); |
| 0 | 146 | | GenericAnalytics.SendAnalytic(EXPLORE_CLICK_EVENT_INFO, data); |
| 0 | 147 | | } |
| | 148 | |
|
| | 149 | | public void SendPlaceTeleport(string placeId, string placeName, Vector2Int coords, ActionSource source = ActionS |
| | 150 | | { |
| 0 | 151 | | Dictionary<string, string> data = new Dictionary<string, string>(); |
| 0 | 152 | | data.Add("place_id", placeId); |
| 0 | 153 | | data.Add("place_name", placeName); |
| 0 | 154 | | data.Add("place_coords_x", coords.x.ToString()); |
| 0 | 155 | | data.Add("place_coords_y", coords.y.ToString()); |
| 0 | 156 | | data.Add("source", source.ToString()); |
| 0 | 157 | | GenericAnalytics.SendAnalytic(EXPLORE_PLACE_TELEPORT, data); |
| 0 | 158 | | } |
| | 159 | |
|
| | 160 | | public void SendWorldTeleport(string worldId, string worldName, ActionSource source = ActionSource.FromExplore) |
| | 161 | | { |
| 0 | 162 | | Dictionary<string, string> data = new Dictionary<string, string>(); |
| 0 | 163 | | data.Add("place_id", worldId); |
| 0 | 164 | | data.Add("place_name", worldName); |
| 0 | 165 | | data.Add("source", source.ToString()); |
| 0 | 166 | | GenericAnalytics.SendAnalytic(EXPLORE_WORLD_TELEPORT, data); |
| 0 | 167 | | } |
| | 168 | |
|
| | 169 | | public void SendClickOnPlaceInfo(string placeId, string placeName, int resultPosition = -1, ActionSource source |
| | 170 | | { |
| 0 | 171 | | Dictionary<string, string> data = new Dictionary<string, string>(); |
| 0 | 172 | | data.Add("place_id", placeId); |
| 0 | 173 | | data.Add("place_name", placeName); |
| 0 | 174 | | data.Add("source", source.ToString()); |
| 0 | 175 | | data.Add("result_position", resultPosition.ToString()); |
| 0 | 176 | | GenericAnalytics.SendAnalytic(EXPLORE_CLICK_PLACE_INFO, data); |
| 0 | 177 | | } |
| | 178 | |
|
| | 179 | | public void SendClickOnWorldInfo(string worldId, string worldName, int resultPosition = -1, ActionSource source |
| | 180 | | { |
| 0 | 181 | | Dictionary<string, string> data = new Dictionary<string, string>(); |
| 0 | 182 | | data.Add("world_id", worldId); |
| 0 | 183 | | data.Add("world_name", worldName); |
| 0 | 184 | | data.Add("source", source.ToString()); |
| 0 | 185 | | data.Add("result_position", resultPosition.ToString()); |
| 0 | 186 | | GenericAnalytics.SendAnalytic(EXPLORE_CLICK_WORLD_INFO, data); |
| 0 | 187 | | } |
| | 188 | |
|
| | 189 | | public void TeleportToPlaceFromFavorite(string placeUUID, string placeName) |
| | 190 | | { |
| 0 | 191 | | var data = new Dictionary<string, string> |
| | 192 | | { |
| | 193 | | ["place_id"] = placeUUID, |
| | 194 | | ["place_name"] = placeName |
| | 195 | | }; |
| 0 | 196 | | GenericAnalytics.SendAnalytic(TELEPORT_FAVORITE_PLACE, data); |
| 0 | 197 | | } |
| | 198 | |
|
| | 199 | | public void SendSearchEvents(string searchString, Vector2Int[] firstResultsCoordinates, string[] firstResultsIds |
| | 200 | | { |
| 0 | 201 | | var data = new Dictionary<string, string> |
| | 202 | | { |
| | 203 | | ["search_string"] = searchString, |
| | 204 | | ["first_results_coordinates"] = string.Join(",", firstResultsCoordinates), |
| | 205 | | ["first_results_ids"] = string.Join(",", firstResultsIds) |
| | 206 | | }; |
| 0 | 207 | | GenericAnalytics.SendAnalytic(EXPLORE_SEARCH_EVENTS, data); |
| 0 | 208 | | } |
| | 209 | |
|
| | 210 | | public void SendSearchPlaces(string searchString, Vector2Int[] firstResultsCoordinates, string[] firstResultsIds |
| | 211 | | { |
| 0 | 212 | | var data = new Dictionary<string, string> |
| | 213 | | { |
| | 214 | | ["search_string"] = searchString, |
| | 215 | | ["first_results_coordinates"] = string.Join(",", firstResultsCoordinates), |
| | 216 | | ["first_results_ids"] = string.Join(",", firstResultsIds), |
| | 217 | | ["source"] = source.ToString() |
| | 218 | | }; |
| 0 | 219 | | GenericAnalytics.SendAnalytic(EXPLORE_SEARCH_PLACES, data); |
| 0 | 220 | | } |
| | 221 | |
|
| | 222 | | public void SendSearchWorlds(string searchString, string[] firstResultsIds) |
| | 223 | | { |
| 0 | 224 | | var data = new Dictionary<string, string> |
| | 225 | | { |
| | 226 | | ["search_string"] = searchString, |
| | 227 | | ["first_results_ids"] = string.Join(",", firstResultsIds) |
| | 228 | | }; |
| 0 | 229 | | GenericAnalytics.SendAnalytic(EXPLORE_SEARCH_WORLDS, data); |
| 0 | 230 | | } |
| | 231 | |
|
| | 232 | | public void SendPlacesTabOpen() |
| | 233 | | { |
| 0 | 234 | | var data = new Dictionary<string, string>(); |
| 0 | 235 | | GenericAnalytics.SendAnalytic(EXPLORE_PLACES_TAB_OPEN, data); |
| 0 | 236 | | } |
| | 237 | |
|
| | 238 | | public void SendWorldsTabOpen() |
| | 239 | | { |
| 0 | 240 | | var data = new Dictionary<string, string>(); |
| 0 | 241 | | GenericAnalytics.SendAnalytic(EXPLORE_WORLDS_TAB_OPEN, data); |
| 0 | 242 | | } |
| | 243 | |
|
| | 244 | | public void SendEventsTabOpen() |
| | 245 | | { |
| 0 | 246 | | var data = new Dictionary<string, string>(); |
| 0 | 247 | | GenericAnalytics.SendAnalytic(EXPLORE_EVENTS_TAB_OPEN, data); |
| 0 | 248 | | } |
| | 249 | |
|
| | 250 | | public void SendFavoritesTabOpen() |
| | 251 | | { |
| 0 | 252 | | var data = new Dictionary<string, string>(); |
| 0 | 253 | | GenericAnalytics.SendAnalytic(EXPLORE_FAVORITES_TAB_OPEN, data); |
| 0 | 254 | | } |
| | 255 | |
|
| | 256 | | public void SendFilterEvents(FilterType filterType, string filterValue = "") |
| | 257 | | { |
| 0 | 258 | | if (eventTimeFilterTimeStamp == null) |
| 0 | 259 | | eventTimeFilterTimeStamp = DateTime.Now; |
| | 260 | | else |
| | 261 | | { |
| | 262 | | // Due to the possible amount of times that we could send this metric, we are setting a min time of 5 se |
| 0 | 263 | | if ((DateTime.Now - eventTimeFilterTimeStamp.Value).TotalSeconds <= MIN_TIME_TO_SEND_EVENT_TIME_FILTER_M |
| 0 | 264 | | return; |
| | 265 | |
|
| 0 | 266 | | eventTimeFilterTimeStamp = null; |
| | 267 | | } |
| | 268 | |
|
| 0 | 269 | | var data = new Dictionary<string, string> |
| | 270 | | { |
| | 271 | | ["type"] = filterType.ToString(), |
| | 272 | | ["value"] = filterValue |
| | 273 | | }; |
| 0 | 274 | | GenericAnalytics.SendAnalytic(FILTER_EVENTS, data); |
| 0 | 275 | | } |
| | 276 | |
|
| | 277 | | public void SendClickedNavmapSearchResult(Vector2Int coordinatesOfResult) |
| | 278 | | { |
| 0 | 279 | | var data = new Dictionary<string, string> |
| | 280 | | { |
| | 281 | | ["coordinates_of_result"] = coordinatesOfResult.ToString(), |
| | 282 | | }; |
| 0 | 283 | | GenericAnalytics.SendAnalytic(SELECT_NAVMAP_HISTORY_RESULT, data); |
| 0 | 284 | | } |
| | 285 | |
|
| | 286 | | public void SendToggleMapLayer(string layerName, bool isActive) |
| | 287 | | { |
| 0 | 288 | | var data = new Dictionary<string, string> |
| | 289 | | { |
| | 290 | | ["layer_name"] = layerName, |
| | 291 | | ["is_active"] = isActive.ToString(), |
| | 292 | | }; |
| 0 | 293 | | GenericAnalytics.SendAnalytic(TOGGLE_MAP_LAYER, data); |
| 0 | 294 | | } |
| | 295 | |
|
| | 296 | | public void SendOpenGenesisCityUrl() => |
| 0 | 297 | | GenericAnalytics.SendAnalytic(MAP_OPEN_GENESIS_CITY_URL); |
| | 298 | |
|
| | 299 | | public void SendCenterMapToHome() => |
| 0 | 300 | | GenericAnalytics.SendAnalytic(MAP_CENTER_HOME); |
| | 301 | |
|
| | 302 | | public void SendCenterMapToPlayer() => |
| 0 | 303 | | GenericAnalytics.SendAnalytic(MAP_CENTER_TO_PLAYER); |
| | 304 | | } |
| | 305 | | } |