使用PageSpeed Insights监控网站性能并保存到Google Sheets并发送警报
高级
这是一个DevOps, Miscellaneous, Multimodal AI领域的自动化工作流,包含 20 个节点。主要使用 If, Set, Code, Gmail, Webhook 等节点。 使用PageSpeed Insights监控网站性能,发送警报到Google Sheets
前置要求
- •Google 账号和 Gmail API 凭证
- •HTTP Webhook 端点(n8n 会自动生成)
- •可能需要目标 API 的认证凭证
- •Google Sheets API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"id": "s9YeIkLvgkThgR3d",
"meta": {
"instanceId": "506e1eb999b7a8cf86103921b3e1b94e371534d9bae39d44754933678dc6697d",
"templateCredsSetupCompleted": true
},
"name": "使用 PageSpeed Insights 监控网站性能并保存到 Google Sheets 并发送警报",
"tags": [
{
"id": "T3xhK1cIuPex0boX",
"name": "Templates",
"createdAt": "2025-09-03T11:06:03.839Z",
"updatedAt": "2025-09-03T11:06:03.839Z"
}
],
"nodes": [
{
"id": "dfbcd954-aefb-45c0-b0cd-b8f7374e6126",
"name": "主模板说明",
"type": "n8n-nodes-base.stickyNote",
"position": [
-336,
-224
],
"parameters": {
"width": 700,
"height": 1764,
"content": "# 使用 PageSpeed Insights 监控网站性能并保存到 Google Sheets 并发送警报"
},
"typeVersion": 1
},
{
"id": "d1cedc16-b144-4a4f-8506-be91607bd7db",
"name": "按需测试说明",
"type": "n8n-nodes-base.stickyNote",
"position": [
448,
960
],
"parameters": {
"color": 4,
"width": 600,
"height": 112,
"content": "## 按需测试"
},
"typeVersion": 1
},
{
"id": "2ffb1551-9549-49a9-aeee-fdb5c12a87bf",
"name": "格式化 Webhook 输入",
"type": "n8n-nodes-base.set",
"position": [
672,
1136
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"name": "URL",
"type": "string",
"value": "={{ $json.body.url }}"
},
{
"name": "Site_Name",
"type": "string",
"value": "={{ $json.body.site_name || 'On-Demand Test' }}"
},
{
"name": "Alert_Threshold",
"type": "number",
"value": "={{ $json.body.alert_threshold || 75 }}"
},
{
"name": "device",
"type": "string",
"value": "={{ $json.body.device || 'mobile' }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "8ae6a002-9201-4adb-8cca-369097c6bbeb",
"name": "运行按需测试",
"type": "n8n-nodes-base.httpRequest",
"position": [
880,
1136
],
"parameters": {
"url": "=https://www.googleapis.com/pagespeedonline/v5/runPagespeed",
"options": {},
"sendQuery": true,
"queryParameters": {
"parameters": [
{
"name": "url",
"value": "={{ $json.URL }}"
},
{
"name": "key",
"value": "YOUR-API-KEY"
},
{
"name": "strategy",
"value": "={{ $json.device }}"
},
{
"name": "category",
"value": "performance"
}
]
}
},
"typeVersion": 4.2
},
{
"id": "7994e14d-6cfc-4db8-9fcb-da673ac03a98",
"name": "处理按需结果",
"type": "n8n-nodes-base.code",
"position": [
1072,
1136
],
"parameters": {
"jsCode": "// Same processing logic as scheduled audit\nconst response = $input.first().json;\nconst webhookData = $('Format Webhook Input').item.json;\n\n// Extract key metrics\nconst lighthouseResult = response.lighthouseResult;\nconst categories = lighthouseResult.categories;\nconst audits = lighthouseResult.audits;\n\n// Core Web Vitals\nconst lcp = audits['largest-contentful-paint']?.displayValue || 'N/A';\nconst fid = audits['max-potential-fid']?.displayValue || 'N/A';\nconst cls = audits['cumulative-layout-shift']?.displayValue || 'N/A';\n\n// Performance score (0-100)\nconst performanceScore = Math.round(categories.performance.score * 100);\n\n// Key recommendations\nconst recommendations = [];\nif (audits['unused-css-rules'] && audits['unused-css-rules'].score < 0.5) {\n recommendations.push('Remove unused CSS');\n}\nif (audits['render-blocking-resources'] && audits['render-blocking-resources'].score < 0.5) {\n recommendations.push('Eliminate render-blocking resources');\n}\nif (audits['unminified-css'] && audits['unminified-css'].score < 0.5) {\n recommendations.push('Minify CSS');\n}\nif (audits['unminified-javascript'] && audits['unminified-javascript'].score < 0.5) {\n recommendations.push('Minify JavaScript');\n}\nif (audits['uses-optimized-images'] && audits['uses-optimized-images'].score < 0.5) {\n recommendations.push('Optimize images');\n}\n\nreturn {\n json: {\n success: true,\n audit_date: new Date().toISOString(),\n url: webhookData.URL,\n site_name: webhookData.Site_Name,\n device: webhookData.device,\n performance_score: performanceScore,\n core_web_vitals: {\n lcp: lcp,\n fid: fid,\n cls: cls\n },\n recommendations: recommendations,\n full_report_url: response.id ? `https://pagespeed.web.dev/report?url=${encodeURIComponent(webhookData.URL)}` : 'N/A',\n raw_scores: {\n performance: categories.performance.score,\n accessibility: categories.accessibility?.score || null,\n 'best-practices': categories['best-practices']?.score || null,\n seo: categories.seo?.score || null\n }\n }\n};"
},
"typeVersion": 2
},
{
"id": "58e18dcc-9fce-4648-a3b9-51754f2e6c2b",
"name": "返回审计响应",
"type": "n8n-nodes-base.respondToWebhook",
"position": [
1280,
1136
],
"parameters": {
"options": {},
"respondWith": "allIncomingItems"
},
"typeVersion": 1.4
},
{
"id": "ae4b5083-903d-450b-8cc0-b9f49aaf714a",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"onError": "continueRegularOutput",
"maxTries": 2,
"position": [
464,
1136
],
"webhookId": "2e00a9c8-71fc-4f79-999c-bd93ac9473d5",
"parameters": {
"path": "2e00a9c8-71fc-4f79-999c-bd93ac9473d5",
"options": {},
"httpMethod": "POST",
"responseMode": "responseNode"
},
"executeOnce": false,
"retryOnFail": true,
"typeVersion": 2.1
},
{
"id": "e8b625d3-44fa-4599-accf-ea576a05708b",
"name": "计划审计说明",
"type": "n8n-nodes-base.stickyNote",
"position": [
448,
-208
],
"parameters": {
"color": 3,
"width": 600,
"height": 144,
"content": "## 计划审计工作流"
},
"typeVersion": 1
},
{
"id": "505706c1-0d0f-48c6-8585-b44cb98d114d",
"name": "运行 PageSpeed 测试",
"type": "n8n-nodes-base.httpRequest",
"position": [
1360,
64
],
"parameters": {
"url": "=https://www.googleapis.com/pagespeedonline/v5/runPagespeed",
"options": {},
"sendQuery": true,
"queryParameters": {
"parameters": [
{
"name": "url",
"value": "={{ $json.URL }}"
},
{
"name": "key",
"value": "=YOUR-API-KEY"
},
{
"name": "strategy",
"value": "={{ $json.Device }}"
},
{
"name": "category",
"value": "={{ $('Load Sites from Google Sheet').item.json.Category }}"
}
]
}
},
"typeVersion": 4.2
},
{
"id": "711ea54b-01aa-424d-904c-be5d30a6c1b9",
"name": "处理审计结果",
"type": "n8n-nodes-base.code",
"position": [
1648,
64
],
"parameters": {
"jsCode": "const response = $input.first().json;\nconst siteData = $('Load Sites from Google Sheet').item.json;\n\n// Extract key metrics\nconst lighthouseResult = response.lighthouseResult;\nconst categories = lighthouseResult.categories;\nconst audits = lighthouseResult.audits;\n\n// Core Web Vitals\nconst lcp = audits['largest-contentful-paint']?.displayValue || 'N/A';\nconst fid = audits['max-potential-fid']?.displayValue || 'N/A';\nconst cls = audits['cumulative-layout-shift']?.displayValue || 'N/A';\n\n// Performance score (0-100)\nconst performanceScore = Math.round(categories.performance.score * 100);\n\n// IMPROVED ALERT LOGIC\nconst alertThreshold = parseInt(siteData.Alert_Threshold) || 75; // Ensure it's a number\nconst shouldAlert = performanceScore < alertThreshold;\n\n// SEVERITY LEVELS for better alerting\nlet alertSeverity = 'info';\nlet alertMessage = 'Performance within acceptable range';\n\nif (performanceScore < 30) {\n alertSeverity = 'critical';\n alertMessage = '🚨 CRITICAL: Extremely poor performance';\n} else if (performanceScore < 50) {\n alertSeverity = 'high';\n alertMessage = '⚠️ HIGH: Poor performance affecting user experience';\n} else if (performanceScore < alertThreshold) {\n alertSeverity = 'medium';\n alertMessage = '⚠️ MEDIUM: Performance below threshold';\n} else if (performanceScore < 80) {\n alertSeverity = 'low';\n alertMessage = 'ℹ️ LOW: Room for improvement';\n}\n\n// Key recommendations (unchanged)\nconst recommendations = [];\nif (audits['unused-css-rules'] && audits['unused-css-rules'].score < 0.5) {\n recommendations.push('Remove unused CSS');\n}\nif (audits['render-blocking-resources'] && audits['render-blocking-resources'].score < 0.5) {\n recommendations.push('Eliminate render-blocking resources');\n}\n// ... other recommendations\n\nreturn {\n json: {\n date: new Date().toISOString().split('T')[0],\n url: siteData.URL,\n site_name: siteData.Site_Name,\n category: siteData.Category || 'General',\n device: $json.device,\n performance_score: performanceScore,\n lcp: lcp,\n fid: fid,\n cls: cls,\n recommendations: recommendations.join(', ') || 'No major issues detected',\n full_report_url: response.id ? `https://pagespeed.web.dev/report?url=${encodeURIComponent(siteData.URL)}` : 'N/A',\n \n // IMPROVED ALERT DATA\n should_alert: shouldAlert,\n alert_threshold: alertThreshold,\n alert_severity: alertSeverity,\n alert_message: alertMessage,\n \n // PERFORMANCE CATEGORY\n performance_category: performanceScore >= 90 ? 'excellent' : \n performanceScore >= 50 ? 'needs_improvement' : 'poor'\n }\n};"
},
"typeVersion": 2
},
{
"id": "882e6e4f-a9a6-4dd8-abd3-ab4262781b7d",
"name": "保存审计结果",
"type": "n8n-nodes-base.googleSheets",
"position": [
1904,
64
],
"parameters": {
"columns": {
"value": {
"CLS": "={{ $json.cls }}",
"FID": "={{ $json.fid }}",
"LCP": "={{ $json.lcp }}",
"URL": "={{ $json.url }}",
"Date": "={{ $json.date }}",
"Device": "{{ $json.Device }}",
"Site_Name": "={{ $json.site_name }}",
"Recommendatios": "={{ $json.recommendations }}",
"Full_Report_URL": "={{ $json.full_report_url }}",
"Performance_Score": "={{ $json.performance_score }}"
},
"schema": [
{
"id": "Date",
"type": "string",
"display": true,
"required": false,
"displayName": "Date",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "URL",
"type": "string",
"display": true,
"required": false,
"displayName": "URL",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Site_Name",
"type": "string",
"display": true,
"required": false,
"displayName": "Site_Name",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Device",
"type": "string",
"display": true,
"required": false,
"displayName": "Device",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Performance_Score",
"type": "string",
"display": true,
"required": false,
"displayName": "Performance_Score",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "LCP",
"type": "string",
"display": true,
"required": false,
"displayName": "LCP",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "FID",
"type": "string",
"display": true,
"required": false,
"displayName": "FID",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "CLS",
"type": "string",
"display": true,
"required": false,
"displayName": "CLS",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Recommendatios",
"type": "string",
"display": true,
"required": false,
"displayName": "Recommendatios",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Full_Report_URL",
"type": "string",
"display": true,
"required": false,
"displayName": "Full_Report_URL",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"options": {},
"operation": "append",
"sheetName": {
"__rl": true,
"mode": "list",
"value": 1367646124,
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/158cVb-BnFu3eGiabTrMR59f-Yl5ThsUMWC2WPERzaAI/edit#gid=1367646124",
"cachedResultName": "audit_results"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "158cVb-BnFu3eGiabTrMR59f-Yl5ThsUMWC2WPERzaAI",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/158cVb-BnFu3eGiabTrMR59f-Yl5ThsUMWC2WPERzaAI/edit?usp=drivesdk",
"cachedResultName": "n8n_website_audite_templace"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "aTC1xknA5P6BIbgt",
"name": "Dahiana's (Google Sheets Account)"
}
},
"typeVersion": 4.6
},
{
"id": "24a4a27d-d746-4d8b-a4a3-df33086f29db",
"name": "检查警报阈值",
"type": "n8n-nodes-base.if",
"position": [
2352,
64
],
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{ $('Process Audit Results').item.json.should_alert }}",
"value2": true
}
]
}
},
"typeVersion": 1
},
{
"id": "2ddf6c22-2094-47d6-a1ce-32e01693e43b",
"name": "计划触发器",
"type": "n8n-nodes-base.scheduleTrigger",
"position": [
464,
64
],
"parameters": {
"rule": {
"interval": [
{
"field": "weeks"
}
]
}
},
"typeVersion": 1.2
},
{
"id": "28198a35-077b-46bb-8f26-b0a4fc432d52",
"name": "过滤未处理的站点",
"type": "n8n-nodes-base.code",
"position": [
1024,
64
],
"parameters": {
"jsCode": "// Get today's date in YYYY-MM-DD format\nconst today = new Date().toISOString().split('T')[0];\n\nconst sitesToProcess = [];\n\nfor (const site of $input.all()) {\n const lastProcessed = site.json.Last_Processed_Date;\n \n // If never processed OR processed on a different date, include it\n if (!lastProcessed || lastProcessed === '' || lastProcessed !== today) {\n sitesToProcess.push(site);\n }\n}\n\nreturn sitesToProcess;"
},
"typeVersion": 2
},
{
"id": "7988d3d0-5f19-49d4-a189-4d43d419a8d0",
"name": "发送消息",
"type": "n8n-nodes-base.gmail",
"position": [
2656,
-32
],
"webhookId": "3ee36113-745a-4a73-a2bc-aadd85a61f1a",
"parameters": {
"sendTo": "EMAIL-THE-PERSON-IN-CHARGE",
"message": "={{ $('Process Audit Results').item.json.alert_message }}",
"options": {},
"subject": "=Audit results from {{ $('Process Audit Results').item.json.date }}"
},
"credentials": {
"gmailOAuth2": {
"id": "bfOHLfupXBRqCzXU",
"name": "Gmail account"
}
},
"typeVersion": 2.1
},
{
"id": "5ffb3bca-94ea-427f-b0d6-07b77beacfb7",
"name": "计划审计说明1",
"type": "n8n-nodes-base.stickyNote",
"position": [
2848,
-48
],
"parameters": {
"color": 7,
"width": 328,
"height": 128,
"content": "## 选择适合您的方式"
},
"typeVersion": 1
},
{
"id": "d8c76ba1-07bc-4905-a968-bea291565885",
"name": "计划审计说明2",
"type": "n8n-nodes-base.stickyNote",
"position": [
896,
224
],
"parameters": {
"color": 7,
"width": 392,
"height": 432,
"content": "### 过滤未处理的站点"
},
"typeVersion": 1
},
{
"id": "7215e78a-e6b7-4725-9f99-1152aac6d1e6",
"name": "从 Google Sheet 加载站点",
"type": "n8n-nodes-base.googleSheets",
"maxTries": 2,
"position": [
704,
64
],
"parameters": {
"options": {},
"sheetName": {
"__rl": true,
"mode": "list",
"value": 1748870974,
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/158cVb-BnFu3eGiabTrMR59f-Yl5ThsUMWC2WPERzaAI/edit#gid=1748870974",
"cachedResultName": "sites"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "158cVb-BnFu3eGiabTrMR59f-Yl5ThsUMWC2WPERzaAI",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/158cVb-BnFu3eGiabTrMR59f-Yl5ThsUMWC2WPERzaAI/edit?usp=drivesdk",
"cachedResultName": "n8n_website_audite_templace"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "ORvs3CshMAYZy9Zg",
"name": "Google Sheets account"
}
},
"retryOnFail": true,
"typeVersion": 4.7
},
{
"id": "9fcc0d28-480e-4674-a2d1-74a795afd90a",
"name": "跳过警报(性能正常)",
"type": "n8n-nodes-base.noOp",
"position": [
2656,
160
],
"parameters": {},
"typeVersion": 1
},
{
"id": "8e4cac66-8c85-418e-9a42-54fd3352496f",
"name": "更新审计日期",
"type": "n8n-nodes-base.googleSheets",
"position": [
2144,
64
],
"parameters": {
"options": {},
"filtersUI": {
"values": [
{
"lookupValue": "={{ $json.URL }}",
"lookupColumn": "URL"
},
{
"lookupValue": "={{ new Date().toISOString().split('T')[0] }}",
"lookupColumn": "Last_Processed_Date"
}
]
},
"sheetName": {
"__rl": true,
"mode": "list",
"value": 1748870974,
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/158cVb-BnFu3eGiabTrMR59f-Yl5ThsUMWC2WPERzaAI/edit#gid=1748870974",
"cachedResultName": "sites"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "158cVb-BnFu3eGiabTrMR59f-Yl5ThsUMWC2WPERzaAI",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/158cVb-BnFu3eGiabTrMR59f-Yl5ThsUMWC2WPERzaAI/edit?usp=drivesdk",
"cachedResultName": "n8n_website_audite_templace"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "ORvs3CshMAYZy9Zg",
"name": "Google Sheets account"
}
},
"typeVersion": 4.7
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "e9cd91e5-8cf5-48a3-8f4c-1223e7e4e5c1",
"connections": {
"Webhook": {
"main": [
[
{
"node": "Format Webhook Input",
"type": "main",
"index": 0
}
]
]
},
"Schedule Trigger": {
"main": [
[
{
"node": "Load Sites from Google Sheet",
"type": "main",
"index": 0
}
]
]
},
"Update Audit Date": {
"main": [
[
{
"node": "Check Alert Threshold",
"type": "main",
"index": 0
}
]
]
},
"Run On-Demand Test": {
"main": [
[
{
"node": "Process On-Demand Results",
"type": "main",
"index": 0
}
]
]
},
"Run PageSpeed Test": {
"main": [
[
{
"node": "Process Audit Results",
"type": "main",
"index": 0
}
]
]
},
"Save Audit Results": {
"main": [
[
{
"node": "Update Audit Date",
"type": "main",
"index": 0
}
]
]
},
"Format Webhook Input": {
"main": [
[
{
"node": "Run On-Demand Test",
"type": "main",
"index": 0
}
]
]
},
"Check Alert Threshold": {
"main": [
[
{
"node": "Send a message",
"type": "main",
"index": 0
}
],
[
{
"node": "Skip Alert (Performance OK)",
"type": "main",
"index": 0
}
]
]
},
"Process Audit Results": {
"main": [
[
{
"node": "Save Audit Results",
"type": "main",
"index": 0
}
]
]
},
"Filter Unprocessed Sites": {
"main": [
[
{
"node": "Run PageSpeed Test",
"type": "main",
"index": 0
}
]
]
},
"Process On-Demand Results": {
"main": [
[
{
"node": "Return Audit Response",
"type": "main",
"index": 0
}
]
]
},
"Load Sites from Google Sheet": {
"main": [
[
{
"node": "Filter Unprocessed Sites",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
高级 - 开发运维, 杂项, 多模态 AI
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
竞争对手内容差距分析器:自动化网站主题映射
使用Gemini AI、Apify和Google Sheets分析竞争对手内容差距
If
Set
Code
+10
30 节点Mychel Garzon
杂项
批量SEO内容生成与带AI图片的Webflow草稿创建(模板)
使用GPT、Gemini图片和Webflow草稿创建进行批量SEO内容生成
If
Set
Code
+18
54 节点Dahiana
内容创作
每日 WhatsApp 群组智能分析:GPT-4.1 分析与语音消息转录
每日 WhatsApp 群组智能分析:GPT-4.1 分析与语音消息转录
If
Set
Code
+20
52 节点Daniel Lianes
杂项
GitHub 同步仪表板 - V2
具有提交历史和回滚功能的 GitHub 工作流版本控制仪表板
If
N8n
Set
+20
94 节点Eduard
开发运维
防欺诈潜在客户捕获与培育系统
通过AI评分、表格跟踪和多渠道提醒捕获和培育防欺诈潜在客户
If
Set
Code
+11
28 节点Jitesh Dugar
内容创作
使用 YouTube Transcript API 提取 YouTube 视频字幕
通过Google Sheets或API Webhook提取YouTube字幕
Code
Webhook
Http Request
+4
13 节点Dahiana
市场调研
工作流信息
难度等级
高级
节点数量20
分类3
节点类型11
作者
Dahiana
@mssportoNo-Code Specialist with more than 10 years of experience in Digital Marketing. Currently working with Bubble. Webflow, AI, Agents and N8N.
外部链接
在 n8n.io 查看 →
分享此工作流