< Summary

Class:SocialFeaturesAnalytics.SocialAnalytics
Assembly:SocialAnalytics
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Analytics/SocialAnalytics/SocialAnalytics.cs
Covered lines:6
Uncovered lines:199
Coverable lines:205
Total lines:441
Line coverage:2.9% (6 of 205)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SocialAnalytics(...)0%220100%
SendPlayerMuted(...)0%6200%
SendPlayerUnmuted(...)0%6200%
SendVoiceMessageStartedByFirstTime()0%2100%
SendVoiceMessage(...)0%6200%
SendVoiceChannelConnection(...)0%2100%
SendVoiceChannelDisconnection()0%2100%
SendClickedOnCollectibles()0%2100%
SendStartedConversation(...)0%2100%
SendNftBuy(...)0%2100%
SendInspectAvatar(...)0%2100%
SendLinkClick(...)0%2100%
SendCopyWallet(...)0%2100%
SendCopyUsername(...)0%2100%
SendJumpInToPlayer(...)0%2100%
SendProfileEdit(...)0%2100%
SendVoiceChatPreferencesChanged(...)0%2100%
SendFriendRequestError(...)0%2100%
SendFriendRequestSent(...)0%30500%
SendFriendRequestApproved(...)0%30500%
SendFriendRequestRejected(...)0%30500%
SendFriendRequestCancelled(...)0%12300%
SendFriendDeleted(...)0%12300%
SendPassportOpen()0%2100%
SendPassportClose(...)0%2100%
SendPlayerBlocked(...)0%2100%
SendPlayerUnblocked(...)0%2100%
SendPlayerReport(...)0%2100%
SendPlayerJoin(...)0%2100%
SendPlayEmote(...)0%2100%
SendEmptyChannelCreated(...)0%30500%
SendPopulatedChannelJoined(...)0%42600%
SendLeaveChannel(...)0%42600%
SendChannelSearch(...)0%2100%
SendChannelLinkClicked(...)0%72800%
GetPlayerTypeByUserId(...)0%30500%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Analytics/SocialAnalytics/SocialAnalytics.cs

