-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
395 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
Packages/com.walletconnect.web3modal/Runtime/Controllers/EventsController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Newtonsoft.Json; | ||
using UnityEngine; | ||
using WalletConnect.Web3Modal.Http; | ||
using WalletConnectUnity.Core; | ||
|
||
namespace WalletConnect.Web3Modal | ||
{ | ||
public class EventsController | ||
{ | ||
private const string BasePath = "https://pulse.walletconnect.org/"; | ||
private const int TimoutSeconds = 5; | ||
|
||
private readonly UnityHttpClient _httpClient = new(new Uri(BasePath), TimeSpan.FromSeconds(TimoutSeconds), new Web3ModalApiHeaderDecorator()); | ||
|
||
// private Queue<Event> _eventsQueue = new(); | ||
private AnalyticsState _state = AnalyticsState.Loading; | ||
|
||
public async Task InitializeAsync(Web3ModalConfig config, ApiController apiController) | ||
{ | ||
#if UNITY_WEBGL && !UNITY_EDITOR | ||
return; | ||
#endif | ||
|
||
if (!Web3Modal.Config.enableAnalytics) | ||
{ | ||
_state = AnalyticsState.Disabled; | ||
return; | ||
} | ||
|
||
await LoadRemoteAnalyticsConfig(apiController); | ||
} | ||
|
||
|
||
private async Task LoadRemoteAnalyticsConfig(ApiController apiController) | ||
{ | ||
try | ||
{ | ||
var response = await apiController.GetAnalyticsConfigAsync(); | ||
|
||
_state = response.isAnalyticsEnabled | ||
? AnalyticsState.Enabled | ||
: AnalyticsState.Disabled; | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.LogException(e); | ||
_state = AnalyticsState.Disabled; | ||
} | ||
} | ||
|
||
public async void SendEvent(Event @event) | ||
{ | ||
try | ||
{ | ||
if (_state == AnalyticsState.Disabled) | ||
return; | ||
|
||
var request = new EventRequest | ||
{ | ||
eventId = Guid.NewGuid().ToString(), | ||
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), | ||
bundleId = Application.identifier, | ||
props = @event | ||
}; | ||
|
||
var requestJson = JsonConvert.SerializeObject(request); | ||
|
||
Debug.Log($"[EventsController] Sending event: {@event.name}"); | ||
|
||
await _httpClient.PostAsync("e", requestJson); | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.LogException(e); | ||
} | ||
} | ||
|
||
private enum AnalyticsState | ||
{ | ||
Loading, | ||
Enabled, | ||
Disabled | ||
} | ||
} | ||
|
||
[Serializable] | ||
internal struct EventRequest | ||
{ | ||
public string eventId; | ||
public long timestamp; | ||
public string bundleId; | ||
public Event props; | ||
} | ||
|
||
[Serializable] | ||
public struct Event | ||
{ | ||
[JsonProperty("type")] | ||
public const string type = "track"; | ||
|
||
[JsonProperty("event")] | ||
public string name; | ||
|
||
[JsonProperty("properties")] | ||
public IDictionary<string, object> properties; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Packages/com.walletconnect.web3modal/Runtime/Controllers/EventsController.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.