使用Gmail和Google表格分析的废弃购物车恢复功能
中级
这是一个Social Media领域的自动化工作流,包含 13 个节点。主要使用 If, Set, Code, Wait, Gmail 等节点。 使用Gmail和Google表格分析的废弃购物车恢复功能
前置要求
- •Google 账号和 Gmail API 凭证
- •HTTP Webhook 端点(n8n 会自动生成)
- •Google Sheets API 凭证
分类
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"nodes": [
{
"id": "1",
"name": "购物车放弃 Webhook",
"type": "n8n-nodes-base.webhook",
"position": [
240,
300
],
"parameters": {
"path": "cart-abandoned",
"options": {},
"httpMethod": "POST"
},
"typeVersion": 1
},
{
"id": "2",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
140,
180
],
"parameters": {
"width": 240,
"height": 160,
"content": "## 购物车恢复配置"
},
"typeVersion": 1
},
{
"id": "3",
"name": "恢复设置",
"type": "n8n-nodes-base.set",
"position": [
440,
300
],
"parameters": {
"values": {
"number": [
{
"name": "firstDiscount",
"value": 10
},
{
"name": "secondDiscount",
"value": 15
},
{
"name": "finalDiscount",
"value": 20
}
],
"string": [
{
"name": "fromEmail",
"value": "sales@your-store.com"
},
{
"name": "baseUrl",
"value": "https://your-store.com"
}
]
}
},
"typeVersion": 1
},
{
"id": "4",
"name": "验证购物车",
"type": "n8n-nodes-base.if",
"position": [
640,
300
],
"parameters": {
"conditions": {
"options": {
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"operator": {
"type": "number",
"operation": "gt"
},
"leftValue": "={{ $json.cart_value }}",
"rightValue": 50
},
{
"operator": {
"type": "string",
"operation": "isNotEmpty"
},
"leftValue": "={{ $json.customer_email }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2
},
{
"id": "5",
"name": "生成恢复数据",
"type": "n8n-nodes-base.code",
"position": [
840,
300
],
"parameters": {
"jsCode": "// Generate discount codes for recovery sequence\nconst cartId = $json.cart_id;\nconst customerEmail = $json.customer_email;\nconst timestamp = Date.now();\n\n// Create unique discount codes\nconst codes = {\n firstCode: `SAVE${$node['Recovery Settings'].json.firstDiscount}-${cartId.slice(-4)}`,\n secondCode: `SAVE${$node['Recovery Settings'].json.secondDiscount}-${cartId.slice(-4)}`,\n finalCode: `SAVE${$node['Recovery Settings'].json.finalDiscount}-${cartId.slice(-4)}`\n};\n\n// Calculate recovery schedule\nconst schedules = {\n firstEmail: new Date(timestamp + 1 * 60 * 60 * 1000).toISOString(), // 1 hour\n secondEmail: new Date(timestamp + 24 * 60 * 60 * 1000).toISOString(), // 24 hours\n finalEmail: new Date(timestamp + 72 * 60 * 60 * 1000).toISOString() // 72 hours\n};\n\nreturn {\n ...codes,\n ...schedules,\n cartData: $json,\n recoveryId: `recovery_${cartId}_${timestamp}`\n};"
},
"typeVersion": 1
},
{
"id": "6",
"name": "等待 1 小时",
"type": "n8n-nodes-base.wait",
"position": [
1040,
200
],
"parameters": {
"unit": "hours",
"amount": 1
},
"typeVersion": 1
},
{
"id": "7",
"name": "发送首次恢复邮件",
"type": "n8n-nodes-base.gmail",
"position": [
1240,
200
],
"parameters": {
"sendTo": "={{ $node['Generate Recovery Data'].json.cartData.customer_email }}",
"message": "=<!DOCTYPE html>\n<html>\n<head>\n <style>\n body { font-family: Arial, sans-serif; margin: 0; padding: 20px; background-color: #f8f9fa; }\n .container { max-width: 600px; margin: 0 auto; background: white; border-radius: 10px; padding: 30px; }\n .header { text-align: center; margin-bottom: 30px; }\n .product-item { border: 1px solid #eee; padding: 20px; margin: 10px 0; border-radius: 8px; }\n .cta-button { background: #007bff; color: white; padding: 15px 30px; text-decoration: none; border-radius: 5px; display: inline-block; margin: 20px 0; }\n .discount { background: #28a745; color: white; padding: 10px; text-align: center; margin: 20px 0; border-radius: 5px; }\n </style>\n</head>\n<body>\n <div class=\"container\">\n <div class=\"header\">\n <h2>Your cart is waiting for you! 🛒</h2>\n <p>Hello {{ $node['Generate Recovery Data'].json.cartData.customer_name }},</p>\n <p>You left some items in your cart. Don't let them get away!</p>\n </div>\n \n {{#each $node['Generate Recovery Data'].json.cartData.items}}\n <div class=\"product-item\">\n <h3>{{ this.name }}</h3>\n <p>Price: {{ this.price }} €</p>\n <p>Quantity: {{ this.quantity }}</p>\n </div>\n {{/each}}\n \n <div class=\"discount\">\n <h3>🎉 Special offer - 10% discount!</h3>\n <p>Code: <strong>{{ $node['Generate Recovery Data'].json.firstCode }}</strong></p>\n </div>\n \n <div style=\"text-align: center;\">\n <a href=\"{{ $node['Recovery Settings'].json.baseUrl }}/cart/{{ $node['Generate Recovery Data'].json.cartData.cart_id }}\" class=\"cta-button\">\n Complete my order\n </a>\n </div>\n \n <p style=\"color: #666; font-size: 14px; margin-top: 30px;\">\n This offer expires in 24 hours. Hurry up!\n </p>\n </div>\n</body>\n</html>",
"options": {
"contentType": "html"
},
"subject": "You forgot something in your cart 🛒"
},
"typeVersion": 1
},
{
"id": "8",
"name": "再等待 23 小时",
"type": "n8n-nodes-base.wait",
"position": [
1440,
200
],
"parameters": {
"unit": "hours",
"amount": 23
},
"typeVersion": 1
},
{
"id": "9",
"name": "发送第二次恢复邮件",
"type": "n8n-nodes-base.gmail",
"position": [
1640,
200
],
"parameters": {
"sendTo": "={{ $node['Generate Recovery Data'].json.cartData.customer_email }}",
"message": "=<!DOCTYPE html>\n<html>\n<head>\n <style>\n body { font-family: Arial, sans-serif; margin: 0; padding: 20px; background-color: #f8f9fa; }\n .container { max-width: 600px; margin: 0 auto; background: white; border-radius: 10px; padding: 30px; }\n .header { text-align: center; margin-bottom: 30px; }\n .urgency { background: #dc3545; color: white; padding: 15px; text-align: center; margin: 20px 0; border-radius: 5px; }\n .cta-button { background: #28a745; color: white; padding: 15px 30px; text-decoration: none; border-radius: 5px; display: inline-block; margin: 20px 0; }\n .discount { background: #ffc107; color: #212529; padding: 15px; text-align: center; margin: 20px 0; border-radius: 5px; }\n </style>\n</head>\n<body>\n <div class=\"container\">\n <div class=\"header\">\n <h2>🚨 Your cart expires soon!</h2>\n <p>Hello {{ $node['Generate Recovery Data'].json.cartData.customer_name }},</p>\n </div>\n \n <div class=\"urgency\">\n <h3>⏰ Only a few hours left!</h3>\n <p>Your cart will be automatically deleted soon</p>\n </div>\n \n <div class=\"discount\">\n <h3>🎁 Exceptional offer - 15% discount!</h3>\n <p>Code: <strong>{{ $node['Generate Recovery Data'].json.secondCode }}</strong></p>\n <p>Valid only for the next 24 hours</p>\n </div>\n \n <div style=\"text-align: center;\">\n <a href=\"{{ $node['Recovery Settings'].json.baseUrl }}/cart/{{ $node['Generate Recovery Data'].json.cartData.cart_id }}\" class=\"cta-button\">\n I'll recover my cart now\n </a>\n </div>\n \n <p style=\"color: #666; font-size: 14px; margin-top: 30px;\">\n Your cart total: {{ $node['Generate Recovery Data'].json.cartData.cart_value }} €\n </p>\n </div>\n</body>\n</html>",
"options": {
"contentType": "html"
},
"subject": "Last chance - Your discount is waiting! 💸"
},
"typeVersion": 1
},
{
"id": "10",
"name": "再等待 48 小时",
"type": "n8n-nodes-base.wait",
"position": [
1840,
200
],
"parameters": {
"unit": "hours",
"amount": 48
},
"typeVersion": 1
},
{
"id": "11",
"name": "发送最终恢复邮件",
"type": "n8n-nodes-base.gmail",
"position": [
2040,
200
],
"parameters": {
"sendTo": "={{ $node['Generate Recovery Data'].json.cartData.customer_email }}",
"message": "=<!DOCTYPE html>\n<html>\n<head>\n <style>\n body { font-family: Arial, sans-serif; margin: 0; padding: 20px; background-color: #f8f9fa; }\n .container { max-width: 600px; margin: 0 auto; background: white; border-radius: 10px; padding: 30px; }\n .header { text-align: center; margin-bottom: 30px; }\n .final-offer { background: linear-gradient(45deg, #ff6b6b, #ffa500); color: white; padding: 20px; text-align: center; margin: 20px 0; border-radius: 10px; }\n .cta-button { background: #dc3545; color: white; padding: 20px 40px; text-decoration: none; border-radius: 5px; display: inline-block; margin: 20px 0; font-size: 18px; }\n .testimonial { background: #e9ecef; padding: 15px; margin: 20px 0; border-radius: 5px; font-style: italic; }\n </style>\n</head>\n<body>\n <div class=\"container\">\n <div class=\"header\">\n <h2>🔥 Final offer - Don't miss this chance!</h2>\n <p>{{ $node['Generate Recovery Data'].json.cartData.customer_name }}, this is really your last chance...</p>\n </div>\n \n <div class=\"final-offer\">\n <h2>🎯 EXCLUSIVE OFFER</h2>\n <h3>20% DISCOUNT</h3>\n <p>Code: <strong>{{ $node['Generate Recovery Data'].json.finalCode }}</strong></p>\n <p>⏰ Expires in 24 hours - Definitely!</p>\n </div>\n \n <div class=\"testimonial\">\n <p>\"I loved my purchases on this site! Fast delivery and quality products.\" - Sarah M.</p>\n </div>\n \n <div style=\"text-align: center;\">\n <a href=\"{{ $node['Recovery Settings'].json.baseUrl }}/cart/{{ $node['Generate Recovery Data'].json.cartData.cart_id }}\" class=\"cta-button\">\n I'll take advantage now!\n </a>\n </div>\n \n <p style=\"color: #666; font-size: 14px; margin-top: 30px;\">\n If you no longer want to receive these emails, <a href=\"#\">click here</a>.\n </p>\n </div>\n</body>\n</html>",
"options": {
"contentType": "html"
},
"subject": "Absolutely last chance - 20% discount! 🔥"
},
"typeVersion": 1
},
{
"id": "12",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
1940,
60
],
"parameters": {
"width": 240,
"height": 160,
"content": "## 恢复分析"
},
"typeVersion": 1
},
{
"id": "13",
"name": "跟踪恢复开始",
"type": "n8n-nodes-base.googleSheets",
"position": [
1040,
400
],
"parameters": {
"values": {
"values": [
"={{ $node['Generate Recovery Data'].json.recoveryId }}",
"={{ $node['Generate Recovery Data'].json.cartData.customer_email }}",
"={{ $node['Generate Recovery Data'].json.cartData.cart_value }}",
"={{ new Date().toISOString() }}",
"sequence_started"
]
},
"resource": "sheet",
"operation": "appendRow",
"sheetName": "Cart Recovery Tracking",
"documentId": "your-google-sheet-id"
},
"typeVersion": 1
}
],
"connections": {
"Wait 1 Hour": {
"main": [
[
{
"node": "Send First Recovery Email",
"type": "main",
"index": 0
}
]
]
},
"Qualify Cart": {
"main": [
[
{
"node": "Generate Recovery Data",
"type": "main",
"index": 0
}
]
]
},
"Recovery Settings": {
"main": [
[
{
"node": "Qualify Cart",
"type": "main",
"index": 0
}
]
]
},
"Wait 23 Hours More": {
"main": [
[
{
"node": "Send Second Recovery Email",
"type": "main",
"index": 0
}
]
]
},
"Wait 48 Hours More": {
"main": [
[
{
"node": "Send Final Recovery Email",
"type": "main",
"index": 0
}
]
]
},
"Cart Abandoned Webhook": {
"main": [
[
{
"node": "Recovery Settings",
"type": "main",
"index": 0
}
]
]
},
"Generate Recovery Data": {
"main": [
[
{
"node": "Wait 1 Hour",
"type": "main",
"index": 0
},
{
"node": "Track Recovery Start",
"type": "main",
"index": 0
}
]
]
},
"Send First Recovery Email": {
"main": [
[
{
"node": "Wait 23 Hours More",
"type": "main",
"index": 0
}
]
]
},
"Send Second Recovery Email": {
"main": [
[
{
"node": "Wait 48 Hours More",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 社交媒体
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
使用Gmail提醒和Google表格自动化活动注册与跟进
使用Gmail提醒和Google表格自动化活动注册与跟进
If
Set
Code
+5
14 节点Rodrigue
社交媒体
使用AI评分和Gmail推广管理社交媒体影响者活动
使用AI评分和Gmail推广管理社交媒体影响者活动
If
Set
Code
+6
15 节点Rodrigue
社交媒体
使用GPT-4评分和Gmail通知自动化候选人评估
使用GPT-4评分和Gmail通知自动化候选人评估
If
Set
Code
+4
12 节点Rodrigue
人力资源
供应商风险评分自动化
使用D&B、NewsAPI和Gmail提醒自动化供应商风险评分
If
Set
Code
+6
16 节点Rodrigue
杂项
为 HubSpot 联系人和 SharePoint 生成 AI 撰写的新闻稿和素材
使用 GPT-4o、AI 图像和视频为 HubSpot 和 SharePoint 创建双语新闻稿
If
Set
Code
+15
49 节点plemeo
社交媒体
多司法管辖区智能合约合规监控器 - 自动警报
多司法管辖区智能合约合规监控器,支持自动警报
If
Set
Code
+6
16 节点Rodrigue
文档提取