matomo_get_visits_summary
Retrieve a summary of site visits, including metrics like unique visitors and page views, for a specified date and period using the Matomo Analytics API. Input site ID, date, and period for analysis.
Instructions
Lấy tổng quan lượt truy cập của site
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | Yes | Ngày cần lấy dữ liệu (YYYY-MM-DD) | |
| period | No | Chu kỳ (day, week, month, year) | day |
| siteId | Yes | ID của site |
Implementation Reference
- src/services/matomo-api.ts:170-176 (handler)Core handler implementation that makes the API call to Matomo's VisitsSummary.get endpoint to retrieve visits summary data.async getVisitsSummary(siteId: number, date: string, period: string = 'day'): Promise<any> { return await this.makeRequest('VisitsSummary.get', { idSite: siteId, date, period, }); }
- src/index.ts:456-470 (handler)MCP server wrapper handler that checks connection, invokes the service method, and formats the response as MCP content.private async handleGetVisitsSummary(args: { siteId: number; date: string; period?: string }) { if (!this.matomoService) { throw new Error('Chưa kết nối đến Matomo. Vui lòng sử dụng matomo_connect trước.'); } const summary = await this.matomoService.getVisitsSummary(args.siteId, args.date, args.period); return { content: [ { type: 'text', text: `Tổng quan lượt truy cập:\n${JSON.stringify(summary, null, 2)}`, }, ], }; }
- src/index.ts:185-207 (schema)Tool schema definition including name, description, and input schema for validation in the ListTools response.{ name: 'matomo_get_visits_summary', description: 'Lấy tổng quan lượt truy cập của site', inputSchema: { type: 'object', properties: { siteId: { type: 'number', description: 'ID của site', }, date: { type: 'string', description: 'Ngày cần lấy dữ liệu (YYYY-MM-DD)', }, period: { type: 'string', description: 'Chu kỳ (day, week, month, year)', default: 'day', }, }, required: ['siteId', 'date'], }, },
- src/index.ts:284-286 (registration)Dispatch registration in the CallToolRequest switch statement that routes to the handler.case 'matomo_get_visits_summary': return await this.handleGetVisitsSummary(args as { siteId: number; date: string; period?: string });
- src/services/matomo-api.ts:16-33 (helper)Helper method used by getVisitsSummary to make authenticated HTTP requests to the Matomo API.private async makeRequest(method: string, params: Record<string, any> = {}): Promise<any> { const requestParams = { module: 'API', format: 'JSON', token_auth: this.config.tokenAuth, ...params, }; try { const response = await this.client.get('', { params: requestParams }); return response.data; } catch (error) { if (axios.isAxiosError(error)) { throw new Error(`Matomo API error: ${error.response?.data?.message || error.message}`); } throw error; } }