Skip to content

Commit b93afb4

Browse files
committed
Wallet Analytics
1 parent a871da4 commit b93afb4

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

Assets/Thirdweb/Core/Scripts/Utils.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,5 +583,42 @@ public static BigInteger GweiToWei(double gweiAmount)
583583
{
584584
return new BigInteger(gweiAmount * 1e9);
585585
}
586+
587+
public static async void TrackWalletAnalytics(string clientId, string source, string action, string walletType, string walletAddress)
588+
{
589+
try
590+
{
591+
var body = new
592+
{
593+
source,
594+
action,
595+
walletAddress,
596+
walletType,
597+
};
598+
var headers = new Dictionary<string, string>
599+
{
600+
{ "x-client-id", clientId },
601+
{ "x-sdk-platform", "unity" },
602+
{ "x-sdk-name", "UnitySDK" },
603+
{ "x-sdk-version", ThirdwebSDK.version },
604+
{ "x-sdk-os", GetRuntimePlatform() },
605+
{ "x-bundle-id", GetBundleId() },
606+
};
607+
var request = new HttpRequestMessage(HttpMethod.Post, "https://c.thirdweb.com/event")
608+
{
609+
Content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json")
610+
};
611+
foreach (var header in headers)
612+
{
613+
request.Headers.Add(header.Key, header.Value);
614+
}
615+
using var client = new HttpClient();
616+
await client.SendAsync(request);
617+
}
618+
catch (System.Exception e)
619+
{
620+
ThirdwebDebug.LogWarning($"Failed to send wallet analytics: {e}");
621+
}
622+
}
586623
}
587624
}

Assets/Thirdweb/Core/Scripts/Wallet.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@ public async Task<string> Connect(WalletConnection walletConnection)
3636
}
3737
else
3838
{
39-
return await ThirdwebManager.Instance.SDK.session.Connect(walletConnection);
39+
string address = await ThirdwebManager.Instance.SDK.session.Connect(walletConnection);
40+
Utils.TrackWalletAnalytics(
41+
ThirdwebManager.Instance.SDK.session.Options.clientId,
42+
"connectWallet",
43+
"connect",
44+
walletConnection.provider.ToString()[..1].ToLower() + walletConnection.provider.ToString()[1..],
45+
address
46+
);
47+
return address;
4048
}
4149
}
4250

0 commit comments

Comments
 (0)