claude-skills/

Anthropic公式スキル・プラグインの日本語ディレクトリ

last sync 22h ago
スキルOfficialmonitoring

🏗️instrument-events

プラグイン
amplitude

説明

`event_candidates` YAML(`discover-event-surfaces` の出力)を受け取り、優先度3(クリティカル)のイベントに対する具体的なインストルメンテーション計画を生成します。 ソフトウェアアーキテクトとして機能し、以下の処理を行います: - コードベース内の既存のアナリティクスパターンを探索 - ヒントされたファイルを読み込み、スコープ内の変数を特定 - チャートに有用な最小限のプロパティを設計 - 各トラッキングコールの正確な挿入箇所を特定 処理結果は、構造化された JSON 形式の `trackingPlan` として出力されます。 アナリティクス インストルメンテーション ワークフローのステップ3として、`discover-event-surfaces` の後に使用してください。 次のような場合に使用: - ユーザーが `event_candidates` を持っており、トラッキングコードの生成を希望している - 「これらのイベントをインストルメントしたい」と要求している - 「トラッキングプランを生成して」と依頼している - 「これらのイベントにアナリティクスを追加して」と求めている - 「トラッキングコールをどこに記述すればよいか」と質問している - その他、イベント候補を具体的な実装ガイダンスに変換するよう求めるリクエスト全般

原文を表示

Given event_candidates YAML (output from discover-event-surfaces), generates a concrete instrumentation plan for priority-3 (critical) events. Acts as a Software Architect: discovers existing analytics patterns in the codebase, reads the hinted files to determine what variables are in scope, designs minimal chart-useful properties, and identifies the exact insertion point for each tracking call. Outputs a structured JSON trackingPlan. Use this as step 3 of the analytics instrumentation workflow, after discover-event-surfaces. Trigger whenever a user has event_candidates and wants to generate tracking code, asks "instrument these events", "generate tracking plan", "add analytics for these events", "where should I put the tracking calls", or any request to turn event candidates into concrete implementation guidance.

ユースケース

  • event_candidatesからトラッキングプランを生成するとき
  • 既存のアナリティクスパターンを確認して実装するとき
  • トラッキングコールの挿入箇所を特定したいとき
  • クリティカルイベントのインストルメンテーション計画を立てるとき

本文(日本語訳)

instrument-events

あなたはアナリティクス計装ワークフローのステップ3です。 event_candidates YAML(discover-event-surfaces から受け取ったもの)を入力とし、 エンジニアが一行ずつ実装できる具体的な計装プランを作成します。

ソフトウェアアーキテクトとしてPRをレビューする視点で考えてください。 既存パターンとの一貫性、最小限のフットプリント、 そして誰も参照しないバニティフィールドではなく、 実際にダッシュボードを支えるプロパティを重視します。

../taxonomy/SKILL.md にある taxonomy スキルを読み、 アナリティクスおよびイベント命名規則のコア哲学を理解してください。


1. クリティカルイベントへの絞り込み

event_candidates YAML を解析し、priority: 3 の候補のみを抽出します。 これらはリリースをブロックしうるイベントであり、 それ以外はこのスキルのスコープ外です。

priority-3 のイベントが0件の場合は、その旨をユーザーに伝えて処理を停止してください。

作業を進める前に、絞り込んだイベントを一覧表示してユーザーにスコープを確認してもらいます。


2. 各クリティカルイベントの計装プラン作成

priority-3 のイベントを一つずつ順番に処理します。

2a. ヒントファイルの読み込み

イベント候補には file フィールドがあり、計装を追加すべき場所を示しています。 そのファイルを全体まで読んでください。 また instrumentation フィールドも確認します。 これはイベントがいつ発火するか、どの関数/ハンドラーを対象とするかを記述しています。

ファイルが存在しない、またはヒントが誤っていると思われる場合 (instrumentation に記載された関数がそのファイルに存在しない場合)は、 近隣ファイルを検索してください。ヒントはあくまで出発点であり、 絶対的な正解ではありません。

2b. 正確な挿入ポイントの特定

instrumentation ヒントを使用して、トラッキングコールを追加すべき 具体的な関数、ハンドラー、またはコールバックを特定します。 以下の点に着目してください。

  • instrumentation フィールドに記載されたハンドラー/コールバック名
  • 結果が確定した時点(非同期レスポンス受信後、ステートがコミットされた後、 successコールバックの内部)— アクションの開始時点ではありません
  • 近隣にある既存のトラッキングコール — 同一関数内にすでに track() 呼び出しがある場合は、 同じ配置パターンに従うこと

行番号を記録し、安定したアンカーとして関数/ブロック名を残してください (行番号はコード変更でずれますが、関数名はずれません)。

2c. プロパティの設計

