mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-25 08:49:36 +00:00
feat(telemetry): track API credit top-up success via audit events (#6500)
Summary - Add TelemetryEvents.API_CREDIT_TOPUP_SUCCEEDED and provider method trackApiCreditTopupSucceeded - Introduce topupTrackerStore to persist pending top-ups per user (localStorage) and reconcile against recent audit logs - Hook purchase flow to start tracking before opening Stripe checkout - Reconcile after fetching audit events (UsageLogsTable) and after fetchBalance, then emit telemetry, refresh balance, and clear pending - Minor refactor in customerEventsService to return awaited result Implementation details - Matching strategy: - Event type: credit_added - Time window: createdAt between top-up start time and +24h - Amount: if known, e.params.amount must equal expected cents - Cross-tab/user changes: synchronize via storage event and userId watcher Limitations / Follow-up - Reconciliation fetches only page 1 (limit 10) of events; in high-volume cases, a recent credit_added could fall outside the first page - The window and pagination issue will be "resolved by a followup PR to core and cloud" Files touched - src/stores/topupTrackerStore.ts (new) - src/components/dialog/content/setting/UsageLogsTable.vue - src/composables/auth/useFirebaseAuthActions.ts - src/platform/telemetry/providers/cloud/MixpanelTelemetryProvider.ts - src/platform/telemetry/types.ts - src/services/customerEventsService.ts ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6500-feat-telemetry-track-API-credit-top-up-success-via-audit-events-29e6d73d365081169941efae70cf71fe) by [Unito](https://www.unito.io) --------- Co-authored-by: Christian Byrne <chrbyrne96@gmail.com> Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import type { OverridedMixpanel } from 'mixpanel-browser'
|
||||
|
||||
import { useCurrentUser } from '@/composables/auth/useCurrentUser'
|
||||
import {
|
||||
checkForCompletedTopup as checkTopupUtil,
|
||||
clearTopupTracking as clearTopupUtil,
|
||||
startTopupTracking as startTopupUtil
|
||||
} from '@/platform/telemetry/topupTracker'
|
||||
import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
|
||||
import { useWorkflowTemplatesStore } from '@/platform/workflow/templates/repositories/workflowTemplatesStore'
|
||||
import { app } from '@/scripts/app'
|
||||
@@ -172,6 +177,23 @@ export class MixpanelTelemetryProvider implements TelemetryProvider {
|
||||
)
|
||||
}
|
||||
|
||||
trackApiCreditTopupSucceeded(): void {
|
||||
this.trackEvent(TelemetryEvents.API_CREDIT_TOPUP_SUCCEEDED)
|
||||
}
|
||||
|
||||
// Credit top-up tracking methods (composition with utility functions)
|
||||
startTopupTracking(): void {
|
||||
startTopupUtil()
|
||||
}
|
||||
|
||||
checkForCompletedTopup(events: any[] | undefined | null): boolean {
|
||||
return checkTopupUtil(events)
|
||||
}
|
||||
|
||||
clearTopupTracking(): void {
|
||||
clearTopupUtil()
|
||||
}
|
||||
|
||||
trackRunButton(options?: { subscribe_to_run?: boolean }): void {
|
||||
const executionContext = this.getExecutionContext()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user