matomo_add_goal
Add and configure a new goal for a Matomo site by specifying the site ID, name, description, match attribute, pattern, and pattern type to track specific user interactions.
Instructions
Thêm một goal mới cho site
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| description | Yes | Mô tả của goal | |
| matchAttribute | Yes | Thuộc tính khớp (url, title, event, etc.) | |
| name | Yes | Tên của goal | |
| pattern | Yes | Mẫu khớp | |
| patternType | Yes | Loại mẫu (exact, contains, regex, etc.) | |
| siteId | Yes | ID của site |
Implementation Reference
- src/index.ts:154-182 (schema)Input schema definition for the matomo_add_goal tool, specifying parameters like siteId, name, description, matchAttribute, pattern, and patternType.inputSchema: { type: 'object', properties: { siteId: { type: 'number', description: 'ID của site', }, name: { type: 'string', description: 'Tên của goal', }, description: { type: 'string', description: 'Mô tả của goal', }, matchAttribute: { type: 'string', description: 'Thuộc tính khớp (url, title, event, etc.)', }, pattern: { type: 'string', description: 'Mẫu khớp', }, patternType: { type: 'string', description: 'Loại mẫu (exact, contains, regex, etc.)', }, }, required: ['siteId', 'name', 'description', 'matchAttribute', 'pattern', 'patternType'],
- src/index.ts:274-282 (registration)Registration of the matomo_add_goal handler in the switch statement of the CallToolRequestSchema handler.case 'matomo_add_goal': return await this.handleAddGoal(args as { siteId: number; name: string; description: string; matchAttribute: string; pattern: string; patternType: string; });
- src/index.ts:426-454 (handler)MCP tool handler for matomo_add_goal, validates connection and delegates to MatomoApiService.addGoal.private async handleAddGoal(args: { siteId: number; name: string; description: string; matchAttribute: string; pattern: string; patternType: 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 goalId = await this.matomoService.addGoal( args.siteId, args.name, args.description, args.matchAttribute, args.pattern, args.patternType ); return { content: [ { type: 'text', text: `Đã thêm goal thành công với ID: ${goalId}`, }, ], }; }
- src/services/matomo-api.ts:111-121 (helper)Core helper function in MatomoApiService that makes the actual API request to Goals.addGoal endpoint.async addGoal(siteId: number, name: string, description: string, matchAttribute: string, pattern: string, patternType: string): Promise<number> { const response = await this.makeRequest('Goals.addGoal', { idSite: siteId, name, description, matchAttribute, pattern, patternType, }); return response.value; }
- src/index.ts:151-184 (registration)Tool registration in the ListToolsRequestSchema response, including name, description, and schema.{ name: 'matomo_add_goal', description: 'Thêm một goal mới cho site', inputSchema: { type: 'object', properties: { siteId: { type: 'number', description: 'ID của site', }, name: { type: 'string', description: 'Tên của goal', }, description: { type: 'string', description: 'Mô tả của goal', }, matchAttribute: { type: 'string', description: 'Thuộc tính khớp (url, title, event, etc.)', }, pattern: { type: 'string', description: 'Mẫu khớp', }, patternType: { type: 'string', description: 'Loại mẫu (exact, contains, regex, etc.)', }, }, required: ['siteId', 'name', 'description', 'matchAttribute', 'pattern', 'patternType'], }, },