SERPBear analytics template
工作流概述
这是一个包含10个节点的复杂工作流,主要用于自动化处理各种任务。
工作流源代码
{
"id": "qmmXKcpJOCm9qaCk",
"meta": {
"instanceId": "558d88703fb65b2d0e44613bc35916258b0f0bf983c5d4730c00c424b77ca36a",
"templateCredsSetupCompleted": true
},
"name": "SERPBear analytics template",
"tags": [],
"nodes": [
{
"id": "2ad0eb40-6628-4c6b-bc15-7081e7712f1a",
"name": "When clicking ‘Test workflow’",
"type": "n8n-nodes-base.manualTrigger",
"position": [
260,
380
],
"parameters": {},
"typeVersion": 1
},
{
"id": "5a3c9ad8-a562-4bb0-bb11-c325552d8101",
"name": "Schedule Trigger",
"type": "n8n-nodes-base.scheduleTrigger",
"position": [
260,
160
],
"parameters": {
"rule": {
"interval": [
{
"field": "weeks"
}
]
}
},
"typeVersion": 1.2
},
{
"id": "bdfa7388-f9b3-4145-90de-2e58138e14bf",
"name": "Get data from SerpBear",
"type": "n8n-nodes-base.httpRequest",
"position": [
580,
260
],
"parameters": {
"url": "https://myserpbearinstance.com/api/keyword?id=22",
"options": {},
"sendQuery": true,
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth",
"queryParameters": {
"parameters": [
{
"name": "domain",
"value": "rumjahn.com"
}
]
}
},
"credentials": {
"httpHeaderAuth": {
"id": "3fshHb4fyI5XfLyq",
"name": "Header Auth account 6"
}
},
"executeOnce": false,
"typeVersion": 4.2,
"alwaysOutputData": false
},
{
"id": "c169f4e3-ab60-4b46-9f49-cf27a13dd7c6",
"name": "Parse data from SerpBear",
"type": "n8n-nodes-base.code",
"position": [
820,
260
],
"parameters": {
"jsCode": "const keywords = items[0].json.keywords;
const today = new Date().toISOString().split('T')[0];
// Create summary for each keyword
const keywordSummaries = keywords.map(kw => {
const position = kw.position || 0;
const lastWeekPositions = Object.values(kw.history || {}).slice(-7);
const avgPosition = lastWeekPositions.reduce((a, b) => a + b, 0) / lastWeekPositions.length;
return {
keyword: kw.keyword,
currentPosition: position,
averagePosition: Math.round(avgPosition * 10) / 10,
trend: position < avgPosition ? 'improving' : position > avgPosition ? 'declining' : 'stable',
url: kw.url || 'not ranking'
};
});
// Create the prompt
const prompt = `Here's the SEO ranking data for rumjahn.com as of ${today}:
${keywordSummaries.map(kw => `
Keyword: \"${kw.keyword}\"
Current Position: ${kw.currentPosition}
7-Day Average: ${kw.averagePosition}
Trend: ${kw.trend}
Ranking URL: ${kw.url}
`).join('\n')}
Please analyze this data and provide:
1. Key observations about ranking performance
2. Keywords showing the most improvement
3. Keywords needing attention
4. Suggested actions for improvement`;
return {
prompt
};"
},
"typeVersion": 2
},
{
"id": "cc6e16a7-db46-42fe-837a-59ce635c906c",
"name": "Send data to A.I. for analysis",
"type": "n8n-nodes-base.httpRequest",
"position": [
1060,
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. This is keyword data for my site. Can you summarize the data into a table and then give me some suggestions:{{ encodeURIComponent($json.prompt)}}\"
}
]
}",
"sendBody": true,
"specifyBody": "json",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth"
},
"credentials": {
"httpHeaderAuth": {
"id": "WY7UkF14ksPKq3S8",
"name": "Header Auth account 2"
}
},
"typeVersion": 4.2,
"alwaysOutputData": false
},
{
"id": "a623f06c-1dfe-4d04-a7fd-fed7049a7588",
"name": "Save data to Baserow",
"type": "n8n-nodes-base.baserow",
"position": [
1340,
260
],
"parameters": {
"tableId": 644,
"fieldsUi": {
"fieldValues": [
{
"fieldId": 6264,
"fieldValue": "={{ DateTime.now().toFormat('yyyy-MM-dd') }}"
},
{
"fieldId": 6265,
"fieldValue": "={{ $json.choices[0].message.content }}"
},
{
"fieldId": 6266,
"fieldValue": "Rumjahn"
}
]
},
"operation": "create",
"databaseId": 121
},
"credentials": {
"baserowApi": {
"id": "8w0zXhycIfCAgja3",
"name": "Baserow account"
}
},
"typeVersion": 1
},
{
"id": "e8048faf-bbed-4e48-b273-d1a50a767e76",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
220,
-360
],
"parameters": {
"color": 5,
"width": 614.709677419355,
"height": 208.51612903225802,
"content": "## Send Matomo analytics to A.I. and save results to baserow
This workflow will check the Google keywords for your site and it's rank.
[💡 You can read more about this workflow here](https://rumjahn.com/how-to-create-an-a-i-agent-to-analyze-serpbear-keyword-rankings-using-n8n-for-free-without-any-coding-skills-required/)"
},
"typeVersion": 1
},
{
"id": "1a18e685-79db-423f-992a-5e0d4ddeb672",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
520,
-80
],
"parameters": {
"width": 214.75050403225822,
"height": 531.7318548387107,
"content": "## Get SERPBear Data
1. Enter your SerpBear API keys and URL. You need to find your website ID which is probably 1.
2. Navigate to Administration > Personal > Security > Auth tokens within your Matomo dashboard. Click on Create new token and provide a purpose for reference."
},
"typeVersion": 1
},
{
"id": "99895baf-75d0-4af2-87de-5b8951186e78",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
980,
-60
],
"parameters": {
"color": 3,
"width": 225.99936321742769,
"height": 508.95792207792226,
"content": "## Send data to A.I.
Fill in your Openrouter A.I. credentials. Use Header Auth.
- Username: Authorization
- Password: Bearer {insert your API key}
Remember to add a space after bearer. Also, feel free to modify the prompt to A.1."
},
"typeVersion": 1
},
{
"id": "07d03511-98b0-4f4a-8e68-96ca177fb246",
"name": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"position": [
1240,
-40
],
"parameters": {
"color": 6,
"width": 331.32883116883124,
"height": 474.88,
"content": "## Send data to Baserow
Create a table first with the following columns:
- Date
- Note
- Blog
Enter the name of your website under \"Blog\" field."
},
"typeVersion": 1
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "8b7e7da7-1965-4ca4-8e15-889eda819723",
"connections": {
"Schedule Trigger": {
"main": [
[
{
"node": "Get data from SerpBear",
"type": "main",
"index": 0
}
]
]
},
"Get data from SerpBear": {
"main": [
[
{
"node": "Parse data from SerpBear",
"type": "main",
"index": 0
}
]
]
},
"Parse data from SerpBear": {
"main": [
[
{
"node": "Send data to A.I. for analysis",
"type": "main",
"index": 0
}
]
]
},
"Send data to A.I. for analysis": {
"main": [
[
{
"node": "Save data to Baserow",
"type": "main",
"index": 0
}
]
]
},
"When clicking ‘Test workflow’": {
"main": [
[
{
"node": "Get data from SerpBear",
"type": "main",
"index": 0
}
]
]
}
}
}
功能特点
- 自动检测新邮件
- AI智能内容分析
- 自定义分类规则
- 批量处理能力
- 详细的处理日志
技术分析
节点类型及作用
- Manualtrigger
- Scheduletrigger
- Httprequest
- Code
- Baserow
复杂度评估
配置难度:
维护难度:
扩展性:
实施指南
前置条件
- 有效的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错误记录和告警
- 处理失败邮件的隔离机制
- 异常情况下的回滚操作