matomo_add_goal
Add a new goal to a Matomo Analytics site by specifying tracking criteria like URL patterns or event attributes to measure conversions and user actions.
Instructions
Thêm một goal mới cho site
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| siteId | Yes | ID của site | |
| name | Yes | Tên của goal | |
| description | Yes | Mô tả của goal | |
| matchAttribute | Yes | Thuộc tính khớp (url, title, event, etc.) | |
| pattern | Yes | Mẫu khớp | |
| patternType | Yes | Loại mẫu (exact, contains, regex, etc.) |
Implementation Reference
- src/index.ts:151-184 (schema)Input schema definition for the matomo_add_goal tool, specifying parameters and validation.{ 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'], }, },
- src/index.ts:274-282 (registration)Registration of the tool in the switch statement dispatching to the handler method.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)Tool handler function that checks Matomo connection, calls the service to add the goal, and returns success response.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 method in MatomoApiService that performs the actual API request to Matomo's 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; }