Skip to content

Commit

Permalink
Feat: used emotes analytics (#1598)
Browse files Browse the repository at this point in the history
## What does this PR change?

- add ECS System for triggered emotes (by player or by scene)
- add Decorator to handle equipped emote

## How to test the changes?

1. Launch the explorer
2. Verify "happy path" is not broken (and emotes are playing as previously - by player and by scene)
  • Loading branch information
popuz authored Aug 6, 2024
1 parent 9708dd7 commit c2f4cb3
Show file tree
Hide file tree
Showing 30 changed files with 320 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@

namespace DCL.AvatarRendering.Emotes
{
public enum TriggerSource
{
PREVIEW,
SELF,
REMOTE,
SCENE,
}

public struct CharacterEmoteIntent
{
public URN EmoteId;
public bool Spatial;
public TriggerSource TriggerSource;
}
}
10 changes: 5 additions & 5 deletions Explorer/Assets/DCL/AvatarRendering/Emotes/Emote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public class Emote : IEmote

public bool IsLoading { get; set; } = true;

public bool IsOnChain()
{
var id = ((IAvatarAttachment) this).GetUrn().ToString();
return id.StartsWith("urn:") && !id.StartsWith("urn:decentraland:off-chain:");
}
public bool IsOnChain() =>
IsOnChain(id: ((IAvatarAttachment) this).GetUrn().ToString());

public static bool IsOnChain(string id) =>
id.StartsWith("urn:") && !id.StartsWith("urn:decentraland:off-chain:");

public AvatarAttachmentDTO GetDTO() =>
Model.Asset!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ protected override void Update(float t)
ref CharacterEmoteIntent intention = ref World.AddOrGet<CharacterEmoteIntent>(entity);
intention.EmoteId = remoteEmoteIntention.EmoteId;
intention.Spatial = true;
intention.TriggerSource = TriggerSource.REMOTE;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private void TriggerEmote([Data] int emoteIndex, in Entity entity, in Profile pr

if (emoteId.IsNullOrEmpty()) return;

var newEmoteIntent = new CharacterEmoteIntent { EmoteId = emoteId, Spatial = true };
var newEmoteIntent = new CharacterEmoteIntent { EmoteId = emoteId, Spatial = true, TriggerSource = TriggerSource.SELF};
ref var emoteIntent = ref World.AddOrGet(entity, newEmoteIntent);
emoteIntent = newEmoteIntent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public AvatarController(AvatarView view,
AvatarSlotView[] slotViews,
NftTypeIconSO rarityBackgrounds,
BackpackCommandBus backpackCommandBus,
BackpackEventBus backpackEventBus,
IBackpackEventBus backpackEventBus,
BackpackGridController backpackGridController,
BackpackInfoPanelController backpackInfoPanelController,
IThumbnailProvider thumbnailProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ public interface IBackpackEventBus
public event Action<string> FilterCategoryEvent;
public event Action<string> SearchEvent;
public event Action<BackpackSections> ChangedBackpackSectionEvent;
public event Action<Color,string>? ChangeColorEvent;
public event Action<Color, string>? ChangeColorEvent;
public event Action UnEquipAllEvent;
event Action PublishProfileEvent;
event Action<AvatarWearableCategoryEnum>? FilterCategoryByEnumEvent;
event Action? DeactivateEvent;

public void SendWearableSelect(IWearable equipWearable);

Expand Down Expand Up @@ -52,5 +54,7 @@ public interface IBackpackEventBus
void SendEmoteSlotSelect(int slot);

public void SendChangedBackpackSectionEvent(BackpackSections backpackSections);

public void SendBackpackDeactivateEvent();
}
}
4 changes: 2 additions & 2 deletions Explorer/Assets/DCL/Backpack/BackpackController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class BackpackController : ISection, IDisposable
private readonly Dictionary<BackpackSections, ISection> backpackSections;
private readonly SectionSelectorController<BackpackSections> sectionSelectorController;
private readonly Dictionary<BackpackSections, TabSelectorView> tabsBySections;
private readonly BackpackEventBus backpackEventBus;
private readonly IBackpackEventBus backpackEventBus;
private BackpackSections lastShownSection;

private CancellationTokenSource? animationCts;
Expand All @@ -49,7 +49,7 @@ public BackpackController(
AvatarView avatarView,
NftTypeIconSO rarityInfoPanelBackgrounds,
BackpackCommandBus backpackCommandBus,
BackpackEventBus backpackEventBus,
IBackpackEventBus backpackEventBus,
BackpackGridController gridController,
BackpackInfoPanelController wearableInfoPanelController,
BackpackInfoPanelController emoteInfoPanelController,
Expand Down
4 changes: 2 additions & 2 deletions Explorer/Assets/DCL/Backpack/BackpackGridController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class BackpackGridController

private readonly BackpackGridView view;
private readonly BackpackCommandBus commandBus;
private readonly BackpackEventBus eventBus;
private readonly IBackpackEventBus eventBus;
private readonly IWeb3IdentityCache web3IdentityCache;
private readonly NftTypeIconSO rarityBackgrounds;
private readonly NFTColorsSO rarityColors;
Expand Down Expand Up @@ -70,7 +70,7 @@ public class BackpackGridController
public BackpackGridController(
BackpackGridView view,
BackpackCommandBus commandBus,
BackpackEventBus eventBus,
IBackpackEventBus eventBus,
IWeb3IdentityCache web3IdentityCache,
NftTypeIconSO rarityBackgrounds,
NFTColorsSO rarityColors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class BackpackInfoPanelController : IDisposable
private const string EMOTE_CATEGORY = "emote";

private readonly BackpackInfoPanelView view;
private readonly BackpackEventBus backpackEventBus;
private readonly IBackpackEventBus backpackEventBus;
private readonly NftTypeIconSO categoryIcons;
private readonly NftTypeIconSO rarityInfoPanelBackgrounds;
private readonly NFTColorsSO rarityColors;
Expand All @@ -26,7 +26,7 @@ public class BackpackInfoPanelController : IDisposable

public BackpackInfoPanelController(
BackpackInfoPanelView view,
BackpackEventBus backpackEventBus,
IBackpackEventBus backpackEventBus,
NftTypeIconSO categoryIcons,
NftTypeIconSO rarityInfoPanelBackgrounds,
NFTColorsSO rarityColors,
Expand Down
4 changes: 2 additions & 2 deletions Explorer/Assets/DCL/Backpack/BackpackSlotsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class BackpackSlotsController : IDisposable
private const int MAX_HIDES = 15;

private readonly BackpackCommandBus backpackCommandBus;
private readonly BackpackEventBus backpackEventBus;
private readonly IBackpackEventBus backpackEventBus;
private readonly NftTypeIconSO rarityBackgrounds;
private readonly IThumbnailProvider thumbnailProvider;
private readonly Dictionary<string, (AvatarSlotView, CancellationTokenSource)> avatarSlots = new ();
Expand All @@ -29,7 +29,7 @@ public class BackpackSlotsController : IDisposable
public BackpackSlotsController(
AvatarSlotView[] avatarSlotViews,
BackpackCommandBus backpackCommandBus,
BackpackEventBus backpackEventBus,
IBackpackEventBus backpackEventBus,
NftTypeIconSO rarityBackgrounds,
IThumbnailProvider thumbnailProvider)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ namespace DCL.Backpack.CharacterPreview
{
public class BackpackCharacterPreviewController : CharacterPreviewControllerBase
{
private readonly BackpackEventBus backpackEventBus;
private readonly IBackpackEventBus backpackEventBus;
private readonly IEquippedEmotes equippedEmotes;
private CancellationTokenSource? emotePreviewCancellationToken;

public BackpackCharacterPreviewController(CharacterPreviewView view,
ICharacterPreviewFactory previewFactory,
BackpackEventBus backpackEventBus,
IBackpackEventBus backpackEventBus,
World world,
IEquippedEmotes equippedEmotes,
CharacterPreviewEventBus characterPreviewEventBus)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class BackpackEmoteGridController : IDisposable

private readonly BackpackGridView view;
private readonly BackpackCommandBus commandBus;
private readonly BackpackEventBus eventBus;
private readonly IBackpackEventBus eventBus;
private readonly IWeb3IdentityCache web3IdentityCache;
private readonly NftTypeIconSO rarityBackgrounds;
private readonly NFTColorsSO rarityColors;
Expand All @@ -52,7 +52,7 @@ public class BackpackEmoteGridController : IDisposable
public BackpackEmoteGridController(
BackpackGridView view,
BackpackCommandBus commandBus,
BackpackEventBus eventBus,
IBackpackEventBus eventBus,
IWeb3IdentityCache web3IdentityCache,
NftTypeIconSO rarityBackgrounds,
NFTColorsSO rarityColors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class BackpackEmoteSlotsController : IDisposable
{
private const int MIN_WAIT_TIME = 500;

private readonly BackpackEventBus backpackEventBus;
private readonly IBackpackEventBus backpackEventBus;
private readonly IBackpackCommandBus backpackCommandBus;
private readonly NftTypeIconSO rarityBackgrounds;
private readonly (EmoteSlotContainerView, CancellationTokenSource)[] avatarSlots;
Expand All @@ -20,7 +20,7 @@ public class BackpackEmoteSlotsController : IDisposable

public BackpackEmoteSlotsController(
EmoteSlotContainerView[] avatarSlotViews,
BackpackEventBus backpackEventBus,
IBackpackEventBus backpackEventBus,
IBackpackCommandBus backpackCommandBus,
NftTypeIconSO rarityBackgrounds)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private async UniTask WaitForAvatarInstantiatedAsync(CancellationToken ct)

public void PlayEmote(string emoteId)
{
globalWorld.Add(characterPreviewEntity, new CharacterEmoteIntent { EmoteId = emoteId });
globalWorld.Add(characterPreviewEntity, new CharacterEmoteIntent { EmoteId = emoteId, TriggerSource = TriggerSource.PREVIEW});
}

public void StopEmotes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ MonoBehaviour:
isEnabled: 1
- eventName: passport_opened
isEnabled: 1
- groupName: Wearables
events:
- eventName: used_emote
isEnabled: 1
useLocalEnvVariableFallback: 0
flushSize: 20
flushInterval: 30
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DCL.Web3.Identities;
#nullable enable
using DCL.Web3.Identities;
using ECS;
using JetBrains.Annotations;
using Segment.Serialization;
Expand Down Expand Up @@ -36,21 +37,21 @@ public AnalyticsController(IAnalyticsService analyticsService, AnalyticsConfigur
});
}

public void SetCommonParam(IRealmData realmData, [CanBeNull] IWeb3IdentityCache identityCache, ExposedTransform playerTransform)
public void SetCommonParam(IRealmData realmData, IWeb3IdentityCache? identityCache, ExposedTransform playerTransform)
{
analytics.AddPlugin(new DynamicCommonTraitsPlugin(realmData, identityCache, playerTransform));

if (identityCache != null)
Identify(identityCache.Identity);
}

public void Track(string eventName, JsonObject properties = null)
public void Track(string eventName, JsonObject? properties = null)
{
if (Configuration.EventIsEnabled(eventName))
analytics.Track(eventName, properties);
}

public void Identify(IWeb3Identity identity)
public void Identify(IWeb3Identity? identity)
{
if (identity != null)
analytics.Identify(identity.Address, new JsonObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public static class World
public const string TIME_SPENT_IN_WORLD = "time_spent_in_world";
}

public static class Wearables
{
public const string USED_EMOTE = "used_emote";
}

public static class UI
{
public const string MESSAGE_SENT = "chat_message_sent";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
"GUID:9ca29a7d75ab84bab806a20bbd350fd8",
"GUID:d0ec51c740809fd4680d3ea27279dca7",
"GUID:007bff6000804d90ac597452fb69a4ee",
"GUID:ae249ee11a6e0ea4aa01cefc0246a151"
"GUID:ae249ee11a6e0ea4aa01cefc0246a151",
"GUID:5eabe9a3d4dd19d42a16208ea5411062",
"GUID:6830e2f56251b492e9934f1fafbc8c7d",
"GUID:45fc0f02fe4e57c4a93a421d8f6f53df",
"GUID:e169fa6683c924c7e99a85981a91d953"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
Loading

0 comments on commit c2f4cb3

Please sign in to comment.