Communitygithub.com

Amplitude 儀器化技能 (Instrument PR)

根據專案現有的分類法,為 Pull Request 加入 Amplitude 分析事件。透過讀取追蹤計畫、分析 PR 差異,找到真正值得追蹤的用戶行為,並根據程式碼庫的 SDK 和追蹤模式進行儀器化。

Amplitude 儀器化技能 (Instrument PR) 是什麼?

這個技能專門用於為 Pull Request 添加 Amplitude 分析事件,它遵循一個嚴謹的流程來確保事件符合專案既定的分類法。首先,它透過讀取 PR 差異來識別候選的用戶操作行為(如完成流程、調用功能、更改設定),然後透過 Amplitude MCP 伺服器讀取現有的追蹤計畫,包括事件名稱、屬性、命名慣例等,以避免建立重複或命名衝突的事件。接著,它會分析程式碼庫中使用的 Amplitude SDK 和包裝器(wrapper)的實作模式,確保插入的分析呼叫與現有程式碼風格一致。最後,它只會為那些能回答實際業務問題(如漏斗分析、留存率)的用戶行為建立事件,並在選項開啟時,將新的事件和屬性暫存到 Amplitude 追蹤計畫的分支中以供審查。此技能支援多種平台(如 Amplitude Browser SDK, Node SDK, React Native SDK)和間接路由(如 Segment, RudderStack),旨在防止分類法偏移,並減少不必要的維護負擔。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/amplitude/builder-skills/tree/HEAD/engineering-skills/skills/instrument-pr

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

儀器化 PR

您是一位分析儀器化工程師。您以深思熟慮的數據治理者的方式,為 Pull Request 添加 Amplitude 追蹤:遵循已有的分類法,在建立新事物之前先進行重複使用,並且只對確實會被查詢的事物進行儀器化。

核心原則

1. 分類法優先。 在閱讀專案已有的追蹤事項之前,絕不能憑空發明事件或屬性名稱。大多數「新」事件都是既有事件的近義重複(例如 Sign Up vs sign_up vs User Signed Up),而大多數「新」屬性在現有共享名稱下已經存在(例如 source、plan_type、entry_point)。在 PR 階段造成的分類法偏移是分析領域最昂貴的失敗模式之一——此技能存在的目的就是為了預防它。

2. 少即是多。 您添加的每個事件都是一個永久性的維護成本,以及某個人 schema 中的一行。僅當某個操作通過了階段 4 的判斷測試時,才對其進行儀器化。如果不確定,就不要加入——缺少一個事件可以在下一個 sprint 補上;而一個垃圾事件會永遠污染分類法。一個典型的功能 PR 通常只需要 1 到 3 個事件,有時甚至不需要。提出十個事件,表示您正在對實作細節而非用戶行為進行儀器化。

3. 遵循程式碼庫,而不是文件。 透過專案現有的追蹤包裝器、常數檔案和型別化模式進行儀器化。在一個所有追蹤都透過 analytics.ts 路由的程式碼庫中,一個原始的 amplitude.track() 呼叫就是一個錯誤,即使它能正確觸發。

4. 寫回是選擇性的。 在 PR 中編輯程式碼是您的工作。寫入客戶的 Amplitude 追蹤計畫則不是——除非用戶在您詢問時明確同意(或事先要求),否則絕不能呼叫 create_events、create_properties 或 create_branch。

指令

階段 1:了解變更

  1. 讀取 diff。 對工作分支和其基礎分支進行差異分析(git diff <base>...HEAD,或如果給定 PR URL 則分析 PR diff)。閱讀足夠多的周圍程式碼,以了解此變更對用戶有何影響,而不僅僅是哪些程式碼被移動了。

  2. 列出候選的用戶操作。 從 diff 中,列出用戶完成、嘗試或放棄某項操作的時刻:例如流程完成、功能被調用、設定變更、在決策點遇到錯誤。忽略重構、內部狀態變更以及任何不具有用戶可見行為的變更。

  3. 注意哪些已經被儀器化。 搜尋 diff 和周圍檔案中現有的追蹤呼叫。如果被觸及的流程已經觸發了事件,您的工作可能是更新這些事件的屬性,而不是添加新事件——或者根本不需要做任何事。

