Google Analytics到Discord
高级
这是一个Market Research领域的自动化工作流,包含 34 个节点。主要使用 Set, Code, Sort, Wait, Switch 等节点。 多个Google Analytics账户的Discord每日摘要
前置要求
- •Discord Bot Token 或 Webhook
- •可能需要目标 API 的认证凭证
使用的节点 (34)
分类
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"id": "EkiPj955iLTz4N2X",
"meta": {
"instanceId": "52254486b159b349334953c1738da94e90477c7604aa8db2062d11afc0120739",
"templateCredsSetupCompleted": true
},
"name": "Google Analytics 到 Discord",
"tags": [
{
"id": "ieqEVthNwLDfYSc1",
"name": "Emp0",
"createdAt": "2025-05-06T11:04:25.307Z",
"updatedAt": "2025-05-06T11:04:25.307Z"
}
],
"nodes": [
{
"id": "d3bf8c74-1adf-46ca-8bb0-18ad83a1a3e7",
"name": "编辑字段2",
"type": "n8n-nodes-base.set",
"position": [
440,
80
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "c89a369e-0c67-476f-8227-b56b2b1c87b3",
"name": "discord_channel_id",
"type": "string",
"value": ""
},
{
"id": "0bc05648-2f31-4757-8703-75d3c7f80917",
"name": "google_analytics_id",
"type": "string",
"value": "="
}
]
}
},
"typeVersion": 3.4
},
{
"id": "6592e781-3b51-44c7-9b60-0d38cb6143b2",
"name": "编辑字段3",
"type": "n8n-nodes-base.set",
"position": [
440,
280
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "c89a369e-0c67-476f-8227-b56b2b1c87b3",
"name": "discord_channel_id",
"type": "string",
"value": ""
},
{
"id": "be197313-7b88-462a-8ff7-9bb9ddf7e846",
"name": "google_analytics_id",
"type": "string",
"value": ""
}
]
}
},
"typeVersion": 3.4
},
{
"id": "325bcec9-276a-4a62-9755-04c3033f385f",
"name": "Google Analytics",
"type": "n8n-nodes-base.googleAnalytics",
"position": [
820,
380
],
"parameters": {
"metricsGA4": {
"metricValues": [
{},
{
"listName": "active1DayUsers"
},
{
"listName": "active7DayUsers"
},
{
"listName": "eventCount"
},
{
"listName": "screenPageViews"
},
{
"listName": "userEngagementDuration"
}
]
},
"propertyId": {
"__rl": true,
"mode": "id",
"value": "={{ $json.google_analytics_id }}"
},
"dimensionsGA4": {
"dimensionValues": [
{}
]
},
"additionalFields": {}
},
"credentials": {
"googleAnalyticsOAuth2": {
"id": "2MUaxG3VpYuVQyJi",
"name": "Ganalytics - user@gmail.com"
}
},
"typeVersion": 2
},
{
"id": "e8b1a2da-d59f-44fb-8d03-60e6304d0d3a",
"name": "计划触发器",
"type": "n8n-nodes-base.scheduleTrigger",
"position": [
280,
280
],
"parameters": {
"rule": {
"interval": [
{
"triggerAtHour": 21,
"triggerAtMinute": 51
}
]
}
},
"typeVersion": 1.2
},
{
"id": "5b91ccf6-5397-4e4b-97a9-bbe196ddbc8e",
"name": "计划触发器1",
"type": "n8n-nodes-base.scheduleTrigger",
"position": [
280,
80
],
"parameters": {
"rule": {
"interval": [
{
"triggerAtHour": 21,
"triggerAtMinute": 50
}
]
}
},
"typeVersion": 1.2
},
{
"id": "9073f015-ae42-4461-b423-88fa2d45c205",
"name": "排序",
"type": "n8n-nodes-base.sort",
"position": [
980,
380
],
"parameters": {
"options": {},
"sortFieldsUi": {
"sortField": [
{
"fieldName": "date"
}
]
}
},
"typeVersion": 1
},
{
"id": "a71e1cdd-ddc3-458d-b349-638ad0d59146",
"name": "Discord",
"type": "n8n-nodes-base.discord",
"position": [
1280,
380
],
"webhookId": "6cc9c7b4-4b8e-4b01-a125-d16c6f9c2e15",
"parameters": {
"limit": 10,
"guildId": {
"__rl": true,
"mode": "list",
"value": "1363068664886329397"
},
"options": {},
"resource": "message",
"channelId": {
"__rl": true,
"mode": "id",
"value": "={{ $('Code1').first().json.discord_channel_id }}"
},
"operation": "getAll",
"authentication": "oAuth2"
},
"credentials": {
"discordOAuth2Api": {
"id": "aAorRULaRsUXUcmc",
"name": "Discord - jarvis_bot"
}
},
"typeVersion": 2,
"alwaysOutputData": true
},
{
"id": "67074924-8e24-4cf2-bc0b-115112b1bcef",
"name": "代码",
"type": "n8n-nodes-base.code",
"position": [
1620,
380
],
"parameters": {
"jsCode": "// n8n Function Node\n\n// 1. Grab GA records\nconst gaRecords = $('gaData').first().json.gaData;\nconst discord_channel_id = $('Code1').first().json.discord_channel_id;\n\n// 2. Grab Discord messages and unpack their .json\nconst discordMsgs = $input.all().map(item => item.json);\n\n// Helper: get embed field by name\nfunction getEmbedField(msg, name) {\n return msg.embeds?.[0]?.fields.find(f => f.name === name)?.value || null;\n}\n\n// Format JS Date to dd-MM-yyyy\nfunction formatDate(dateObj) {\n const dd = String(dateObj.getDate()).padStart(2,'0');\n const mm = String(dateObj.getMonth()+1).padStart(2,'0');\n const yyyy = dateObj.getFullYear();\n return `${dd}-${mm}-${yyyy}`;\n}\n\nconst today = formatDate(new Date());\n\n// Build lookup of Discord messages by Date\nconst discordByDate = {};\nfor (const msg of discordMsgs) {\n const date = getEmbedField(msg, 'Date');\n if (date) discordByDate[date] = msg;\n}\n\nconst results = [];\n\nfor (const wrapper of gaRecords) {\n const rec = wrapper.json;\n const dateKey = rec.date;\n const existing = discordByDate[dateKey];\n\n // Prepare new fields\n const newFields = [\n { name: 'Date', value: rec.date, inline: true },\n { name: 'totalUsers', value: rec.totalUsers, inline: true },\n { name: 'active1DayUsers', value: rec.active1DayUsers, inline: true },\n { name: 'active7DayUsers', value: rec.active7DayUsers, inline: true },\n { name: 'eventCount', value: rec.eventCount, inline: true },\n { name: 'screenPageViews', value: rec.screenPageViews, inline: true },\n { name: 'userEngagementDuration', value: rec.userEngagementDuration, inline: true },\n { name: 'createdAt', value: existing ? getEmbedField(existing, 'createdAt') : today, inline: true },\n { name: 'updatedAt', value: today, inline: true },\n ];\n\n // If exists, compare fields to avoid unnecessary updates\n if (existing) {\n let changed = false;\n for (const field of newFields) {\n if (getEmbedField(existing, field.name) !== field.value) {\n changed = true;\n break;\n }\n }\n if (changed) {\n results.push({\n action: 'update',\n messageId: existing.id,\n channelId: discord_channel_id,\n payload: {\n content: '',\n embeds: [{\n type: 'rich',\n color: 16751872,\n fields: newFields,\n footer: {\n text: 'Google Analytics',\n icon_url: 'https://images-ext-1.discordapp.net/external/BO599wb-y-yg7GM59J_ZSexsGRd2zIqOF98eJ89J_04/https/www.gstatic.com/analytics-suite/header/suite/v2/ic_analytics.svg'\n }\n }]\n }\n });\n }\n } else {\n // New record → create\n results.push({\n action: 'create',\n channelId: discord_channel_id,\n payload: {\n content: '',\n embeds: [{\n type: 'rich',\n color: 16751872,\n fields: newFields,\n footer: {\n text: 'Google Analytics',\n icon_url: 'https://images-ext-1.discordapp.net/external/BO599wb-y-yg7GM59J_ZSexsGRd2zIqOF98eJ89J_04/https/www.gstatic.com/analytics-suite/header/suite/v2/ic_analytics.svg'\n }\n }]\n }\n });\n }\n}\n\n// Return array for next nodes\nreturn results.map(r => ({ json: r }));\n"
},
"typeVersion": 2
},
{
"id": "01594d3d-7bc9-425c-af39-27c69d825321",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-40,
40
],
"parameters": {
"width": 640,
"height": 180,
"content": "## Google Analytics 属性 1"
},
"typeVersion": 1
},
{
"id": "04ed2530-fa65-427f-9019-bf970055481c",
"name": "便签 3",
"type": "n8n-nodes-base.stickyNote",
"position": [
-40,
240
],
"parameters": {
"width": 640,
"height": 180,
"content": "## Google Analytics 属性 2"
},
"typeVersion": 1
},
{
"id": "7567b2b8-2c12-42d8-898a-be7f59414061",
"name": "代码1",
"type": "n8n-nodes-base.code",
"position": [
680,
380
],
"parameters": {
"jsCode": "return $input.all();"
},
"typeVersion": 2
},
{
"id": "84d96e4a-2da5-4823-ba06-ec56346c5247",
"name": "gaData",
"type": "n8n-nodes-base.code",
"position": [
1120,
380
],
"parameters": {
"jsCode": "return {\"gaData\":$input.all()}"
},
"typeVersion": 2
},
{
"id": "6ea881a9-19ef-4f4c-815c-efd5b963a7fc",
"name": "HTTP 请求",
"type": "n8n-nodes-base.httpRequest",
"position": [
2380,
200
],
"parameters": {
"url": "=https://discord.com/api/v10/channels/{{ $json.channelId }}/messages",
"method": "POST",
"options": {},
"jsonBody": "={{ $json.payload }}",
"sendBody": true,
"sendHeaders": true,
"specifyBody": "json",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth",
"headerParameters": {
"parameters": [
{
"name": "Content-Type",
"value": "application/json"
}
]
}
},
"credentials": {
"httpHeaderAuth": {
"id": "flhKBJwaIL2eyx1u",
"name": "Header Auth - discord"
}
},
"typeVersion": 4.2
},
{
"id": "e27342c6-4128-4be3-bf95-1d11fdc36126",
"name": "HTTP 请求8",
"type": "n8n-nodes-base.httpRequest",
"position": [
2340,
620
],
"parameters": {
"url": "=https://discord.com/api/v10/channels/{{ $json.channelId }}/messages/{{ $json.messageId }}",
"method": "PATCH",
"options": {},
"jsonBody": "={{ $json.payload }}",
"sendBody": true,
"sendHeaders": true,
"specifyBody": "json",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth",
"headerParameters": {
"parameters": [
{
"name": "Content-Type",
"value": "application/json"
}
]
}
},
"credentials": {
"httpHeaderAuth": {
"id": "flhKBJwaIL2eyx1u",
"name": "Header Auth - discord"
}
},
"typeVersion": 4.2
},
{
"id": "113d9181-b7f5-455c-8c98-3592b223544a",
"name": "条件分支",
"type": "n8n-nodes-base.switch",
"position": [
1840,
380
],
"parameters": {
"rules": {
"values": [
{
"outputKey": "create",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "0fada883-e01d-402f-a582-960511303d1f",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.action }}",
"rightValue": "create"
}
]
},
"renameOutput": true
},
{
"outputKey": "update",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "28274b49-c3eb-49cc-9e22-ee10e0be456f",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.action }}",
"rightValue": "update"
}
]
},
"renameOutput": true
}
]
},
"options": {}
},
"typeVersion": 3.2
},
{
"id": "e1bb4d90-07d8-4d9a-9fa9-77969b980973",
"name": "遍历项目",
"type": "n8n-nodes-base.splitInBatches",
"position": [
2140,
600
],
"parameters": {
"options": {}
},
"typeVersion": 3
},
{
"id": "cb148176-64d2-412d-b93f-7a4f41f71bb6",
"name": "等待",
"type": "n8n-nodes-base.wait",
"position": [
2560,
620
],
"webhookId": "1b5c93e8-676d-49fa-acf3-46aeefbcc167",
"parameters": {
"amount": 10
},
"typeVersion": 1.1
},
{
"id": "32daa189-fbf3-456f-8fe1-532ea5329163",
"name": "遍历项目4",
"type": "n8n-nodes-base.splitInBatches",
"position": [
2140,
160
],
"parameters": {
"options": {}
},
"typeVersion": 3
},
{
"id": "acfea1dc-6154-419a-bfc3-33d38b88d392",
"name": "等待4",
"type": "n8n-nodes-base.wait",
"position": [
2560,
180
],
"webhookId": "97dcc624-188f-422e-a852-3c33f67666ce",
"parameters": {
"amount": 10
},
"typeVersion": 1.1
},
{
"id": "d2aebef9-605a-471a-b0cd-c90946e0ecaf",
"name": "便签 1",
"type": "n8n-nodes-base.stickyNote",
"position": [
2060,
20
],
"parameters": {
"color": 5,
"width": 700,
"height": 360,
"content": "## 发送新的 Discord 消息"
},
"typeVersion": 1
},
{
"id": "530cb064-a232-4791-8041-d2e86d081687",
"name": "便签 2",
"type": "n8n-nodes-base.stickyNote",
"position": [
2060,
440
],
"parameters": {
"color": 5,
"width": 700,
"height": 400,
"content": "## 更新现有的 Discord 消息"
},
"typeVersion": 1
},
{
"id": "04c66040-d5dd-46df-874c-13a2f41e5bee",
"name": "编辑字段",
"type": "n8n-nodes-base.set",
"position": [
440,
480
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "c89a369e-0c67-476f-8227-b56b2b1c87b3",
"name": "discord_channel_id",
"type": "string",
"value": ""
},
{
"id": "0bc05648-2f31-4757-8703-75d3c7f80917",
"name": "google_analytics_id",
"type": "string",
"value": "="
}
]
}
},
"typeVersion": 3.4
},
{
"id": "41409245-e194-4e69-866c-f357af2607b1",
"name": "编辑字段4",
"type": "n8n-nodes-base.set",
"position": [
440,
680
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "c89a369e-0c67-476f-8227-b56b2b1c87b3",
"name": "discord_channel_id",
"type": "string",
"value": ""
},
{
"id": "be197313-7b88-462a-8ff7-9bb9ddf7e846",
"name": "google_analytics_id",
"type": "string",
"value": ""
}
]
}
},
"typeVersion": 3.4
},
{
"id": "15404bc5-657a-4429-ada9-6528d766b779",
"name": "计划触发器2",
"type": "n8n-nodes-base.scheduleTrigger",
"position": [
280,
680
],
"parameters": {
"rule": {
"interval": [
{
"triggerAtHour": 21,
"triggerAtMinute": 53
}
]
}
},
"typeVersion": 1.2
},
{
"id": "1901a316-6baa-4674-b8b5-cfa4a35d3818",
"name": "计划触发器3",
"type": "n8n-nodes-base.scheduleTrigger",
"position": [
280,
480
],
"parameters": {
"rule": {
"interval": [
{
"triggerAtHour": 21,
"triggerAtMinute": 52
}
]
}
},
"typeVersion": 1.2
},
{
"id": "34d1a765-f42a-4cdd-bc7a-2c97234fd3fd",
"name": "便签 4",
"type": "n8n-nodes-base.stickyNote",
"position": [
-40,
440
],
"parameters": {
"width": 640,
"height": 180,
"content": "## Google Analytics 属性 3"
},
"typeVersion": 1
},
{
"id": "44ca144f-ca2d-4c7a-8348-2a50dbb48772",
"name": "便签 5",
"type": "n8n-nodes-base.stickyNote",
"position": [
-40,
640
],
"parameters": {
"width": 640,
"height": 180,
"content": "## Google Analytics 属性 4"
},
"typeVersion": 1
},
{
"id": "28e662c6-7071-4d54-b7ca-710d185e3422",
"name": "便签6",
"type": "n8n-nodes-base.stickyNote",
"position": [
820,
200
],
"parameters": {
"color": 7,
"width": 400,
"content": "### 获取并排序 Google Analytics 数据"
},
"typeVersion": 1
},
{
"id": "dfc3412f-e989-4c6f-aa8e-5a2e34b0221d",
"name": "便签7",
"type": "n8n-nodes-base.stickyNote",
"position": [
1280,
200
],
"parameters": {
"color": 7,
"width": 260,
"content": "### 从频道获取并排序 Discord 消息"
},
"typeVersion": 1
},
{
"id": "1287b658-275e-4d72-858c-2f279a20eb41",
"name": "排序6",
"type": "n8n-nodes-base.sort",
"onError": "continueRegularOutput",
"position": [
1440,
380
],
"parameters": {
"options": {},
"sortFieldsUi": {
"sortField": [
{
"fieldName": "embeds[0].fields[0].value"
}
]
}
},
"typeVersion": 1
},
{
"id": "8a999078-a716-4b1a-b501-dec5beb469f0",
"name": "便签8",
"type": "n8n-nodes-base.stickyNote",
"position": [
1600,
200
],
"parameters": {
"color": 7,
"width": 160,
"content": "### 映射数据"
},
"typeVersion": 1
},
{
"id": "dfe339cd-0335-4f77-8517-a35441eb6193",
"name": "便签9",
"type": "n8n-nodes-base.stickyNote",
"position": [
2060,
-140
],
"parameters": {
"color": 7,
"width": 700,
"height": 120,
"content": "### 使用 Discord API 更新消息"
},
"typeVersion": 1
},
{
"id": "39be50dc-79bc-4091-a802-ae7aacdfa684",
"name": "便签 10",
"type": "n8n-nodes-base.stickyNote",
"position": [
-580,
-20
],
"parameters": {
"color": 7,
"width": 440,
"height": 480,
"content": "## 获取您的 Discord 频道 ID"
},
"typeVersion": 1
},
{
"id": "a1032930-f62f-49d4-8e39-28c9c73fe5a2",
"name": "便签11",
"type": "n8n-nodes-base.stickyNote",
"position": [
-580,
500
],
"parameters": {
"color": 7,
"width": 440,
"height": 420,
"content": "## 获取您的 Google Analytics ID"
},
"typeVersion": 1
}
],
"active": false,
"pinData": {},
"settings": {
"callerPolicy": "workflowsFromSameOwner",
"errorWorkflow": "ernonQOxi07n6WGi",
"executionOrder": "v1"
},
"versionId": "064d13a2-ee8a-4672-9065-09e4aed21c32",
"connections": {
"Code": {
"main": [
[
{
"node": "Switch",
"type": "main",
"index": 0
}
]
]
},
"Sort": {
"main": [
[
{
"node": "gaData",
"type": "main",
"index": 0
}
]
]
},
"Wait": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Code1": {
"main": [
[
{
"node": "Google Analytics",
"type": "main",
"index": 0
}
]
]
},
"Sort6": {
"main": [
[
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
},
"Wait4": {
"main": [
[
{
"node": "Loop Over Items4",
"type": "main",
"index": 0
}
]
]
},
"Switch": {
"main": [
[
{
"node": "Loop Over Items4",
"type": "main",
"index": 0
}
],
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"gaData": {
"main": [
[
{
"node": "Discord",
"type": "main",
"index": 0
}
]
]
},
"Discord": {
"main": [
[
{
"node": "Sort6",
"type": "main",
"index": 0
}
]
]
},
"Edit Fields": {
"main": [
[
{
"node": "Code1",
"type": "main",
"index": 0
}
]
]
},
"Edit Fields2": {
"main": [
[
{
"node": "Code1",
"type": "main",
"index": 0
}
]
]
},
"Edit Fields3": {
"main": [
[
{
"node": "Code1",
"type": "main",
"index": 0
}
]
]
},
"Edit Fields4": {
"main": [
[
{
"node": "Code1",
"type": "main",
"index": 0
}
]
]
},
"HTTP Request": {
"main": [
[
{
"node": "Wait4",
"type": "main",
"index": 0
}
]
]
},
"HTTP Request8": {
"main": [
[
{
"node": "Wait",
"type": "main",
"index": 0
}
]
]
},
"Loop Over Items": {
"main": [
[],
[
{
"node": "HTTP Request8",
"type": "main",
"index": 0
}
]
]
},
"Google Analytics": {
"main": [
[
{
"node": "Sort",
"type": "main",
"index": 0
}
]
]
},
"Loop Over Items4": {
"main": [
[],
[
{
"node": "HTTP Request",
"type": "main",
"index": 0
}
]
]
},
"Schedule Trigger": {
"main": [
[
{
"node": "Edit Fields3",
"type": "main",
"index": 0
}
]
]
},
"Schedule Trigger1": {
"main": [
[
{
"node": "Edit Fields2",
"type": "main",
"index": 0
}
]
]
},
"Schedule Trigger2": {
"main": [
[
{
"node": "Edit Fields4",
"type": "main",
"index": 0
}
]
]
},
"Schedule Trigger3": {
"main": [
[
{
"node": "Edit Fields",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
高级 - 市场调研
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
内容农场 - AI驱动的WordPress博客自动化
内容农场 - AI驱动的WordPress博客自动化
Set
Code
Html
+16
81 节点Jay Emp0
人工智能
Reels趋势观察器
使用Gemini和Apify查找高表现Instagram Reels并将洞察保存至Notion
If
Set
Code
+9
36 节点Eugene Green
市场调研
新抓取器_TechCrunch新闻-AI1
TechCrunch AI文章抓取与分类器,使用GPT-4.1-nano到Sheets和Telegram
Set
Code
Html
+12
18 节点Mujahid Kabae
市场调研
内容生成器 v3
AI驱动博客自动化:使用GPT-4生成并发布SEO文章至WordPress和Twitter
If
Set
Code
+25
144 节点Jay Emp0
内容创作
MetaAds创意洞察研究员v1.4
使用Google Vision和Video Intelligence API分析Meta广告创意
If
Set
Code
+9
32 节点Kirill Khatkevich
市场调研
竞争价格监控与警报(Bright Data、Sheets 和 Slack)
使用 Bright Data、Sheets 和 Slack 进行竞争价格监控与警报
If
Set
Code
+9
29 节点Daniel Shashko
市场调研
工作流信息
难度等级
高级
节点数量34
分类1
节点类型11
作者
Jay Emp0
@jay-emp0AI and Automation developer. Im implementing n8n and ai tools to automate marketing and sales in companies
外部链接
在 n8n.io 查看 →
分享此工作流