挿入ポイントでスコープ内にある変数を確認します。 これらがプロパティの候補です。各候補について以下を問います。

  1. アナリストはチャートでこの値でセグメントまたはフィルタリングするか? しないなら除外します。
  2. プリミティブ値(string、number、boolean)か? 配列やオブジェクトはチャートに適しません — フラット化するか除外します。
  3. トラッキングSDKがすでに自動的に取得している値を重複して送っていないか? (例: timestamp、user_id、session_id は通常自動収集されます — 再送不要)

少ない方が良い。 1イベントあたり2〜4プロパティが最適です。 各プロパティは特定のチャート軸またはフィルターを実現するものでなければなりません。 それが可能にするチャートを一文で説明できない場合は除外してください。

discover-analytics-patterns を呼び出し、その event_naming_convention および property_naming_convention の出力を利用します。 命名解決の手順と優先順位はそのスキルが管理しています。ここで再定義しないでください。

これはイベント名とプロパティ名の命名にのみ適用されます。 importパス、トラッキング関数、オブジェクトの形状、配置はコードベースに合わせてください。

スコープを厳守する。 挿入ポイントで利用可能な変数のみを使用します。 重要なプロパティが他の場所(親コンポーネントのstate、別のAPIレスポンスなど)に 存在する場合は、reasoningに記載するにとどめ、プランには含めないでください — スレッドを通す必要があるかどうかはエンジニアが後から判断します。

2d. 既存のトラッキングコールとの照合

計画中のコールをステップ2で発見したサンプルと比較します。

  • import / 関数は同じか?
  • プロパティの形状は同じか(フラットオブジェクト? ネスト? 型付きインターフェース?)?
  • 配置パターンは同じか(ハンドラーにインライン? ヘルパーに切り出し?)?

異なる点があれば、既存パターンに合わせて調整してください。 一貫性 > 巧みさ。


3. トラッキングプランの組み立て

以下の正確な形式に従い、JSON オブジェクトとして結果を出力します。

{
  "trackingRequired": true,
  "reasoning": "これらのイベントがクリティカルである理由を簡潔に説明する一文。",
  "existingPattern": {
    "trackingFunction": "使用する関数名(例: 'track', 'trackEvent')",
    "importPath": "インポート元のパス",
    "exampleCall": "コードベースから抜き出した実際のパターンを示す一行のコード"
  },
  "trackingPlan": [
    {
      "eventName": "Event Name Here",
      "eventProperties": [
        {
          "name": "property_name",
          "type": "string",
          "description": "何を取得し、分析でどのように使用されるかの説明。"
        }
      ],
      "eventDescriptionAndReasoning": "このイベントが何を計測するか、なぜクリティカルか、どのPMの問いに答えるか。analysis_recipe のコンテキストも含めること。",
      "implementationLocations": [
        {
          "filePath": "src/components/Foo/Bar.tsx",
          "originalLineNumberPreChanges": 142,
          "codeContext": "useExtract() フックの onSuccess コールバック内",
          "trackingCode": "track('Event Name Here', { property_name: variableInScope })"
        }
      ]
    }
  ]
}

フィールドの説明

  • eventDescriptionAndReasoning — 候補の rationaleanalysis_recipe を一つのまとまった段落にまとめます。 エンジニアが実装前に読む「なぜ」の部分です。
  • filePath — リポジトリルートからの相対パス。
  • originalLineNumberPreChanges — 現在のファイル状態を基準に、トラッキングコールを挿入すべき行番号。
  • codeContext — コールを配置する関数名、コールバック、またはブロックを示す安定したアンカー。 リベース後も残りますが、行番号は残りません。
  • trackingCode — 既存のアナリティクスパターンに合わせた、挿入する正確なコード。 ファイル内の実際の変数名を使用してください。

5. プランの提示

JSONトラッキングプランをユーザーに提示します。 各イベントについて以下を簡潔に説明します。

  • 何をトラッキングするか
  • どこに配置するか(ファイル + 関数)
  • どのプロパティを送信するか、その理由

エンジニアが実装を開始する前に調整が必要かどうか確認します。


原則

  • 合わせる、発明しない。 コードベースにはすでにイベント送信の方法があります。それを見つけて正確に従います。
  • プロパティはその存在意義を示すこと。 すべてのプロパティは「このチャート軸またはフィルターを実現するため」と 説明できなければなりません。答えが曖昧なら除外します。
  • スコープは厳守。 挿入ポイントで利用可能な変数のみを使用します。 データをスレッドで通すリファクタリングを提案しないでください — それは別のPRの仕事です。
  • クリティカルとはクリティカルを意味する。 このスキルは priority 3 のみを扱います。 priority 2 のイベントが必要な場合はユーザーが明示的に伝えてください。 その場合は含めることができます。
原文(English)を表示

instrument-events

You are step 3 of the analytics instrumentation workflow. You receive event_candidates YAML (from discover-event-surfaces) and produce a concrete instrumentation plan that an engineer can implement line-by-line.

Think like a Software Architect reviewing a PR: you care about consistency with existing patterns, minimal footprint, and properties that actually power dashboards — not vanity fields nobody queries.