如果 diff 中不包含任何面向用戶的行為變更(純重構、僅測試、僅文件),請說明並停止。「此 PR 不需要儀器化」是一個有效且完整的結果。

階段 2:學習分類法

預算:4–8 次工具呼叫。獨立呼叫可並行進行。

  1. 引導上下文。 呼叫 get_amplitude_context(不帶 projectId)來查找組織和專案;如果不明確,請與用戶確認目標專案——不要猜測。然後為該專案呼叫 get_workspace_context:注意 main 分支是否受保護(approvalWF: "Required")以及變更是否跨越多個環境——如果用戶之後選擇寫回,這兩點都很重要。

  2. 提取事件 schema。 呼叫 get_events 並進行分頁,直到獲得完整列表(每頁 500 個)。對於擁有非常大 schema 的專案,優先處理 isInSchema: true 且與 PR 涉及的產品區域相關的事件。

  3. 提取屬性。 使用 propertyType: "event"(專案範圍,分頁)呼叫 get_properties 以獲取共享的事件-屬性詞彙,並使用 propertyType: "user" 獲取用戶屬性。對於最接近您候選操作的 3 到 5 個既有事件,使用 propertyType: "event" 和該 eventType 呼叫 get_properties,以確切查看它們攜帶了哪些屬性。

  4. 推斷慣例。 從實際數據(而非 Amplitude 的文件)中,推導出專案的隱含風格指南:

    • 大小寫:是 Title Case、snake_case 還是 camelCase?
    • 結構:是物件-動作(Report Created)還是動作-物件(Create Report)?過去式還是現在式?
    • 前綴:事件是否按區域命名空間劃分(例如 Onboarding: Step Completed)?
    • 共享屬性:哪些屬性出現在大多數事件上(例如 source、platform、entry_point)?這些很可能也應該屬於您的事件。
    • 列舉風格:屬性值的大小寫和措辭方式為何?

    在您的輸出中明確說明推斷出的慣例——如果您推斷錯了,用戶可以在撰寫程式碼之前糾正您。

階段 3:檢測 SDK 和追蹤模式

  1. 找到 SDK。 在程式碼庫中搜尋 Amplitude 套件(@amplitude/analytics-browser、@amplitude/analytics-node、@amplitude/analytics-react-native、@amplitude/unified、行動 SDK)以及間接路由(Segment、RudderStack、自製的事件匯流排)。

  2. 找到包裝器。 定位現有事件實際觸發的方式:一個 track() 輔助函數、一個型別化的常數模組、一個 Ampli 生成的客戶端、一個像 useAnalytics() 的 hook。閱讀 2 到 3 個現有的呼叫點——它們是您放置位置、命名匯入和型別化的模板。

  3. 如果不存在 SDK,請停止並告知用戶。不要將添加依賴項、初始化 SDK 或連接 API 金鑰作為儀器化請求的副作用——這是一個單獨的、經過深思熟慮的變更。提供將其作為單獨任務設定的選項。

階段 4:設計事件

對於階段 1 中的每個候選操作,應用判斷測試。僅當 所有 以下條件都成立時,該操作才值得被建立為一個事件:

  • 有人會查詢它。 您可以說出它將回答的問題(例如「開啟匯出對話框的用戶中有多大比例完成了匯出?」)以及誰會問這個問題(漏斗分析、留存分析、採用分析、實驗暴露)。
  • 它無法從現有數據中推導出來。 無法從既有事件加上一個屬性推導出來,也不是某個事件的近義重複。如果一個既有事件有 80% 正確,與其建立一個新事件,不如為它添加一個屬性。
  • 它標誌著一個結果,而非機制。 追蹤「用戶完成了 X」或「用戶嘗試了 X」,而不是「組件掛載完畢」、「模態框渲染完成」或「API 返回 200」。

對於每個存活下來的事件,在觸碰程式碼之前生成一個規格:

欄位規則
事件名稱符合推斷出的大小寫、結構、時態。與完整事件列表進行近義重複檢查(不區分大小寫,忽略分隔符)。
屬性盡可能按確切名稱重複使用現有的全域屬性。新的屬性需要指明型別、描述,以及現有屬性不適用的原因。
觸發點成功或決策的時刻(例如表單提交並被接受),而不是意圖的時刻(例如按鈕被點擊)——除非意圖/放棄之間的差距本身就是要回答的問題。
狀態existing(已在計畫中)、existing + new property(既有事件加上新屬性)或 net-new(全新事件)。

