🔍discover-analytics-patterns
- プラグイン
- amplitude
- ソース
- GitHub で見る ↗
説明
このコードベースにおけるアナリティクストラッキング呼び出しの実際の実装方法(イベント送信に使用される具体的なSDK呼び出し、関数シグネチャ、インポートパターン)を調査します。 次のような場合に使用: - 新しいトラッキングを追加する前に、既存のアナリティクス計装パターンを把握したいとき - 「このプロジェクトではどうやってイベントをトラッキングするの?」「アナリティクスのセットアップを見せて」「このコードベースのアナリティクスパターンは?」といった質問を受けたとき - `instrument-events` または `discover-event-surfaces` スキルを実行しようとしており、従うべき正しいコーディングスタイルを事前に確認する必要があるとき 重複を排除したパターン一覧を出力します。各パターンには汎化されたサンプルコードと、そのパターンが使われているファイルパスが含まれます。また、各呼び出し箇所から推定される、イベント名およびプロパティ名の主要な命名規則も併せて出力します。 アナリティクスの計装コードを記述する前には、必ずこのスキルを使用してください。
原文を表示
Discovers how analytics tracking calls are actually written in this codebase — the concrete SDK calls, function signatures, and import patterns used to send events. Use this skill whenever you need to understand the existing analytics instrumentation patterns before adding new tracking, when someone asks "how do we track events here?", "show me the analytics setup", "what's the analytics pattern in this codebase?", or any time the instrument-events or discover-event-surfaces skills are about to run and you need to know the correct coding style to follow. Outputs a deduplicated list of patterns with generalized examples and the file paths where each pattern appears, plus the dominant event and property naming conventions inferred from those call sites. Always use this skill before writing any analytics instrumentation code.
ユースケース
- ✓既存のアナリティクス計装パターンを把握したいとき
- ✓プロジェクトのイベントトラッキング方法を確認するとき
- ✓アナリティクスセットアップの実装例を見たいとき
- ✓新規トラッキング追加前にコーディング規則を確認するとき
本文(日本語訳)
discover-analytics-patterns
このコードベースがアナリティクスイベントを送信する方法を明らかにすることが目的です。 どのイベントが存在するかではなく、トラッキングコールを発火させるためにエンジニアが使用する 具体的なコードパターンを特定します。 この出力は、コードベースの既存スタイルと一貫した新規イベントを追加する際にエンジニアの助けとなります。 また、イベント名やプロパティ名がこのコードベースでどのように記述されるかを、 後続のSkillに伝える役割も担います。
このSkillで命名規則を決定する際は、以下のソースを厳密な優先順位で使用してください:
- Amplitude MCPサーバーから取得したイベントおよびプロパティ
- コードベース内の実際のトラッキングコールサイト
../taxonomy/SKILL.mdのtaxonomySkill
Step 1: トラッキングコールを探す
利用可能な状況に応じて、2つのアプローチを使用します。
Amplitude MCPが接続されている場合
get_events(または同等のメソッド)を呼び出し、プロジェクトからイベント名のサンプルを取得します。
その結果をもとに、代表的な非システム系プロダクトイベントをいくつか選択し、
get_event_properties を呼び出して実際のプロパティ名を確認します。
これが命名規則の主要な参照元となります。
[Amplitude]、[Guides-Surveys]、[Assistant]、[Experiment] など、
角括弧プレフィックスが付いたAmplitudeのシステム名は、
イベント・プロパティいずれのパターン検出においても使用しないでください。
MCPのサンプルがAmplitudeシステム名に支配されている、または十分な根拠が得られない場合は、
コードベースからの推定にフォールバックしてください。
次に、サンプリングした非システム系イベント名をGrepでコードベース内検索し、 実際のトラッキングコールサイトを特定します。
Amplitude MCPが利用できない場合(フォールバック)
以下のシグナルをGrepでコードベース内検索します。 最初は広く網を張り、後から絞り込んでください:
| 検索対象 | 理由 |
|---|---|
\.track\( |
汎用的な .track() メソッド呼び出し |
ampli\. |
Ampli型付きSDK呼び出し(例: ampli.myEvent(...)) |
amplitude\.track|amplitude\.logEvent |
Amplitude SDK直接呼び出し |
sendEvent |
カスタムラッパーメソッド名 |
from.*amplitude|import.*amplitude|require.*amplitude |
インポート文 |
https://api2\.amplitude\.com/2/httpapi |
HTTP API呼び出し |
カスタムアナリティクスラッパーも積極的に探してください。
コードベースでは多くの場合、生のSDKを trackEvent()、track()、
あるいは useAnalytics() や useTracking() といったReact hookなどのユーティリティでラップしています。
内部でAmplitudeを呼び出している関数を検索することでこれらを見つけられます。
ラッパーは、内部で最終的に amplitude.track() を呼び出すとしても、
それぞれを独立したパターンとして扱ってください。
ラッパーに遭遇したエンジニアは生のSDKではなくそちらを使用するため、
ラッパーこそがドキュメント化すべき重要なパターンです。
ラッパーを見つけるには: Amplitude SDKをインポートしているファイルを探し、 そのファイルがトラッキング目的でコードベースの他の部分にインポート・使用される 関数やhookをエクスポートしているかどうかを確認します。
テストファイル(.test.、.spec.、__tests__)およびモックファイルは、
そのパターンがそれのみに存在する場合を除き、対象から除外してください。
Step 2: パターンでグループ化する
以下の要素をすべて共有する場合、2つのコールサイトは同一パターンです:
- 使用しているライブラリ / SDK / 関数
- メソッド名
- 引数の構造(イベント名やプロパティが異なっていても)
例えば、以下は同一パターンです:
amplitude.track('Page Viewed', { page: '/home' })
amplitude.track('Button Clicked', { label: 'signup' })
しかし以下は異なるパターンです。常に別々に扱ってください:
amplitude.track('Page Viewed', { page: '/home' }) // SDK直接呼び出し — 1つのパターン
ampli.pageViewed({ page: '/home' }) // Ampli型付きメソッド — 別パターン
trackEvent('Page Viewed', { page: '/home' }) // カスタムラッパー — これも別パターン
カスタムラッパーは、内部でSDKに委譲している場合でも、常に独自のパターンです。
ラッパーパターンをドキュメント化する際は、何をラップしているかを明記してください
(例: 「amplitude.track() をラップするカスタムhook」)。
エンジニアが階層構造を理解できるようにするためです。
Step 3: 命名規則を解決する
以下の2つの規則を個別に解決します:
event_naming_convention— インストルメンテーションコードにおけるイベント名の ケーシング・区切り文字・語順・プレフィックス・時制。 例:Title Case、snake_case、[Prefix] Action、オブジェクト先行 vs アクション先行。property_naming_convention— イベントプロパティのケーシング・区切り文字・ 一般的なサフィックス/プレフィックスパターン。 例:snake_case、camelCase、*_id、is_*、フラットなキー vs ネストされたオブジェクト。
以下の優先順位を使用してください:
- Amplitude MCPを最優先。
get_event_propertiesが返す代表的な非システム系イベントのeventType値およびプロパティ名に明確な支配的規則が見られる場合はそれを使用します。 角括弧プレフィックス付きのAmplitudeシステム名を命名の根拠として使用しないでください。 - コードベースを次点。 MCPの根拠が利用不可・不十分・不一致の場合は、 リポジトリ内の近傍にある実際のトラッキングコールサイトから支配的な規則を推定します。 複数の規則が存在する場合は、支配的なものを示しつつ、重要なローカル例外を注記してください。
- Taxonomyをラストリゾートとして使用。 MCPもコードベースも十分な根拠を提供できない場合は、
../taxonomy/SKILL.mdのtaxonomySkillにフォールバックします。
推測はしないでください。これらのソースを確認した後も一方または両方の規則が不明な場合は、 その旨を明示してください。
Step 4: 出力
最初に短い規則セクションを示し、その後に各ユニークパターンを列挙します。
event_naming_convention: "<MCPが明確ならそこから、次にコードベース、次にtaxonomy Skill、または 'insufficient evidence'>"
property_naming_convention: "<MCPが明確ならそこから、次にコードベース、次にtaxonomy Skill、または 'insufficient evidence'>"
次に、各ユニークパターンについて以下の形式でセクションを出力します:
Pattern: <短い説明的な名前>
Description: このパターンが何をするものか、このコードベースで典型的にどのような場面で使われるか (例: 「Reactフロントエンド全体でユーザーアクションのトラッキングに使用」)。
Example(汎化済み):
// 必要なインポートを示す
import { amplitude } from '@/lib/analytics'
// プレースホルダー名を使った代表的なトラッキングコールを示す
amplitude.track('Event Name', {
propertyOne: value,
propertyTwo: value,
})
Relevant paths:
src/path/to/file.tssrc/another/file.tsx
パターンは最も一般的なもの(ファイルパスが多いもの)から順に列挙してください。
2つのパターンが常にセットで使用される場合(例: インポートと呼び出し)は、 1つのExampleにまとめて示してください。
Step 5: 結果が見つからない場合の対処
どの検索戦略でもトラッキングコールが見つからない場合は、その旨を明確に伝えてください。 Amplitude(または他のアナリティクスライブラリ)がプロジェクトにセットアップされているかを 確認するよう提案し、必要に応じて他のアナリティクスライブラリ (Segment、Mixpanel、PostHogなど)の検索も提案してください。
原文(English)を表示
discover-analytics-patterns
Your goal is to find out how this codebase sends analytics events — not which events exist, but the specific code patterns engineers use to fire a tracking call. This output helps engineers add new events that look consistent with the rest of the codebase. It should also tell downstream skills how event names and property names are typically written in code here.
When determining naming conventions in this skill, use the following sources in strict order of preference:
- Events and properties observed from the Amplitude MCP server
- Real tracking call sites in the codebase
- The
taxonomyskill at../taxonomy/SKILL.md
Step 1: Find tracking calls
Use two approaches based on what's available.
If the Amplitude MCP is connected
Call get_events (or equivalent) to fetch a sample of event names from the
project. Use those results to choose a few representative non-system product
events, then call get_event_properties for those events to inspect real
property names. This is your primary naming reference.
Do not infer naming conventions from bracket-prefixed Amplitude system names
such as [Amplitude], [Guides-Surveys], [Assistant], [Experiment] for either events or properties. Exclude those from
pattern detection. If the MCP sample is dominated by Amplitude system names or otherwise does not provide enough evidence, fall back to codebase
inference for naming.
Then search the codebase for the sampled non-system event names using Grep to locate the actual tracking call sites.
If the Amplitude MCP is not available (fallback)
Search the codebase for these signals using Grep. Cast a wide net — you can narrow down after:
| What to search for | Why |
|---|---|
\.track\( |
Generic .track() method calls |
ampli\. |
Ampli typed SDK calls (e.g. ampli.myEvent(...)) |
amplitude\.track|amplitude\.logEvent |
Direct Amplitude SDK calls |
sendEvent |
Custom wrapper method names |
from.*amplitude|import.*amplitude|require.*amplitude |
Import statements |
https://api2\.amplitude\.com/2/httpapi |
HTTP API calls |
Also actively look for custom analytics wrappers — a codebase often wraps the
raw SDK in a utility like trackEvent(), track(), or a React hook like
useAnalytics() or useTracking(). Search for these by looking for functions
that call into Amplitude internally. Treat each wrapper as its own pattern,
separate from the underlying SDK call, even if it ultimately calls
amplitude.track() underneath. Engineers who encounter the wrapper will use
it, not the raw SDK — so it's the more important pattern to document.
To find wrappers: search for files that import the Amplitude SDK, then check whether any of those files export a function or hook that other parts of the codebase import and use for tracking.
Exclude test files (.test., .spec., __tests__) and mock files unless they
are the only place a pattern appears.
Step 2: Group by pattern
Two call sites use the same pattern if they share the same:
- Library/SDK/function being called
- Method name
- Argument structure (even if the event name or properties differ)
For example, these are the same pattern:
amplitude.track('Page Viewed', { page: '/home' })
amplitude.track('Button Clicked', { label: 'signup' })
But these are different patterns — always keep them separate:
amplitude.track('Page Viewed', { page: '/home' }) // direct SDK — one pattern
ampli.pageViewed({ page: '/home' }) // Ampli typed method — different pattern
trackEvent('Page Viewed', { page: '/home' }) // custom wrapper — also a separate pattern
A custom wrapper is always its own pattern, even if it delegates to the SDK
underneath. When documenting a wrapper pattern, note what it wraps (e.g.,
"Custom hook wrapping amplitude.track()") so engineers understand the layering.
Step 3: Resolve naming conventions
Resolve two conventions separately:
event_naming_convention— casing, separators, word order, prefixes, and tense used for event names in instrumentation code. Examples:Title Case,snake_case,[Prefix] Action, object-first vs action-first.property_naming_convention— casing, separators, and common suffix/prefix patterns used for event properties. Examples:snake_case,camelCase,*_id,is_*, flat keys vs nested objects.
Use this precedence order:
- Amplitude MCP first. If the observed
eventTypevalues and property names returned byget_event_propertiesfor a few representative non-system events show a clear dominant convention, use that. Do not use bracket-prefixed Amplitude system names as naming evidence. - Codebase second. If the MCP evidence is unavailable, sparse, or inconsistent, infer the dominant convention from nearby, real tracking call sites in the repository. If the codebase shows multiple conventions, call out the dominant one and note meaningful local exceptions.
- Taxonomy fallback last. If neither MCP nor codebase evidence is
clear enough, fall back to the
taxonomyskill at../taxonomy/SKILL.md.
Do not guess. If one or both conventions remain unclear even after checking those sources, say so explicitly.
Step 4: Output
Start with a short conventions section, then list each unique pattern.
event_naming_convention: "<from MCP if clear, otherwise codebase, otherwise taxonomy skill, or 'insufficient evidence'>"
property_naming_convention: "<from MCP if clear, otherwise codebase, otherwise taxonomy skill, or 'insufficient evidence'>"
Then, for each unique pattern, output a section in this format:
Pattern: <short descriptive name>
Description: What this pattern does and when it's typically used in this codebase (e.g., "Used throughout the React frontend for user action tracking").
Example (generalized):
// show the import(s) needed
import { amplitude } from '@/lib/analytics'
// show a representative tracking call with placeholder names
amplitude.track('Event Name', {
propertyOne: value,
propertyTwo: value,
})
Relevant paths:
src/path/to/file.tssrc/another/file.tsx
List patterns from most common (most file paths) to least common.
If two patterns are always used together (e.g., an import + a call), show them together in one example.
Step 5: Handle no results
If no tracking calls are found with any search strategy, say so clearly. Suggest that the user check whether Amplitude (or another analytics library) has been set up in the project, and offer to search for other analytics libraries (Segment, Mixpanel, PostHog, etc.) if relevant.
原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。