Use generic product analytics event tracking in TUI

This commit is contained in:
James Chu
2026-04-27 18:34:26 -04:00
parent 847e9e0691
commit f69f3a9928
7 changed files with 51 additions and 52 deletions
+3 -4
View File
@@ -101,6 +101,7 @@ use codex_app_server_protocol::PluginReadParams;
use codex_app_server_protocol::PluginReadResponse;
use codex_app_server_protocol::PluginUninstallParams;
use codex_app_server_protocol::PluginUninstallResponse;
use codex_app_server_protocol::ProductAnalyticsEvent;
use codex_app_server_protocol::RequestId;
use codex_app_server_protocol::SendAddCreditsNudgeEmailParams;
use codex_app_server_protocol::ServerNotification;
@@ -112,13 +113,11 @@ use codex_app_server_protocol::ThreadLoadedListParams;
use codex_app_server_protocol::ThreadMemoryMode;
use codex_app_server_protocol::ThreadRollbackResponse;
use codex_app_server_protocol::ThreadStartSource;
use codex_app_server_protocol::TrackUsageLimitBannerAction;
use codex_app_server_protocol::TrackUsageLimitBannerParams;
use codex_app_server_protocol::TrackUsageLimitBannerResponse;
use codex_app_server_protocol::TrackProductAnalyticsEventParams;
use codex_app_server_protocol::TrackProductAnalyticsEventResponse;
use codex_app_server_protocol::Turn;
use codex_app_server_protocol::TurnError as AppServerTurnError;
use codex_app_server_protocol::TurnStatus;
use codex_app_server_protocol::UsageLimitBannerType;
use codex_config::ConfigLayerStackOrdering;
use codex_config::types::ApprovalsReviewer;
use codex_config::types::ModelAvailabilityNuxConfig;
+11 -16
View File
@@ -59,16 +59,15 @@ impl App {
});
}
pub(super) fn track_usage_limit_banner(
pub(super) fn track_product_analytics_event(
&mut self,
app_server: &AppServerSession,
action: TrackUsageLimitBannerAction,
banner_type: UsageLimitBannerType,
event: ProductAnalyticsEvent,
) {
let request_handle = app_server.request_handle();
tokio::spawn(async move {
if let Err(err) = track_usage_limit_banner(request_handle, action, banner_type).await {
tracing::warn!("failed to track usage limit banner event: {err:#}");
if let Err(err) = track_product_analytics_event(request_handle, event).await {
tracing::warn!("failed to track product analytics event: {err:#}");
}
});
}
@@ -465,22 +464,18 @@ pub(super) async fn send_add_credits_nudge_email(
Ok(response.status)
}
pub(super) async fn track_usage_limit_banner(
pub(super) async fn track_product_analytics_event(
request_handle: AppServerRequestHandle,
action: TrackUsageLimitBannerAction,
banner_type: UsageLimitBannerType,
event: ProductAnalyticsEvent,
) -> Result<()> {
let request_id = RequestId::String(format!("usage-limit-banner-{}", Uuid::new_v4()));
let _: TrackUsageLimitBannerResponse = request_handle
.request_typed(ClientRequest::TrackUsageLimitBanner {
let request_id = RequestId::String(format!("product-analytics-event-{}", Uuid::new_v4()));
let _: TrackProductAnalyticsEventResponse = request_handle
.request_typed(ClientRequest::TrackProductAnalyticsEvent {
request_id,
params: TrackUsageLimitBannerParams {
action,
banner_type,
},
params: TrackProductAnalyticsEventParams { event },
})
.await
.wrap_err("account/usageLimitBanner/track failed in TUI")?;
.wrap_err("analytics/productEvent/track failed in TUI")?;
Ok(())
}
+2 -5
View File
@@ -564,11 +564,8 @@ impl App {
self.send_add_credits_nudge_email(app_server, credit_type);
}
}
AppEvent::TrackUsageLimitBanner {
action,
banner_type,
} => {
self.track_usage_limit_banner(app_server, action, banner_type);
AppEvent::TrackProductAnalyticsEvent { event } => {
self.track_product_analytics_event(app_server, event);
}
AppEvent::AddCreditsNudgeEmailFinished { result } => {
self.chat_widget
+4 -6
View File
@@ -20,10 +20,9 @@ use codex_app_server_protocol::PluginListResponse;
use codex_app_server_protocol::PluginReadParams;
use codex_app_server_protocol::PluginReadResponse;
use codex_app_server_protocol::PluginUninstallResponse;
use codex_app_server_protocol::ProductAnalyticsEvent;
use codex_app_server_protocol::SkillsListResponse;
use codex_app_server_protocol::ThreadGoalStatus;
use codex_app_server_protocol::TrackUsageLimitBannerAction;
use codex_app_server_protocol::UsageLimitBannerType;
use codex_file_search::FileMatch;
use codex_protocol::ThreadId;
use codex_protocol::openai_models::ModelPreset;
@@ -236,10 +235,9 @@ pub(crate) enum AppEvent {
credit_type: AddCreditsNudgeCreditType,
},
/// Track an analytics event for the workspace-owner nudge prompt.
TrackUsageLimitBanner {
action: TrackUsageLimitBannerAction,
banner_type: UsageLimitBannerType,
/// Track a client-side product analytics event.
TrackProductAnalyticsEvent {
event: ProductAnalyticsEvent,
},
/// Result of notifying the workspace owner.
+14 -8
View File
@@ -99,6 +99,7 @@ use codex_app_server_protocol::McpServerStartupState;
use codex_app_server_protocol::McpServerStatusDetail;
use codex_app_server_protocol::McpServerStatusUpdatedNotification;
use codex_app_server_protocol::ModelVerification as AppServerModelVerification;
use codex_app_server_protocol::ProductAnalyticsEvent;
use codex_app_server_protocol::ServerNotification;
use codex_app_server_protocol::ServerRequest;
use codex_app_server_protocol::ThreadGoal as AppThreadGoal;
@@ -106,11 +107,11 @@ use codex_app_server_protocol::ThreadGoalStatus as AppThreadGoalStatus;
use codex_app_server_protocol::ThreadItem;
use codex_app_server_protocol::ThreadTokenUsage;
use codex_app_server_protocol::ToolRequestUserInputParams;
use codex_app_server_protocol::TrackUsageLimitBannerAction;
use codex_app_server_protocol::Turn;
use codex_app_server_protocol::TurnCompletedNotification;
use codex_app_server_protocol::TurnPlanStepStatus;
use codex_app_server_protocol::TurnStatus;
use codex_app_server_protocol::UsageLimitBannerAction;
use codex_app_server_protocol::UsageLimitBannerType;
use codex_chatgpt::connectors;
use codex_config::ConfigLayerStackOrdering;
@@ -8592,9 +8593,11 @@ impl ChatWidget {
}
};
let send_actions: Vec<SelectionAction> = vec![Box::new(move |tx| {
tx.send(AppEvent::TrackUsageLimitBanner {
action: TrackUsageLimitBannerAction::CtaClicked,
banner_type,
tx.send(AppEvent::TrackProductAnalyticsEvent {
event: ProductAnalyticsEvent::UsageLimitBanner {
action: UsageLimitBannerAction::CtaClicked,
banner_type,
},
});
tx.send(AppEvent::SendAddCreditsNudgeEmail { credit_type });
})];
@@ -8623,10 +8626,13 @@ impl ChatWidget {
initial_selected_idx: Some(1),
..Default::default()
});
self.app_event_tx.send(AppEvent::TrackUsageLimitBanner {
action: TrackUsageLimitBannerAction::Shown,
banner_type,
});
self.app_event_tx
.send(AppEvent::TrackProductAnalyticsEvent {
event: ProductAnalyticsEvent::UsageLimitBanner {
action: UsageLimitBannerAction::Shown,
banner_type,
},
});
}
pub(crate) fn start_add_credits_nudge_email_request(
+2 -1
View File
@@ -83,17 +83,18 @@ pub(super) use codex_app_server_protocol::PluginMarketplaceEntry;
pub(super) use codex_app_server_protocol::PluginReadResponse;
pub(super) use codex_app_server_protocol::PluginSource;
pub(super) use codex_app_server_protocol::PluginSummary;
pub(super) use codex_app_server_protocol::ProductAnalyticsEvent;
pub(super) use codex_app_server_protocol::ReasoningSummaryTextDeltaNotification;
pub(super) use codex_app_server_protocol::ServerNotification;
pub(super) use codex_app_server_protocol::SkillSummary;
pub(super) use codex_app_server_protocol::ThreadClosedNotification;
pub(super) use codex_app_server_protocol::ThreadItem as AppServerThreadItem;
pub(super) use codex_app_server_protocol::TrackUsageLimitBannerAction;
pub(super) use codex_app_server_protocol::Turn as AppServerTurn;
pub(super) use codex_app_server_protocol::TurnCompletedNotification;
pub(super) use codex_app_server_protocol::TurnError as AppServerTurnError;
pub(super) use codex_app_server_protocol::TurnStartedNotification;
pub(super) use codex_app_server_protocol::TurnStatus as AppServerTurnStatus;
pub(super) use codex_app_server_protocol::UsageLimitBannerAction;
pub(super) use codex_app_server_protocol::UsageLimitBannerType;
pub(super) use codex_app_server_protocol::UserInput as AppServerUserInput;
pub(super) use codex_app_server_protocol::WarningNotification;
@@ -607,7 +607,7 @@ async fn workspace_member_credits_depleted_prompts_and_sends_credits() {
assert_eq!(
event,
(
TrackUsageLimitBannerAction::Shown,
UsageLimitBannerAction::Shown,
UsageLimitBannerType::WorkspaceMemberCreditsDepleted
)
);
@@ -617,7 +617,7 @@ async fn workspace_member_credits_depleted_prompts_and_sends_credits() {
assert_eq!(
event,
(
TrackUsageLimitBannerAction::CtaClicked,
UsageLimitBannerAction::CtaClicked,
UsageLimitBannerType::WorkspaceMemberCreditsDepleted
)
);
@@ -643,7 +643,7 @@ async fn workspace_member_usage_limit_prompts_and_sends_usage_limit() {
assert_eq!(
event,
(
TrackUsageLimitBannerAction::Shown,
UsageLimitBannerAction::Shown,
UsageLimitBannerType::WorkspaceMemberUsageLimitReached
)
);
@@ -653,7 +653,7 @@ async fn workspace_member_usage_limit_prompts_and_sends_usage_limit() {
assert_eq!(
event,
(
TrackUsageLimitBannerAction::CtaClicked,
UsageLimitBannerAction::CtaClicked,
UsageLimitBannerType::WorkspaceMemberUsageLimitReached
)
);
@@ -812,7 +812,7 @@ async fn workspace_owner_nudge_default_no_dismisses_without_sending() {
assert_eq!(
event,
(
TrackUsageLimitBannerAction::Shown,
UsageLimitBannerAction::Shown,
UsageLimitBannerType::WorkspaceMemberCreditsDepleted
)
);
@@ -837,7 +837,7 @@ async fn workspace_owner_nudge_reappears_after_dismissing_no() {
assert_eq!(
event,
(
TrackUsageLimitBannerAction::Shown,
UsageLimitBannerAction::Shown,
UsageLimitBannerType::WorkspaceMemberUsageLimitReached
)
);
@@ -942,17 +942,20 @@ fn next_send_add_credits_nudge_email_event(
fn next_track_usage_limit_banner_event(
rx: &mut tokio::sync::mpsc::UnboundedReceiver<AppEvent>,
) -> (TrackUsageLimitBannerAction, UsageLimitBannerType) {
) -> (UsageLimitBannerAction, UsageLimitBannerType) {
while let Ok(event) = rx.try_recv() {
if let AppEvent::TrackUsageLimitBanner {
action,
banner_type,
if let AppEvent::TrackProductAnalyticsEvent {
event:
ProductAnalyticsEvent::UsageLimitBanner {
action,
banner_type,
},
} = event
{
return (action, banner_type);
}
}
panic!("expected TrackUsageLimitBanner app event");
panic!("expected usage-limit product analytics app event");
}
fn assert_no_owner_nudge_or_rate_limit_refresh(
@@ -964,7 +967,7 @@ fn assert_no_owner_nudge_or_rate_limit_refresh(
event,
AppEvent::SendAddCreditsNudgeEmail { .. }
| AppEvent::RefreshRateLimits { .. }
| AppEvent::TrackUsageLimitBanner { .. }
| AppEvent::TrackProductAnalyticsEvent { .. }
),
"unexpected event: {event:?}"
);