#LineLine coverage
 1using DCL;
 2using System;
 3using System.Collections.Generic;
 4using static DCL.SettingsCommon.GeneralSettings;
 5
 6namespace SocialFeaturesAnalytics
 7{
 8    public class SocialAnalytics : ISocialAnalytics
 9    {
 10        private const string PLAYER_MUTED = "user_muted";
 11        private const string PLAYER_UNMUTED = "user_unmuted";
 12        private const string VOICE_MESSAGE_STARTED_BY_FIRST_TIME = "voice_chat_start_recording";
 13        private const string VOICE_MESSAGE_SENT = "voice_message_sent";
 14        private const string VOICE_CHANNEL_CONNECTION = "voice_channel_connection";
 15        private const string VOICE_CHANNEL_DISCONNECTION = "voice_channel_disconnection";
 16        private const string VOICE_CHAT_PREFERENCES_CHANGED = "voice_chat_preferences_changed";
 17        private const string FRIEND_REQUEST_SENT = "friend_request_sent";
 18        private const string FRIEND_REQUEST_APPROVED = "friend_request_approved";
 19        private const string FRIEND_REQUEST_REJECTED = "friend_request_rejected";
 20        private const string FRIEND_REQUEST_CANCELLED = "friend_request_cancelled";
 21        private const string FRIEND_REQUEST_ERROR = "friend_request_error";
 22        private const string FRIEND_DELETED = "friend_deleted";
 23        private const string PASSPORT_OPENED = "passport_opened";
 24        private const string PASSPORT_CLOSED = "passport_closed";
 25        private const string PASSPORT_CLICKED_ON_COLLECTIONS = "passport_collections_click";
 26        private const string PASSPORT_STARTED_CONVERSATION = "passport_started_conversation";
 27        private const string PASSPORT_INSPECT_AVATAR = "passport_inspect_avatar";
 28        private const string PASSPORT_CLICK_LINK = "passport_clicked_link";
 29        private const string PASSPORT_WALLET_COPY = "passport_wallet_copy";
 30        private const string PASSPORT_USERNAME_COPY = "passport_username_copy";
 31        private const string PASSPORT_JUMP_IN = "passport_jump_in";
 32        private const string PASSPORT_EDIT_PROFILE = "passport_edit_profile";
 33        private const string PASSPORT_BUY_NFT = "passport_buy_nft";
 34        private const string PLAYER_BLOCKED = "user_blocked";
 35        private const string PLAYER_UNBLOCKED = "user_unblocked";
 36        private const string PLAYER_REPORT = "player_report";
 37        private const string PLAYER_JOIN = "player_join";
 38        private const string PLAY_EMOTE = "used_emote";
 39        private const string EMPTY_CHANNEL_CREATED = "chat_channel_created";
 40        private const string POPULATED_CHANNEL_JOINED = "player_joins_channel";
 41        private const string CHANNEL_LEAVE = "player_leaves_channel";
 42        private const string CHANNEL_SEARCH = "player_search_channel";
 43        private const string CHANNEL_LINK_CLICK = "player_clicks_channel_link";
 44
 38945        public static SocialAnalytics i { get; private set; }
 46
 47        private readonly IAnalytics analytics;
 48        private readonly IUserProfileBridge userProfileBridge;
 49
 38850        public SocialAnalytics(IAnalytics analytics, IUserProfileBridge userProfileBridge)
 51        {
 38852            this.analytics = analytics;
 38853            this.userProfileBridge = userProfileBridge;
 38854            i ??= this;
 38855        }
 56
 57        public void SendPlayerMuted(string toUserId)
 58        {
 059            PlayerType? toPlayerType = GetPlayerTypeByUserId(toUserId);
 60
 061            if (toPlayerType == null)
 062                return;
 63
 064            Dictionary<string, string> data = new Dictionary<string, string>();
 065            data.Add("to", toPlayerType.ToString());
 66
 067            analytics.SendAnalytic(PLAYER_MUTED, data);
 068        }
 69
 70        public void SendPlayerUnmuted(string toUserId)
 71        {
 072            PlayerType? toPlayerType = GetPlayerTypeByUserId(toUserId);
 73
 074            if (toPlayerType == null)
 075                return;
 76
 077            Dictionary<string, string> data = new Dictionary<string, string>();
 078            data.Add("to", toPlayerType.ToString());
 79
 080            analytics.SendAnalytic(PLAYER_UNMUTED, data);
 081        }
 82
 083        public void SendVoiceMessageStartedByFirstTime() { analytics.SendAnalytic(VOICE_MESSAGE_STARTED_BY_FIRST_TIME, n
 84
 85        public void SendVoiceMessage(double messageLength, VoiceMessageSource source, string fromUserId)
 86        {
 087            PlayerType? fromPlayerType = GetPlayerTypeByUserId(fromUserId);
 88
 089            if (fromPlayerType == null)
 090                return;
 91
 092            Dictionary<string, string> data = new Dictionary<string, string>();
 093            data.Add("from", fromPlayerType.ToString());
 094            data.Add("length", messageLength.ToString());
 095            data.Add("source", source.ToString());
 96
 097            analytics.SendAnalytic(VOICE_MESSAGE_SENT, data);
 098        }
 99
 100        public void SendVoiceChannelConnection(int numberOfPeers)
 101        {
 0102            Dictionary<string, string> data = new Dictionary<string, string>();
 0103            data.Add("numberOfPeers", numberOfPeers.ToString());
 104
 0105            analytics.SendAnalytic(VOICE_CHANNEL_CONNECTION, data);
 0106        }
 107
 0108        public void SendVoiceChannelDisconnection() { analytics.SendAnalytic(VOICE_CHANNEL_DISCONNECTION, new Dictionary
 109
 110        public void SendClickedOnCollectibles()
 111        {
 0112            analytics.SendAnalytic(PASSPORT_CLICKED_ON_COLLECTIONS, new Dictionary<string, string>());
 0113        }
 114
 115        public void SendStartedConversation(PlayerActionSource source)
 116        {
 0117            Dictionary<string, string> data = new Dictionary<string, string>();
 0118            data.Add("source", source.ToString());
 119
 0120            analytics.SendAnalytic(PASSPORT_STARTED_CONVERSATION, data);
 0121        }
 122
 123        public void SendNftBuy(PlayerActionSource source)
 124        {
 0125            Dictionary<string, string> data = new Dictionary<string, string>();
 0126            data.Add("source", source.ToString());
 127
 0128            analytics.SendAnalytic(PASSPORT_BUY_NFT, data);
 0129        }
 130
 131        public void SendInspectAvatar(double timeSpent)
 132        {
 0133            Dictionary<string, string> data = new Dictionary<string, string>();
 0134            data.Add("timeSpent", timeSpent.ToString());
 135
 0136            analytics.SendAnalytic(PASSPORT_INSPECT_AVATAR, data);
 0137        }
 138
 139        public void SendLinkClick(PlayerActionSource source)
 140        {
 0141            Dictionary<string, string> data = new Dictionary<string, string>();
 0142            data.Add("source", source.ToString());
 143
 0144            analytics.SendAnalytic(PASSPORT_CLICK_LINK, data);
 0145        }
 146
 147        public void SendCopyWallet(PlayerActionSource source)
 148        {
 0149            Dictionary<string, string> data = new Dictionary<string, string>();
 0150            data.Add("source", source.ToString());
 151
 0152            analytics.SendAnalytic(PASSPORT_WALLET_COPY, data);
 0153        }
 154
 155        public void SendCopyUsername(PlayerActionSource source)
 156        {
 0157            Dictionary<string, string> data = new Dictionary<string, string>();
 0158            data.Add("source", source.ToString());
 159
 0160            analytics.SendAnalytic(PASSPORT_USERNAME_COPY, data);
 0161        }
 162
 163        public void SendJumpInToPlayer(PlayerActionSource source)
 164        {
 0165            Dictionary<string, string> data = new Dictionary<string, string>();
 0166            data.Add("source", source.ToString());
 167
 0168            analytics.SendAnalytic(PASSPORT_JUMP_IN, data);
 0169        }
 170
 171        public void SendProfileEdit(int descriptionLength, bool hasLinks, PlayerActionSource source)
 172        {
 0173            var data = new Dictionary<string, string>
 174            {
 175                ["source"] = source.ToString(),
 176                ["descriptionLength"] = descriptionLength.ToString(),
 177                ["hasLinks"] = hasLinks.ToString(),
 178            };
 179
 0180            analytics.SendAnalytic(PASSPORT_EDIT_PROFILE, data);
 0181        }
 182
 183        public void SendVoiceChatPreferencesChanged(VoiceChatAllow preference)
 184        {
 0185            Dictionary<string, string> data = new Dictionary<string, string>();
 0186            data.Add("allow", preference.ToString());
 187
 0188            analytics.SendAnalytic(VOICE_CHAT_PREFERENCES_CHANGED, data);
 0189        }
 190
 191        public void SendFriendRequestError(string senderId, string recipientId, string source, string errorDescription)
 192        {
 0193            var data = new Dictionary<string, string>
 194            {
 195                ["source"] = source,
 196                ["from"] = senderId,
 197                ["to"] = recipientId,
 198                ["description"] = errorDescription,
 199            };
 0200            analytics.SendAnalytic(FRIEND_REQUEST_ERROR, data);
 0201        }
 202
 203        public void SendFriendRequestSent(string fromUserId, string toUserId, double messageLength, PlayerActionSource s
 204        {
 0205            PlayerType? fromPlayerType = GetPlayerTypeByUserId(fromUserId);
 0206            PlayerType? toPlayerType = GetPlayerTypeByUserId(toUserId);
 207
 0208            if (fromPlayerType == null || toPlayerType == null)
 0209                return;
 210
 0211            Dictionary<string, string> data = new Dictionary<string, string>();
 0212            data.Add("from", fromPlayerType.ToString());
 0213            data.Add("to", toPlayerType.ToString());
 214            // TODO (FRIEND REQUESTS): retro-compatibility, remove this param in the future
 0215            data.Add("text_length", messageLength.ToString());
 0216            data.Add("attached_message_length", messageLength.ToString());
 0217            data.Add("attached_message", messageLength > 0 ? "true" : "false");
 0218            data.Add("source", source.ToString());
 219
 0220            analytics.SendAnalytic(FRIEND_REQUEST_SENT, data);
 0221        }
 222
 223        public void SendFriendRequestApproved(string fromUserId, string toUserId, string source, bool hasBodyMessage)
 224        {
 0225            PlayerType? fromPlayerType = GetPlayerTypeByUserId(fromUserId);
 0226            PlayerType? toPlayerType = GetPlayerTypeByUserId(toUserId);
 227
 0228            if (fromPlayerType == null || toPlayerType == null)
 0229                return;
 230
 0231            Dictionary<string, string> data = new Dictionary<string, string>();
 0232            data.Add("from", fromPlayerType.ToString());
 0233            data.Add("to", toPlayerType.ToString());
 0234            data.Add("source", source);
 0235            data.Add("has_body_message", hasBodyMessage ? "true" : "false");
 236
 0237            analytics.SendAnalytic(FRIEND_REQUEST_APPROVED, data);
 0238        }
 239
 240        public void SendFriendRequestRejected(string fromUserId, string toUserId, string source, bool hasBodyMessage)
 241        {
 0242            PlayerType? fromPlayerType = GetPlayerTypeByUserId(fromUserId);
 0243            PlayerType? toPlayerType = GetPlayerTypeByUserId(toUserId);
 244
 0245            if (fromPlayerType == null || toPlayerType == null)
 0246                return;
 247
 0248            Dictionary<string, string> data = new Dictionary<string, string>();
 0249            data.Add("from", fromPlayerType.ToString());
 0250            data.Add("to", toPlayerType.ToString());
 0251            data.Add("source", source);
 0252            data.Add("has_body_message", hasBodyMessage ? "true" : "false");
 253
 0254            analytics.SendAnalytic(FRIEND_REQUEST_REJECTED, data);
 0255        }
 256
 257        public void SendFriendRequestCancelled(string fromUserId, string toUserId, string source)
 258        {
 0259            PlayerType? fromPlayerType = GetPlayerTypeByUserId(fromUserId);
 0260            PlayerType? toPlayerType = GetPlayerTypeByUserId(toUserId);
 261
 0262            if (fromPlayerType == null || toPlayerType == null)
 0263                return;
 264
 0265            Dictionary<string, string> data = new Dictionary<string, string>();
 0266            data.Add("from", fromPlayerType.ToString());
 0267            data.Add("to", toPlayerType.ToString());
 0268            data.Add("source", source);
 269
 0270            analytics.SendAnalytic(FRIEND_REQUEST_CANCELLED, data);
 0271        }
 272
 273        public void SendFriendDeleted(string fromUserId, string toUserId, PlayerActionSource source)
 274        {
 0275            PlayerType? fromPlayerType = GetPlayerTypeByUserId(fromUserId);
 0276            PlayerType? toPlayerType = GetPlayerTypeByUserId(toUserId);
 277
 0278            if (fromPlayerType == null || toPlayerType == null)
 0279                return;
 280
 0281            Dictionary<string, string> data = new Dictionary<string, string>();
 0282            data.Add("from", fromPlayerType.ToString());
 0283            data.Add("to", toPlayerType.ToString());
 0284            data.Add("source", source.ToString());
 285
 0286            analytics.SendAnalytic(FRIEND_DELETED, data);
 0287        }
 288
 289        public void SendPassportOpen()
 290        {
 0291            analytics.SendAnalytic(PASSPORT_OPENED, new Dictionary<string, string>());
 0292        }
 293
 294        public void SendPassportClose(double timeSpent)
 295        {
 0296            Dictionary<string, string> data = new Dictionary<string, string>();
 0297            data.Add("time_spent", timeSpent.ToString());
 298
 0299            analytics.SendAnalytic(PASSPORT_CLOSED, data);
 0300        }
 301
 302        public void SendPlayerBlocked(bool isFriend, PlayerActionSource source)
 303        {
 0304            Dictionary<string, string> data = new Dictionary<string, string>();
 0305            data.Add("friend", isFriend.ToString());
 0306            data.Add("source", source.ToString());
 307
 0308            analytics.SendAnalytic(PLAYER_BLOCKED, data);
 0309        }
 310
 311        public void SendPlayerUnblocked(bool isFriend, PlayerActionSource source)
 312        {
 0313            Dictionary<string, string> data = new Dictionary<string, string>();
 0314            data.Add("friend", isFriend.ToString());
 0315            data.Add("source", source.ToString());
 316
 0317            analytics.SendAnalytic(PLAYER_UNBLOCKED, data);
 0318        }
 319
 320        public void SendPlayerReport(PlayerReportIssueType issueType, double messageLength, PlayerActionSource source)
 321        {
 0322            Dictionary<string, string> data = new Dictionary<string, string>();
 0323            data.Add("issue_type", issueType.ToString());
 0324            data.Add("text_length", messageLength.ToString());
 0325            data.Add("source", source.ToString());
 326
 0327            analytics.SendAnalytic(PLAYER_REPORT, data);
 0328        }
 329
 330        public void SendPlayerJoin(PlayerActionSource source)
 331        {
 0332            Dictionary<string, string> data = new Dictionary<string, string>();
 0333            data.Add("source", source.ToString());
 334
 0335            analytics.SendAnalytic(PLAYER_JOIN, data);
 0336        }
 337
 338        public void SendPlayEmote(string emoteId, string emoteName, string rarity, bool isBaseEmote, UserProfile.EmoteSo
 339        {
 0340            Dictionary<string, string> data = new Dictionary<string, string>();
 0341            data.Add("id", emoteId);
 0342            data.Add("name", emoteName);
 0343            data.Add("rarity", rarity);
 0344            data.Add("isBase", isBaseEmote.ToString());
 0345            data.Add("source", source.ToString());
 0346            data.Add("parcel_location", parcelLocation);
 347
 0348            analytics.SendAnalytic(PLAY_EMOTE, data);
 0349        }
 350
 351        public void SendEmptyChannelCreated(string channelName, ChannelJoinedSource source)
 352        {
 0353            var data = new Dictionary<string, string>
 354            {
 355                ["source"] = source switch
 356                {
 0357                    ChannelJoinedSource.Command => "command",
 0358                    ChannelJoinedSource.Link => "link",
 0359                    ChannelJoinedSource.Search => "create_search",
 0360                    _ => ""
 361                },
 362                ["channel"] = channelName
 363            };
 0364            analytics.SendAnalytic(EMPTY_CHANNEL_CREATED, data);
 0365        }
 366
 367        public void SendPopulatedChannelJoined(string channelName, ChannelJoinedSource source, string method)
 368        {
 0369            var data = new Dictionary<string, string>
 370            {
 371                ["source"] = source switch
 372                {
 0373                    ChannelJoinedSource.Command => "command",
 0374                    ChannelJoinedSource.Link => "link",
 0375                    ChannelJoinedSource.Search => "search",
 0376                    ChannelJoinedSource.ConversationList => "conversation_list",
 0377                    _ => ""
 378                },
 379                ["channel"] = channelName,
 380                ["method"] = method
 381            };
 0382            analytics.SendAnalytic(POPULATED_CHANNEL_JOINED, data);
 0383        }
 384
 385        public void SendLeaveChannel(string channelId, ChannelLeaveSource source)
 386        {
 0387            var data = new Dictionary<string, string>
 388            {
 389                ["source"] = source switch
 390                {
 0391                    ChannelLeaveSource.Chat => "chat",
 0392                    ChannelLeaveSource.Command => "command",
 0393                    ChannelLeaveSource.Search => "search",
 0394                    ChannelLeaveSource.ConversationList => "conversation_list",
 0395                    _ => ""
 396                },
 397                ["channel"] = channelId
 398            };
 0399            analytics.SendAnalytic(CHANNEL_LEAVE, data);
 0400        }
 401
 402        public void SendChannelSearch(string text)
 403        {
 0404            var data = new Dictionary<string, string>
 405            {
 406                ["search"] = text
 407            };
 0408            analytics.SendAnalytic(CHANNEL_SEARCH, data);
 0409        }
 410
 411        public void SendChannelLinkClicked(string channel, bool joinAccepted, ChannelLinkSource source)
 412        {
 0413            var data = new Dictionary<string, string>
 414            {
 415                ["source"] = source switch
 416                {
 0417                    ChannelLinkSource.Chat => "chat",
 0418                    ChannelLinkSource.Event => "event",
 0419                    ChannelLinkSource.Place => "place",
 0420                    ChannelLinkSource.Profile => "profile",
 0421                    _ => ""
 422                },
 423                ["channel"] = channel,
 424                ["result"] = joinAccepted ? "joined" : "cancel"
 425            };
 0426            analytics.SendAnalytic(CHANNEL_LINK_CLICK, data);
 0427        }
 428
 429        private PlayerType? GetPlayerTypeByUserId(string userId)
 430        {
 0431            if (string.IsNullOrEmpty(userId))
 0432                return null;
 433
 0434            UserProfile userProfile = userProfileBridge.Get(userId);
 435
 0436            if (userProfile == null)
 0437                return null;
 0438            return userProfile.isGuest ? PlayerType.Guest : PlayerType.Wallet;
 439        }
 440    }
 441}

Methods/Properties

i()
i(SocialFeaturesAnalytics.SocialAnalytics)
SocialAnalytics(IAnalytics, IUserProfileBridge)
SendPlayerMuted(System.String)
SendPlayerUnmuted(System.String)
SendVoiceMessageStartedByFirstTime()
SendVoiceMessage(System.Double, SocialFeaturesAnalytics.VoiceMessageSource, System.String)
SendVoiceChannelConnection(System.Int32)
SendVoiceChannelDisconnection()
SendClickedOnCollectibles()
SendStartedConversation(SocialFeaturesAnalytics.PlayerActionSource)
SendNftBuy(SocialFeaturesAnalytics.PlayerActionSource)
SendInspectAvatar(System.Double)
SendLinkClick(SocialFeaturesAnalytics.PlayerActionSource)
SendCopyWallet(SocialFeaturesAnalytics.PlayerActionSource)
SendCopyUsername(SocialFeaturesAnalytics.PlayerActionSource)
SendJumpInToPlayer(SocialFeaturesAnalytics.PlayerActionSource)
SendProfileEdit(System.Int32, System.Boolean, SocialFeaturesAnalytics.PlayerActionSource)
SendVoiceChatPreferencesChanged(DCL.SettingsCommon.GeneralSettings/VoiceChatAllow)
SendFriendRequestError(System.String, System.String, System.String, System.String)
SendFriendRequestSent(System.String, System.String, System.Double, SocialFeaturesAnalytics.PlayerActionSource)
SendFriendRequestApproved(System.String, System.String, System.String, System.Boolean)
SendFriendRequestRejected(System.String, System.String, System.String, System.Boolean)
SendFriendRequestCancelled(System.String, System.String, System.String)
SendFriendDeleted(System.String, System.String, SocialFeaturesAnalytics.PlayerActionSource)
SendPassportOpen()
SendPassportClose(System.Double)
SendPlayerBlocked(System.Boolean, SocialFeaturesAnalytics.PlayerActionSource)
SendPlayerUnblocked(System.Boolean, SocialFeaturesAnalytics.PlayerActionSource)
SendPlayerReport(SocialFeaturesAnalytics.PlayerReportIssueType, System.Double, SocialFeaturesAnalytics.PlayerActionSource)
SendPlayerJoin(SocialFeaturesAnalytics.PlayerActionSource)
SendPlayEmote(System.String, System.String, System.String, System.Boolean, UserProfile/EmoteSource, System.String)
SendEmptyChannelCreated(System.String, DCL.ChannelJoinedSource)
SendPopulatedChannelJoined(System.String, DCL.ChannelJoinedSource, System.String)
SendLeaveChannel(System.String, DCL.ChannelLeaveSource)
SendChannelSearch(System.String)
SendChannelLinkClicked(System.String, System.Boolean, DCL.ChannelLinkSource)
GetPlayerTypeByUserId(System.String)