| | 1 | | using DCL; |
| | 2 | | using DCLPlugins.RealmPlugin; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using UnityEngine; |
| | 5 | | using static Decentraland.Bff.AboutResponse.Types; |
| | 6 | |
|
| | 7 | | namespace WorldsFeaturesAnalytics |
| | 8 | | { |
| | 9 | | public class WorldsAnalytics : IWorldsAnalytics |
| | 10 | | { |
| | 11 | | internal const string ENTERED_WORLD = "user_entered_world"; |
| | 12 | | internal const string EXIT_WORLD = "user_exit_world"; |
| | 13 | |
|
| | 14 | | private readonly DataStore_Common commonDataStore; |
| | 15 | | private readonly DataStore_Realm realmDataStore; |
| | 16 | |
|
| | 17 | | private readonly IAnalytics analytics; |
| | 18 | | private bool currentlyInWorld; |
| | 19 | | private string currentWorldName; |
| | 20 | | private double lastRealmEnteredTime; |
| | 21 | | private bool firstRealmEntered; |
| | 22 | |
|
| 427 | 23 | | public WorldsAnalytics(DataStore_Common commonDataStore, DataStore_Realm realmDataStore, IAnalytics analytics) |
| | 24 | | { |
| 427 | 25 | | this.commonDataStore = commonDataStore; |
| 427 | 26 | | this.analytics = analytics; |
| 427 | 27 | | this.realmDataStore = realmDataStore; |
| | 28 | |
|
| 427 | 29 | | realmDataStore.playerRealmAboutConfiguration.OnChange += OnEnteredRealm; |
| 427 | 30 | | } |
| | 31 | |
|
| 425 | 32 | | public void Initialize() { } |
| | 33 | |
|
| | 34 | | public void Dispose() |
| | 35 | | { |
| 427 | 36 | | if (currentlyInWorld) |
| 1 | 37 | | SendPlayerLeavesWorld(currentWorldName, Time.realtimeSinceStartup - lastRealmEnteredTime, ExitType.Appli |
| | 38 | |
|
| 427 | 39 | | realmDataStore.playerRealmAboutConfiguration.OnChange -= OnEnteredRealm; |
| 427 | 40 | | } |
| | 41 | |
|
| | 42 | | private void OnEnteredRealm(AboutConfiguration current, AboutConfiguration previous) |
| | 43 | | { |
| 3 | 44 | | if (currentlyInWorld) |
| 1 | 45 | | SendPlayerLeavesWorld(currentWorldName, Time.realtimeSinceStartup - lastRealmEnteredTime, commonDataStor |
| | 46 | |
|
| 3 | 47 | | if (current.IsWorld()) |
| | 48 | | { |
| 2 | 49 | | currentWorldName = current.RealmName; |
| 2 | 50 | | SendPlayerEnteredWorld(currentWorldName, firstRealmEntered ? AccessType.Chat : AccessType.URL); |
| | 51 | | } |
| | 52 | |
|
| 3 | 53 | | currentlyInWorld = current.IsWorld(); |
| 3 | 54 | | lastRealmEnteredTime = Time.realtimeSinceStartup; |
| 3 | 55 | | firstRealmEntered = true; |
| 3 | 56 | | commonDataStore.exitedWorldThroughGoBackButton.Set(false); |
| 3 | 57 | | } |
| | 58 | |
|
| | 59 | | private void SendPlayerEnteredWorld(string worldName, AccessType accessType) |
| | 60 | | { |
| 2 | 61 | | var data = new Dictionary<string, string> |
| | 62 | | { |
| | 63 | | { "worldName", worldName }, |
| | 64 | | { "accessType", accessType.ToString() }, |
| | 65 | | }; |
| | 66 | |
|
| 2 | 67 | | analytics.SendAnalytic(ENTERED_WORLD, data); |
| 2 | 68 | | } |
| | 69 | |
|
| | 70 | | private void SendPlayerLeavesWorld(string worldName, double sessionTimeInSeconds, ExitType exitType) |
| | 71 | | { |
| 2 | 72 | | var data = new Dictionary<string, string> |
| | 73 | | { |
| | 74 | | { "worldName", worldName }, |
| | 75 | | { "sessionTime", sessionTimeInSeconds.ToString() }, |
| | 76 | | { "exitType", exitType.ToString() }, |
| | 77 | | }; |
| | 78 | |
|
| 2 | 79 | | analytics.SendAnalytic(EXIT_WORLD, data); |
| 2 | 80 | | } |
| | 81 | | } |
| | 82 | | } |