feat: add channel dimension to GA4 AI usage tracking

Distinguish claw402, blockrun, and native direct API calls in telemetry.
This commit is contained in:
tinkle-community
2026-03-16 15:19:49 +08:00
parent b8bc91f7a0
commit d5fbe445e1
3 changed files with 17 additions and 1 deletions

View File

@@ -44,13 +44,26 @@ var (
// TokenUsage represents token usage from AI API response
type TokenUsage struct {
Provider string
Provider string // payment channel: "claw402", "blockrun-base", "blockrun-sol", or native provider name
Model string
PromptTokens int
CompletionTokens int
TotalTokens int
}
// Channel returns the payment channel category for telemetry.
// Returns "claw402", "blockrun", or "native" based on the provider.
func (u TokenUsage) Channel() string {
switch u.Provider {
case ProviderClaw402:
return "claw402"
case ProviderBlockRunBase, ProviderBlockRunSol:
return "blockrun"
default:
return "native"
}
}
// Client AI API configuration
type Client struct {
Provider string