mirror of
https://github.com/laoxong/nofx.git
synced 2026-06-04 09:58:22 +08:00
feat: add channel dimension to GA4 AI usage tracking
Distinguish claw402, blockrun, and native direct API calls in telemetry.
This commit is contained in:
@@ -129,6 +129,7 @@ func Init() {
|
|||||||
telemetry.TrackAIUsage(telemetry.AIUsageEvent{
|
telemetry.TrackAIUsage(telemetry.AIUsageEvent{
|
||||||
ModelProvider: usage.Provider,
|
ModelProvider: usage.Provider,
|
||||||
ModelName: usage.Model,
|
ModelName: usage.Model,
|
||||||
|
Channel: usage.Channel(),
|
||||||
InputTokens: usage.PromptTokens,
|
InputTokens: usage.PromptTokens,
|
||||||
OutputTokens: usage.CompletionTokens,
|
OutputTokens: usage.CompletionTokens,
|
||||||
})
|
})
|
||||||
|
|||||||
+14
-1
@@ -44,13 +44,26 @@ var (
|
|||||||
|
|
||||||
// TokenUsage represents token usage from AI API response
|
// TokenUsage represents token usage from AI API response
|
||||||
type TokenUsage struct {
|
type TokenUsage struct {
|
||||||
Provider string
|
Provider string // payment channel: "claw402", "blockrun-base", "blockrun-sol", or native provider name
|
||||||
Model string
|
Model string
|
||||||
PromptTokens int
|
PromptTokens int
|
||||||
CompletionTokens int
|
CompletionTokens int
|
||||||
TotalTokens 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
|
// Client AI API configuration
|
||||||
type Client struct {
|
type Client struct {
|
||||||
Provider string
|
Provider string
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ type AIUsageEvent struct {
|
|||||||
TraderID string
|
TraderID string
|
||||||
ModelProvider string // openai, deepseek, anthropic, etc.
|
ModelProvider string // openai, deepseek, anthropic, etc.
|
||||||
ModelName string // gpt-4o, deepseek-chat, claude-3, etc.
|
ModelName string // gpt-4o, deepseek-chat, claude-3, etc.
|
||||||
|
Channel string // payment channel: "claw402", "blockrun", or "native"
|
||||||
InputTokens int
|
InputTokens int
|
||||||
OutputTokens int
|
OutputTokens int
|
||||||
}
|
}
|
||||||
@@ -214,6 +215,7 @@ func TrackAIUsage(event AIUsageEvent) {
|
|||||||
Params: map[string]interface{}{
|
Params: map[string]interface{}{
|
||||||
"model_provider": event.ModelProvider,
|
"model_provider": event.ModelProvider,
|
||||||
"model_name": event.ModelName,
|
"model_name": event.ModelName,
|
||||||
|
"channel": event.Channel,
|
||||||
"input_tokens": event.InputTokens,
|
"input_tokens": event.InputTokens,
|
||||||
"output_tokens": event.OutputTokens,
|
"output_tokens": event.OutputTokens,
|
||||||
"total_tokens": event.InputTokens + event.OutputTokens,
|
"total_tokens": event.InputTokens + event.OutputTokens,
|
||||||
|
|||||||
Reference in New Issue
Block a user