list_accounts
Retrieve Google Analytics 4 accounts and properties to identify which property ID to use for analysis.
Instructions
GA4のアカウントとプロパティの一覧を取得します。どのプロパティIDを使うべきか確認する際に便利です。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/basic/listAccounts.ts:7-48 (handler)The main handler function that fetches GA4 accounts and their properties using the admin client, returning a structured ListAccountsOutput.export async function listAccounts(): Promise<ListAccountsOutput> { const client = getAdminClient(); const accounts: Account[] = []; // アカウント一覧を取得 const [accountsResponse] = await client.listAccounts({}); for (const account of accountsResponse || []) { if (!account.name || !account.displayName) continue; const accountId = account.name.replace("accounts/", ""); const accountData: Account = { accountId, accountName: account.displayName, properties: [], }; // このアカウントのプロパティ一覧を取得 try { const [propertiesResponse] = await client.listProperties({ filter: `parent:accounts/${accountId}`, }); for (const property of propertiesResponse || []) { if (!property.name || !property.displayName) continue; accountData.properties.push({ propertyId: extractPropertyId(property.name), propertyName: property.displayName, }); } } catch (error) { // プロパティの取得に失敗しても続行 console.error(`Failed to fetch properties for account ${accountId}:`, error); } accounts.push(accountData); } return { accounts }; }
- src/types.ts:23-25 (schema)Output type definition for the list_accounts tool response.export interface ListAccountsOutput { accounts: Account[]; }
- src/server.ts:62-71 (registration)Tool registration in the tools array, defining name, description, and empty input schema.{ name: "list_accounts", description: "GA4のアカウントとプロパティの一覧を取得します。どのプロパティIDを使うべきか確認する際に便利です。", inputSchema: { type: "object" as const, properties: {}, required: [], }, },
- src/server.ts:571-573 (registration)Dispatch handler in switch statement that calls the listAccounts function.case "list_accounts": return await listAccounts();
- src/tools/basic/index.ts:1-1 (helper)Re-export of the listAccounts handler for use in server.ts.export { listAccounts } from "./listAccounts.js";