Read the taxonomy skill at ../taxonomy/SKILL.md to understand the core philosophy of analytics and event naming standards.


1. Filter to critical events

Parse the event_candidates YAML. Extract only candidates where priority: 3. These are the events that would block a release — everything else is out of scope for this skill.

If there are zero priority-3 events, tell the user and stop.

List the filtered events so the user can confirm scope before you proceed.

2. For each critical event, build the instrumentation plan

Work through each priority-3 event one at a time:

2a. Read the hinted file

The event candidate has a file field pointing to where instrumentation likely belongs. Read that file completely. Also read the instrumentation field — it describes when the event fires and which function/handler to target.

If the file doesn't exist or the hint seems wrong (the function described in instrumentation isn't in that file), search nearby files. The hint is a starting point, not gospel.

2b. Find the exact insertion point

Using the instrumentation hint, locate the specific function, handler, or callback where the tracking call should go. Look for:

  • The handler/callback named in the instrumentation field
  • The point where the outcome is confirmed (after an async response, after state is committed, inside a success callback) — not where the action is initiated
  • Existing tracking calls nearby — if there are already track() calls in the same function, your new call should follow the same placement pattern

Record the line number and note the function/block name as a stable anchor (line numbers shift; function names don't).

2c. Design properties

Look at what variables are in scope at the insertion point. These are your property candidates. For each one, ask:

  1. Would an analyst segment or filter by this in a chart? If not, skip it.
  2. Is it a primitive value (string, number, boolean)? Arrays and objects don't chart well — flatten or skip.
  3. Does it duplicate something the tracking SDK already captures? (e.g., timestamp, user_id, session_id are usually automatic — don't re-send them)

Less is more. 2-4 properties per event is the sweet spot. Each property should unlock a specific chart axis or filter. If you can't describe the chart it enables in one sentence, drop it.

Invoke discover-analytics-patterns and use its event_naming_convention and property_naming_convention outputs. That skill owns the naming-resolution procedure and precedence order. Do not redefine it here.

This applies only to event and property naming. Keep import paths, tracking functions, object shape, and placement aligned to the codebase.

Stay in scope. Only use variables available at the insertion point. If an important property exists elsewhere (e.g., in a parent component's state, in a different API response), note it in the reasoning but do not include it in the plan — the engineer can decide later whether to thread it through.

2d. Validate against existing tracking calls

Compare your planned call against the examples you found in step 2:

  • Same import/function?
  • Same property shape (flat object? nested? typed interface?)?
  • Same placement pattern (inline in handler? extracted to a helper?)?

If anything diverges, adjust to match. Consistency > cleverness.

3. Assemble the tracking plan

Output the result as a JSON object following this exact shape:

{
  "trackingRequired": true,
  "reasoning": "Concise sentence explaining why these events are critical.",
  "existingPattern": {
    "trackingFunction": "the function name used (e.g., 'track', 'trackEvent')",
    "importPath": "where it's imported from",
    "exampleCall": "a real one-liner from the codebase showing the pattern"
  },
  "trackingPlan": [
    {
      "eventName": "Event Name Here",
      "eventProperties": [
        {
          "name": "property_name",
          "type": "string",
          "description": "What it captures and how it's used in analysis."
        }
      ],
      "eventDescriptionAndReasoning": "What this event measures, why it's critical, and what PM question it answers. Include the analysis_recipe context.",
      "implementationLocations": [
        {
          "filePath": "src/components/Foo/Bar.tsx",
          "originalLineNumberPreChanges": 142,
          "codeContext": "inside onSuccess callback of useExtract() hook",
          "trackingCode": "track('Event Name Here', { property_name: variableInScope })"
        }
      ]
    }
  ]
}

Field guidance

  • eventDescriptionAndReasoning — merge the candidate's rationale and analysis_recipe into a coherent paragraph. This is the "why" an engineer reads before implementing.
  • filePath — relative from repo root.
  • originalLineNumberPreChanges — the line number where the tracking call should be inserted, based on the current file state.
  • codeContext — a stable anchor: the function name, callback, or block where the call goes. This survives rebases; line numbers don't.
  • trackingCode — the exact code to insert, matching the existing analytics pattern. Use real variable names from the file.

5. Present the plan

Show the user the JSON tracking plan. Walk through each event briefly:

  • What it tracks
  • Where it goes (file + function)
  • What properties it sends and why

Ask if they want to adjust anything before an engineer implements it.


Principles

  • Match, don't invent. The codebase already has a way of sending events. Find it and follow it exactly.
  • Properties earn their place. Every property must answer: "what chart axis or filter does this enable?" If the answer is vague, cut it.
  • Scope is sacred. Only use variables available at the insertion point. Don't propose refactors to thread data through — that's a separate PR.
  • Critical means critical. This skill only handles priority 3. If the user wants priority 2 events, they should say so explicitly and you can include them.

原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。