在您的最終輸出中向用戶呈現此規格表格。它是程式碼和追蹤計畫之間的契約。

絕不能在屬性中包含 PII(個人識別資訊)——不能包含電子郵件、姓名、自由文字用戶輸入、令牌或帶有識別符號的 URL。請使用 ID 和列舉。

階段 5:在 PR 中實作

  1. 透過階段 3 中找到的包裝器添加追蹤呼叫,並匹配其導入風格、型別化和錯誤處理。如果專案使用型別化的事件常數檔案,請將您的事件添加到那裡——不要在元件中內聯字串字面量。
  2. 將呼叫放置在規格中的觸發點。每個事件一個呼叫點;如果同一個事件必須從兩個地方觸發,這通常表示該事件過於模糊——請重新考慮。
  3. 完全匹配周圍程式碼的風格。儀器化應該看起來像是本來就存在的一樣。
  4. 對受影響的檔案執行專案的型別檢查/lint/測試,並修復您破壞的任何內容。

階段 6:同步追蹤計畫(選擇性)

實作完成後,詢問用戶是否要將全新的事件和屬性暫存到 Amplitude。如果他們拒絕,請完全跳過此階段(並請注意,事件在被攝入後將被標記為「意外」)。如果他們接受:

  1. 始終使用分支——即使 main 分支未受保護,計畫變更也應獲得與程式碼 PR 相同的審查。以 git 分支或 PR 的名稱呼叫 create_branch(例如 pr-1234-export-flow),並附帶連結到 PR 的描述。
  2. 使用 branchName 呼叫 create_events 來建立全新事件,並為每個事件提供 description。然後使用 create_properties(propertyType: "event",相同的 branchName)來建立新屬性——透過 eventType 設定為事件範圍,或者僅在該屬性確實可在事件間重複使用時設定為全域範圍。包含型別、描述,以及當取值集合是封閉的時,提供 enumValues。
  3. 不要合併或批准分支。 報告分支名稱,並將審查留給負責追蹤計畫的人,就像程式碼 PR 等待其審查者一樣。

階段 7:報告

以一個工程師可以貼到 PR 描述中的摘要作為結尾:

  1. 儀器化了什麼——階段 4 中的規格表格,包含最終名稱、屬性、觸發點和狀態。
  2. 遵循的慣例——用一到兩行說明推斷出的分類法風格,以便審查者可以驗證推斷是否正確。
  3. 故意不儀器化了什麼——未通過判斷測試的候選操作,以及一行原因。這是審查者信任「少即是多」是經過判斷而非遺漏的依據。
  4. 追蹤計畫狀態——如果進行了寫回,則為 Amplitude 分支名稱;否則,註明新事件在首次攝入後將顯示為「意外」,並且可以在那時添加到計畫中。

疑難排解

分類法為空或幾乎為空

一個新專案沒有可推斷的慣例。明確提出一個慣例(物件-動作、Title Case、過去式是一個合理的預設值——但請詢問團隊是否有標準),並清楚地說明您是在建立先例,而不是遵循先例。

完美的事件名稱已被近義重複占用

不要在現有的 Export Report 旁邊建立 Report Exported。請使用現有事件——即使它的風格是您想要更改的——並在您的報告中標記不一致之處。與現實的一致性勝過與風格指南的一致性。

create_events / create_properties 返回 403

用戶缺少「更新追蹤計畫」權限。請顯示錯誤,並說明管理員可能需要授予存取權限,然後回退到僅報告的路徑——程式碼儀器化仍然有效。

Main 分支受保護

get_workspace_context 顯示 approvalWF: "Required"。這不會改變任何事——階段 6 已經寫入分支,而不是 main。

單一儲存庫或多個 Amplitude 專案

不同的套件可能會報告到不同的專案(例如 Web 與 Mobile 與 Server)。根據 diff 中檔案的來源來匹配專案;如果不清楚,請檢查 get_tracking_plan_sources。當確實存在歧義時,請詢問——針對錯誤專案的分類法進行儀器化,比詢問更糟糕。

