TopStats SDK
.NET analytics SDK
Multi-targets net8.0 and netstandard2.0, so the same package powers an ASP.NET Core API and mod-framework runtimes like CounterStrikeSharp and OpenMod. Capture buffers and a background loop batches; FlushAsync and ShutdownAsync drain deterministically.
Install
dotnet add package TopStats.Analytics # NuGet soon; CI-built feed todayCapture your first event
var client = new TopStatsClient(
Environment.GetEnvironmentVariable("TOPSTATS_API_KEY")!,
new TopStatsClientOptions { DefaultSource = "api" });
client.Capture("report_exported", new Dictionary<string, object?> { ["rows"] = 500 },
new CaptureContext { Actor = "user-3" });
await client.ShutdownAsync();Behaviour you can rely on
- Capture never throws into your code and never blocks on the network - a bounded queue buffers and a background loop batches.
- Retries only 429, 5xx and network failures, with jittered backoff honouring Retry-After; your API key never appears in error output.
- On netstandard2.0 System.Text.Json comes along as a dependency; net8.0 is BCL-only.
- The ASP.NET Core package adds UseTopStats() request analytics and DI-injectable custom capture.