Skip to content

Commit 39c28d4

Browse files
committed
Enable pulse on desktop
1 parent ccd1309 commit 39c28d4

3 files changed

Lines changed: 25 additions & 7 deletions

File tree

Packages/com.walletconnect.web3modal/Runtime/Controllers/EventsController.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Newtonsoft.Json;
55
using UnityEngine;
66
using WalletConnect.Web3Modal.Http;
7+
using WalletConnectSharp.Common.Logging;
78

89
namespace WalletConnect.Web3Modal
910
{
@@ -12,9 +13,8 @@ public class EventsController
1213
private const string BasePath = "https://pulse.walletconnect.org/";
1314
private const int TimoutSeconds = 5;
1415

15-
private readonly UnityHttpClient _httpClient = new(new Uri(BasePath), TimeSpan.FromSeconds(TimoutSeconds), new Web3ModalApiHeaderDecorator());
16+
private readonly UnityHttpClient _httpClient = new(new Uri(BasePath), TimeSpan.FromSeconds(TimoutSeconds), new PulseApiHeaderDecorator());
1617

17-
// private Queue<Event> _eventsQueue = new();
1818
private AnalyticsState _state = AnalyticsState.Loading;
1919

2020
public async Task InitializeAsync(Web3ModalConfig config, ApiController apiController)
@@ -53,10 +53,6 @@ private async Task LoadRemoteAnalyticsConfig(ApiController apiController)
5353

5454
public async void SendEvent(Event @event)
5555
{
56-
#if !UNITY_IOS && !UNITY_ANDROID
57-
// Temporary disable analytics for non-mobile platforms
58-
return;
59-
#endif
6056
try
6157
{
6258
if (_state == AnalyticsState.Disabled)
@@ -66,13 +62,15 @@ public async void SendEvent(Event @event)
6662
{
6763
eventId = Guid.NewGuid().ToString(),
6864
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
65+
#if UNITY_ANDROID || UNITY_IOS || UNITY_VISIONOS
6966
bundleId = Application.identifier,
67+
#endif
7068
props = @event
7169
};
7270

7371
var requestJson = JsonConvert.SerializeObject(request);
7472

75-
Debug.Log($"[EventsController] Sending event: {@event.name}.\n\nRequest payload:\n {requestJson}");
73+
WCLogger.Log($"[EventsController] Sending event: {@event.name}.\n\nRequest payload:\n {requestJson}");
7674

7775
await _httpClient.PostAsync("e", requestJson);
7876
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using UnityEngine;
5+
6+
namespace WalletConnect.Web3Modal.Http
7+
{
8+
public class PulseApiHeaderDecorator : Web3ModalApiHeaderDecorator
9+
{
10+
protected override Task<HttpResponseContext> SendAsyncCore(HttpRequestContext requestContext, CancellationToken cancellationToken, Func<HttpRequestContext, CancellationToken, Task<HttpResponseContext>> next)
11+
{
12+
requestContext.RequestHeaders["x-sdk-platform"] = Application.isMobilePlatform ? "mobile" : "desktop";
13+
14+
return base.SendAsyncCore(requestContext, cancellationToken, next);
15+
}
16+
}
17+
}

Packages/com.walletconnect.web3modal/Runtime/Http/PulseApiHeaderDecorator.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)