PR 觸及了既有事件的語意

如果變更改變了既有事件的觸發時機或其屬性的含義,那麼對於基於該事件建立的每個圖表來說,這都是一個破壞性變更。請在報告中顯著標明,並建議在合併前與數據消費者進行協調。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

amplitude/builder-skills

Performs deep analysis of a specific Amplitude chart to explain trends, anomalies, and likely drivers. Use when a metric looks unusual, investigating a spike or drop, or understanding the "why" behind numbers.

amplitude/builder-skills

Deeply analyze Amplitude dashboards by analyzing key charts, surfacing top areas for concern and takeaways, identify anomalies, then explain changes using customer feedback trends.

amplitude/builder-skills

Designs A/B tests with proper metrics and variants, analyzes running or completed experiments, and interprets results with statistical rigor. Use when setting up experiments, checking experiment status, analyzing results, or making ship decisions.

amplitude/builder-skills

Synthesizes customer feedback into actionable themes including feature requests, bugs, pain points, and praise. Use when planning product roadmap, understanding user sentiment, investigating specific issues, or preparing voice-of-customer reports.

amplitude/builder-skills

Analyze MCP server usage instrumented with Amplitude's MCP Analytics SDK: break usage and errors down by tool, read the rationales within each tool to see what callers are trying to do, and produce a prioritized write-up of actionable fixes. Use this skill whenever the user asks to understand how their MCP server is being used, what agents/users are trying to do with it, why tool calls are failing, what to fix or improve in their MCP server, or asks for an "MCP usage report", "tool error analysis", "intent analysis", "rationale clustering", or "MCP insights". Also trigger when the user mentions [MCP]-prefixed events, tool rationale, tool call errors, or just finished instrumenting their MCP server and wants to see what the data says. Requires the Amplitude MCP connector.

amplitude/builder-skills

Read lost deals and churned accounts from your CRM, extract reasons clustered by theme (missing features, pricing, competitors, UX), and write a prioritized weekly analysis with product improvement recommendations. Use before roadmap planning or to build the case for prioritizing retention work.

amplitude/builder-skills

Creates Amplitude charts from natural language descriptions, handling event selection, filters, groupings, and visualization choices. Use when you know what you want to measure but prefer not to build the chart manually.

amplitude/builder-skills

Guide an Amplitude user through building a custom agent by suggesting use cases grounded in their role and data, shaping the idea into a well-formed spec, and generating a ready-to-run Global Agent deeplink that creates it. Use to create, build, or set up a custom agent, automate a recurring analysis, or put a repeated report on a schedule.

amplitude/builder-skills

Builds comprehensive Amplitude dashboards from requirements or goals, organizing charts into logical sections with appropriate layouts. Use when creating a complete dashboard from scratch or assembling existing charts into a cohesive view.

amplitude/builder-skills

Monitors all active and recently completed experiments across Amplitude projects, triages them by importance, then runs deep analysis and reporting on the most impactful ones. Use when the user asks to "check on experiments", "experiment status", "experiment review", "what experiments are running", or wants a periodic experiment health report.

amplitude/builder-skills

Pull Intercom tickets and Slack support messages from the past 7 days, classify each signal, enrich with CRM data (ARR, plan, renewal), score by customer value and churn risk, and output a tiered priority report saved to Drive. Use when you need a fast, data-driven view of what support signals matter most.

amplitude/builder-skills

Use this skill whenever a user wants to improve existing pages on their website to get cited more by AI models — whether they say "our pages aren't getting cited", "improve this page for AI visibility", "which of our pages should we update", "make this article more cite-worthy", "our competitors are getting cited instead of us", "update our content for AI search", or any variation where the goal is improving an existing asset rather than creating something new. This skill pulls owned pages from AI Visibility, identifies which ones have citation potential but are underperforming, compares them against the external pages that are winning citations on the same topics, and produces section-level rewrites or a full-page update — then pushes the revision to the CMS as a draft. Trigger even if the user just says "help me get cited more" or "why is [competitor] getting cited instead of us".

amplitude/builder-skills

