Umami analytics template
工作流概述
这是一个包含17个节点的复杂工作流,主要用于自动化处理各种任务。
工作流源代码
{
"id": "eZT6SZ4Kvmq5TzyQ",
"meta": {
"instanceId": "558d88703fb65b2d0e44613bc35916258b0f0bf983c5d4730c00c424b77ca36a",
"templateCredsSetupCompleted": true
},
"name": "Umami analytics template",
"tags": [],
"nodes": [
{
"id": "8a54ac1c-a072-42e6-a3ba-8cde33475eb5",
"name": "When clicking ‘Test workflow’",
"type": "n8n-nodes-base.manualTrigger",
"position": [
460,
220
],
"parameters": {},
"typeVersion": 1
},
{
"id": "e81c9be0-f59d-467e-9bda-eeb2d66ed31e",
"name": "Schedule Trigger",
"type": "n8n-nodes-base.scheduleTrigger",
"position": [
460,
380
],
"parameters": {
"rule": {
"interval": [
{
"field": "weeks",
"triggerAtDay": [
4
]
}
]
}
},
"typeVersion": 1.2
},
{
"id": "01b04872-9aea-4834-8df5-f6c91914133d",
"name": "Get view stats from Umami",
"type": "n8n-nodes-base.httpRequest",
"position": [
760,
260
],
"parameters": {
"url": "=https://umami.mydomain.com/api/websites/86d4095c-a2a8-4fc8-9521-103e858e2b41/event-data/stats?startAt={{ DateTime.now().minus({ days: 7 }).toMillis() }}&endAt={{ DateTime.now().toMillis() }}&unit=hour&timezone=Asia%2FHong_Kong",
"options": {},
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth"
},
"credentials": {
"httpHeaderAuth": {
"id": "FKsKXvQUlaX5qt9n",
"name": "Header Auth account 3"
}
},
"typeVersion": 4.2
},
{
"id": "38d342e3-10ad-4260-8f44-5a3233ec3166",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
660,
-460
],
"parameters": {
"width": 505,
"height": 320,
"content": "## Send data from Umami to A.I. and then save to Baserow
You can find out more about the stats available in the [Umami API](https://umami.is/docs/api/website-stats-api)
[Watch youtube tutorial here](https://www.youtube.com/watch?v=hGzdhXyU-o8)
[Get my SEO A.I. agent system here](https://2828633406999.gumroad.com/l/rumjahn)
Read the [case study here](https://rumjahn.com/how-to-analyze-umami-data-using-n8n-and-a-i-to-improve-seo-and-uncover-hidden-insights-for-better-content-optimization/).
"
},
"typeVersion": 1
},
{
"id": "18c997fe-61b1-464a-8bb5-fcdc017dd1f6",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
660,
-60
],
"parameters": {
"color": 4,
"width": 393.16558441558414,
"height": 504.17207792207796,
"content": "## Get summary stats from Umami
It will get: Pageviews, Visitors, Visits, Bounces, Total Time
You need to change the URL to your website. https://{your website}/api/websites/{website ID}/
You can find your ID by going to your Umami account -> Settings -> Edit (next to domain)"
},
"typeVersion": 1
},
{
"id": "bfdc04a2-57fa-4a8a-b412-39047cebb370",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
1080,
-60
],
"parameters": {
"color": 5,
"width": 216.5746753246753,
"height": 502.37012987012963,
"content": "## Send data to A.I.
To use Openrouter, you need to register for an account.
Then add header authorization credentials.
Username: Authroization
Password: Bearer {Your API Key}
*It's Bearer space {API key}."
},
"typeVersion": 1
},
{
"id": "fc373fd7-52fc-4729-8022-021c09d0c89c",
"name": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"position": [
1320,
-60
],
"parameters": {
"color": 6,
"width": 746.3474025974022,
"height": 505.9740259740257,
"content": "## Get page specific stats for this week and last
Calls Umami to get this week and last week's data. It will get the views for each page visited on your website for comparison."
},
"typeVersion": 1
},
{
"id": "82bd35b6-8b49-4d77-8be2-033a8bff3f41",
"name": "Sticky Note4",
"type": "n8n-nodes-base.stickyNote",
"position": [
2120,
-60
],
"parameters": {
"color": 5,
"width": 216.5746753246753,
"height": 502.37012987012963,
"content": "## Send data to A.I.
To use Openrouter, you need to register for an account.
Then add header authorization credentials.
Username: Authroization
Password: Bearer {Your API Key}
*It's Bearer space {API key}."
},
"typeVersion": 1
},
{
"id": "503c4ca3-36da-41a8-9029-f844a34daa59",
"name": "Sticky Note5",
"type": "n8n-nodes-base.stickyNote",
"position": [
2380,
-60
],
"parameters": {
"color": 4,
"width": 393.16558441558414,
"height": 504.17207792207796,
"content": "## Save analysis to baserow
You need to create a table in advance to save.
- Date (date)
- Summary (Long text)
- Top pages (Long text)
- Blog name (Long text)"
},
"typeVersion": 1
},
{
"id": "f64cdfbd-712f-461c-b025-25f37e2bded8",
"name": "Parse Umami data",
"type": "n8n-nodes-base.code",
"position": [
940,
260
],
"parameters": {
"jsCode": "function transformToUrlString(items) {
// In n8n, we need to check if items is an array and get the json property
const data = items[0].json;
if (!data) {
console.log('No valid data found');
return encodeURIComponent(JSON.stringify([]));
}
try {
// Create a simplified object with the metrics
const simplified = {
pageviews: {
value: parseInt(data.pageviews.value) || 0,
prev: parseInt(data.pageviews.prev) || 0
},
visitors: {
value: parseInt(data.visitors.value) || 0,
prev: parseInt(data.visitors.prev) || 0
},
visits: {
value: parseInt(data.visits.value) || 0,
prev: parseInt(data.visits.prev) || 0
},
bounces: {
value: parseInt(data.bounces.value) || 0,
prev: parseInt(data.bounces.prev) || 0
},
totaltime: {
value: parseInt(data.totaltime.value) || 0,
prev: parseInt(data.totaltime.prev) || 0
}
};
return encodeURIComponent(JSON.stringify(simplified));
} catch (error) {
console.log('Error processing data:', error);
throw new Error('Invalid data structure');
}
}
// Get the input data
const items = $input.all();
// Process the data
const result = transformToUrlString(items);
// Return the result
return { json: { urlString: result } };"
},
"typeVersion": 2
},
{
"id": "470715b6-0878-48b8-b6c6-40de27fbc966",
"name": "Send data to A.I.",
"type": "n8n-nodes-base.httpRequest",
"position": [
1140,
260
],
"parameters": {
"url": "https://openrouter.ai/api/v1/chat/completions",
"method": "POST",
"options": {},
"jsonBody": "={
\"model\": \"meta-llama/llama-3.1-70b-instruct:free\",
\"messages\": [
{
\"role\": \"user\",
\"content\": \"You are an SEO expert. Here is data from Umami analytics of Pennibnotes.com. Where X is URL and Y is number of visitors. Give me a table summary of this data in markdown format:{{ $('Parse Umami data').item.json.urlString }}.\"
}
]
}",
"sendBody": true,
"specifyBody": "json",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth"
},
"credentials": {
"httpHeaderAuth": {
"id": "WY7UkF14ksPKq3S8",
"name": "Header Auth account 2"
}
},
"typeVersion": 4.2
},
{
"id": "ea4bb37f-96d9-41b8-bf46-fb09865a6e0f",
"name": "Get page data from Umami",
"type": "n8n-nodes-base.httpRequest",
"position": [
1380,
260
],
"parameters": {
"url": "=https://umami.rumjahn.synology.me/api/websites/f375d28c-1949-4597-8871-f1b942e3aa24/metrics?startAt={{Date.now() - (7 * 24 * 60 * 60 * 1000)}}&endAt={{Date.now()}}&type=url&tz=America/Los_Angeles",
"options": {},
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth"
},
"credentials": {
"httpHeaderAuth": {
"id": "FKsKXvQUlaX5qt9n",
"name": "Header Auth account 3"
}
},
"typeVersion": 4
},
{
"id": "d982606b-49c8-4d5b-ba79-bd0fdd2600b6",
"name": "Parse Umami data1",
"type": "n8n-nodes-base.code",
"position": [
1560,
260
],
"parameters": {
"jsCode": "// Get input data
const data = $input.all();
// Create URL-encoded string from the data
const encodedData = encodeURIComponent(JSON.stringify(data));
// Return the encoded data
return {
json: {
thisWeek: encodedData
}
};"
},
"typeVersion": 2
},
{
"id": "f3734045-1318-4234-a3ac-61b766124609",
"name": "Get page view data from Umami",
"type": "n8n-nodes-base.httpRequest",
"position": [
1760,
260
],
"parameters": {
"url": "=https://umami.rumjahn.synology.me/api/websites/f375d28c-1949-4597-8871-f1b942e3aa24/metrics?startAt={{Date.now() - (14 * 24 * 60 * 60 * 1000)}}&endAt={{Date.now() - (7 * 24 * 60 * 60 * 1000)}}&type=url&tz=America/Los_Angeles",
"options": {},
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth"
},
"credentials": {
"httpHeaderAuth": {
"id": "FKsKXvQUlaX5qt9n",
"name": "Header Auth account 3"
}
},
"typeVersion": 4
},
{
"id": "a0153ab0-3eaf-4f97-a2dc-ab63d45a9187",
"name": "Parse Umami",
"type": "n8n-nodes-base.code",
"position": [
1920,
260
],
"parameters": {
"jsCode": "// Get input data
const data = $input.all();
// Create URL-encoded string from the data
const encodedData = encodeURIComponent(JSON.stringify(data));
// Return the encoded data
return {
json: {
lastweek: encodedData
}
};"
},
"typeVersion": 2
},
{
"id": "c2d3d396-09fa-4800-b56d-40ed7592cd3c",
"name": "Send data to A.I.1",
"type": "n8n-nodes-base.httpRequest",
"position": [
2180,
260
],
"parameters": {
"url": "https://openrouter.ai/api/v1/chat/completions",
"method": "POST",
"options": {},
"jsonBody": "={
\"model\": \"meta-llama/llama-3.1-70b-instruct:free\",
\"messages\": [
{
\"role\": \"user\",
\"content\": \"You are an SEO expert. Here is data from Umami analytics of Pennibnotes.com. Where X is URL and Y is number of visitors. Compare the data from this week to last week. Present the data in a table using markdown and offer 5 improvement suggestions. This week:{{ $('Parse Umami data1').first().json.thisWeek }} Lastweek:{{ $json.lastweek }}\"
}
]
}
",
"sendBody": true,
"specifyBody": "json",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth"
},
"credentials": {
"httpHeaderAuth": {
"id": "WY7UkF14ksPKq3S8",
"name": "Header Auth account 2"
}
},
"typeVersion": 4.2
},
{
"id": "ce58a556-c05a-4395-88b0-3edecbad80e5",
"name": "Save data to Baserow",
"type": "n8n-nodes-base.baserow",
"position": [
2520,
260
],
"parameters": {
"tableId": 607,
"fieldsUi": {
"fieldValues": [
{
"fieldId": 5870,
"fieldValue": "={{ $json.choices[0].message.content }}"
},
{
"fieldId": 5869,
"fieldValue": "={{ $('Send data to A.I.').first().json.choices[0].message.content }}"
},
{
"fieldId": 5868,
"fieldValue": "={{ DateTime.now().toFormat('yyyy-MM-dd') }}"
},
{
"fieldId": 5871,
"fieldValue": "Name of your blog"
}
]
},
"operation": "create",
"databaseId": 121
},
"credentials": {
"baserowApi": {
"id": "8w0zXhycIfCAgja3",
"name": "Baserow account"
}
},
"typeVersion": 1
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "0c09e5c7-49a9-4f11-b93e-35659360fe02",
"connections": {
"Parse Umami": {
"main": [
[
{
"node": "Send data to A.I.1",
"type": "main",
"index": 0
}
]
]
},
"Parse Umami data": {
"main": [
[
{
"node": "Send data to A.I.",
"type": "main",
"index": 0
}
]
]
},
"Schedule Trigger": {
"main": [
[
{
"node": "Get view stats from Umami",
"type": "main",
"index": 0
}
]
]
},
"Parse Umami data1": {
"main": [
[
{
"node": "Get page view data from Umami",
"type": "main",
"index": 0
}
]
]
},
"Send data to A.I.": {
"main": [
[
{
"node": "Get page data from Umami",
"type": "main",
"index": 0
}
]
]
},
"Send data to A.I.1": {
"main": [
[
{
"node": "Save data to Baserow",
"type": "main",
"index": 0
}
]
]
},
"Get page data from Umami": {
"main": [
[
{
"node": "Parse Umami data1",
"type": "main",
"index": 0
}
]
]
},
"Get view stats from Umami": {
"main": [
[
{
"node": "Parse Umami data",
"type": "main",
"index": 0
}
]
]
},
"Get page view data from Umami": {
"main": [
[
{
"node": "Parse Umami",
"type": "main",
"index": 0
}
]
]
},
"When clicking ‘Test workflow’": {
"main": [
[
{
"node": "Get view stats from Umami",
"type": "main",
"index": 0
}
]
]
}
}
}
功能特点
- 自动检测新邮件
- AI智能内容分析
- 自定义分类规则
- 批量处理能力
- 详细的处理日志
技术分析
节点类型及作用
- Manualtrigger
- Scheduletrigger
- Httprequest
- Stickynote
- Code
复杂度评估
配置难度:
维护难度:
扩展性:
实施指南
前置条件
- 有效的Gmail账户
- n8n平台访问权限
- Google API凭证
- AI分类服务订阅
配置步骤
- 在n8n中导入工作流JSON文件
- 配置Gmail节点的认证信息
- 设置AI分类器的API密钥
- 自定义分类规则和标签映射
- 测试工作流执行
- 配置定时触发器(可选)
关键参数
| 参数名称 | 默认值 | 说明 |
|---|---|---|
| maxEmails | 50 | 单次处理的最大邮件数量 |
| confidenceThreshold | 0.8 | 分类置信度阈值 |
| autoLabel | true | 是否自动添加标签 |
最佳实践
优化建议
- 定期更新AI分类模型以提高准确性
- 根据邮件量调整处理批次大小
- 设置合理的分类置信度阈值
- 定期清理过期的分类规则
安全注意事项
- 妥善保管API密钥和认证信息
- 限制工作流的访问权限
- 定期审查处理日志
- 启用双因素认证保护Gmail账户
性能优化
- 使用增量处理减少重复工作
- 缓存频繁访问的数据
- 并行处理多个邮件分类任务
- 监控系统资源使用情况
故障排除
常见问题
邮件未被正确分类
检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。
Gmail认证失败
确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。
调试技巧
- 启用详细日志记录查看每个步骤的执行情况
- 使用测试邮件验证分类逻辑
- 检查网络连接和API服务状态
- 逐步执行工作流定位问题节点
错误处理
工作流包含以下错误处理机制:
- 网络超时自动重试(最多3次)
- API错误记录和告警
- 处理失败邮件的隔离机制
- 异常情况下的回滚操作