Skip to content

Commit 148a321

Browse files
authored
feat: Add agent detection via env vars and tag GA4 with user property agent (#9070)
Add agent detection via env vars and tag GA4 with user property agent. Supported signals: - CODEX_SANDBOX -> codex_cli - CLAUDECODE -> claude_code - GEMINI_CLI -> gemini_cli - CURSOR_AGENT -> cursor - OPENCODE -> open_code
1 parent 59fa61e commit 148a321

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
- Support auth token JSON in `dataconnect_execute` MPC tool. (#9046)
22
- Fixed the bugs when MCP tools cannot connect to emulator due to CLI version mis-matched. (#9068)
33
- Fix bug when `firebase dataconnect:sdk:generate --watch` swallow all logs. (#9055)
4+
- Add GA4 agent user property to tag CLI usage by coding agents. (#9070)

src/track.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ import { logger } from "./logger";
77
import { isFirebaseStudio } from "./env";
88
const pkg = require("../package.json");
99

10+
// Detect if the CLI was invoked by a coding agent, based on well-known env vars.
11+
function detectAIAgent(): string {
12+
if (process.env.CODEX_SANDBOX) return "codex_cli";
13+
if (process.env.CLAUDECODE) return "claude_code";
14+
if (process.env.GEMINI_CLI) return "gemini_cli";
15+
if (process.env.CURSOR_AGENT) return "cursor";
16+
if (process.env.OPENCODE) return "open_code";
17+
return "unknown";
18+
}
19+
1020
type cliEventNames =
1121
| "command_execution"
1222
| "product_deploy"
@@ -85,6 +95,9 @@ const GA4_USER_PROPS = {
8595
is_firebase_studio: {
8696
value: isFirebaseStudio().toString(),
8797
},
98+
ai_agent: {
99+
value: detectAIAgent(),
100+
},
88101
};
89102

90103
export interface AnalyticsParams {

0 commit comments

Comments
 (0)