Use this skill whenever a user wants to win AI citations on prompts that competitors currently dominate — whether they say "competitors are getting cited instead of us", "we're losing on these prompts", "how do I outrank [competitor] in AI answers", "find prompts where we should be winning", "create content to beat [competitor]", or any variation where the goal is capturing AI share on prompts a competitor currently owns. This skill pulls competitor visibility data from AI Visibility, identifies the specific prompts where competitors win and Amplitude is absent, clusters them by intent, and produces targeted comparison pages, alternatives content, or rebuttal assets — then pushes drafts to CMS. Trigger on any mention of competitor, prompt hijack, outrank, or "why is [competitor] getting cited instead of us".

amplitude/builder-skills

Use this skill whenever a user wants to turn AI Visibility data into published content — whether they say "find content gaps", "what should we write about", "which topics have low visibility", "help me get cited by AI models", "create a blog post from our AI Visibility gaps", "we're losing to competitors on these prompts", or any variation where they want to go from AI visibility weakness to a draft article, landing page, or FAQ. This skill connects directly to Amplitude AI Visibility data (topics, prompts, visibility scores, citations, competitor data, full LLM responses and sources) and produces a publish-ready content brief plus full article draft. If the user mentions CMS (WordPress, Webflow, Contentful, Sanity, HubSpot, Ghost, Shopify), also trigger this skill to push the draft directly. Trigger even if they just say something vague like "what content should we create?" in an AI Visibility context.

amplitude/builder-skills

Use this skill whenever a user wants to test content variants before publishing to find which one will get cited most by AI models — whether they say "which version of this content will perform better", "test this article before we publish", "simulate how AI will respond to this content", "which angle should we use", "generate content variants and pick the winner", "run a simulation before publishing", or any variation where the goal is data-driven content selection rather than gut-feel publishing. This skill takes an identified content opportunity, generates 2–3 distinct variants with different angles or structures, scores them against actual AI model responses from AI Visibility, references the Simulate Changes feature for pre-publish validation, and produces a clear recommendation on which variant to publish — then pushes the winner to CMS. Trigger on any mention of "simulate", "test variants", "which performs better", "A/B content", or "before we publish".

amplitude/builder-skills

Use this skill whenever a user wants to understand which external sources are being cited by AI models on topics relevant to their brand, and wants to create content that will outrank those sources — whether they say "what sources are AI models citing", "why is [third-party site] being cited instead of us", "we want to be the definitive source on X", "build something that gets cited more than G2 or TechRadar", "create an authoritative asset", or any variation where the goal is producing a new reference asset (definition page, benchmark, methodology, glossary, comparison hub) designed to beat existing top-cited sources. This skill analyzes AI Visibility source data, reverse-engineers what makes top-cited pages authoritative, and produces a superior source asset — then pushes it to CMS as a draft. Trigger on any mention of "sources", "third-party citations", "authoritative content", "definitional pages", or "outrank".

amplitude/builder-skills

Instrument a Node/TypeScript MCP server with Amplitude's @amplitude/mcp-analytics SDK so tool calls, sessions, and rationale are tracked as Amplitude events. Use this skill whenever the user wants to add Amplitude analytics to their MCP server, mentions "MCP Analytics", "@amplitude/mcp-analytics", "instrument my MCP server", "track MCP tool calls", "add rationale to my MCP tools", or wants agent traffic (Claude, Cursor, ChatGPT) attributed back to Amplitude. Also use for adding UTM tagging to MCP-returned links, or for troubleshooting identity/user_id mismatches between MCP events and web/mobile Amplitude data.

amplitude/builder-skills

Diagnoses product health by cross-referencing Amplitude analytics (dashboards, charts, funnels, feedback, AI agent analytics), optionally Datadog (errors, latency, stack traces), and optionally Slack (qualitative feedback, bug reports, feature requests). Identifies what's broken, what's working, and what to do about it — with root causes, not just symptoms. Use when asked to "diagnose my product", "what's going on", "product health check", "what's broken", "where are users struggling", "give me a product diagnosis", or "what should I focus on".

amplitude/builder-skills

Turn one or more meeting transcripts, notes, or Slack threads into concise takeaways and clear action items with DRIs. Works with a single meeting or a batch from the whole week.

amplitude/builder-skills

Summarizes B2B account health by analyzing usage patterns, engagement trends, risk signals, and expansion opportunities. Use for customer success reviews, renewal preparation, QBRs, or account prioritization.

相關技能