wordpress
google-sheets
gmail

تحلیل و دسته‌بندی RFM مشتریان ووکامرس با n8n

این تمپلیت به شما کمک می‌کند تا مشتریان فروشگاه ووکامرسی خود را به‌صورت خودکار تحلیل و دسته‌بندی کنید. خروجی این تحلیل به‌صورت گزارشی HTML آماده می‌شود که شامل دسته‌بندی RFM، تعداد مشتریان در هر گروه، و پیشنهاد‌های مارکتینگی متناسب با هر دسته است.

نحوه عملکرد:

جمع‌آوری سفارش‌ها: تمپلیت سفارش‌های تکمیل‌شده‌ی یک سال اخیر را از ووکامرس دریافت می‌کند.

محاسبه RFM (Recency – Frequency – Monetary):

Recency: چند روز از آخرین خرید گذشته؟

Frequency: چند بار خرید کرده؟

Monetary: مجموع مبلغ خرید چقدر بوده؟

دسته‌بندی مشتریان: براساس امتیاز RFM، مشتریان به گروه‌هایی مانند “قهرمان‌ها”، “در معرض ریزش”، “از دست‌رفته” و… تقسیم می‌شوند.

گزارش نهایی: گزارشی حرفه‌ای شامل:

نام هر دسته‌بندی (فارسی)

تعداد مشتریان هر گروه

پیشنهاد عملی مارکتینگی برای آن گروه

خروجی گزارش:
خروجی به‌صورت جدول HTML تمیز آماده می‌شود و قابل استفاده در:

ایمیل‌های مدیریتی

داشبورد هفتگی

تبدیل به PDF یا ذخیره در سایت

مزایای استفاده از این تمپلیت:
تحلیل خودکار و سریع RFM برای فروشگاه

نمایش کاربردی برای تیم بازاریابی

قابل ترکیب با نود ایمیل، تلگرام، یا PDF در n8n

فارسی‌سازی کامل برای مخاطبان ایرانی

 

افزودن به لیست پرکاربردها
انتشار:۲۱ خرداد ۱۴۰۴
بروزرسانی:۲۹ آذر ۱۴۰۴
تعداد بازدید:728 نفر
تعداد کامنت:بدون کامنت
اشتراک گذاری:
https://n8nir.ir/?p=1750
دسته بندی:
سایر نمونه های آماده
ChatGPT Image Nov 20, 2025, 02_11_59 PM
file_00000000a56461f9b1d225c07716750a
telegram

اتوماسیون انتشار اخبار در تلگرام با فید RSS

17069512
New-Text-Document
telegram

بررسی وضعیت آپتام سایت با n8n

google_search_console_icon-vector_brandlogos.net_hxtfr-512x512

یافتن صفحات بدون ایمپرشن و کلیک برای هرس محتوا با n8n

google_search_console_icon-vector_brandlogos.net_hxtfr-512x512

بهبود CTR در Google Search Console با n8n

google_search_console_icon-vector_brandlogos.net_hxtfr-512x512

شناسایی کنیبالیزیشن‎‌ها در سرچ کنسول با n8n

google_search_console_icon-vector_brandlogos.net_hxtfr-512x512

گزارش کلمات افت‌کرده در سرچ کنسول با N8N

google_search_console_icon-vector_brandlogos.net_hxtfr-512x512

یافتن کلمات کلیدی جدید در سرچ کنسول

telegram

اعلان سفارش جدید ووکامرس در تلگرام

اتوماسیون هوشمند را همین امروز آغاز کنید!
با استفاده از سرویس n8n، فرآیندهای تکراری را حذف و بهره‌وری کسب‌وکار خود را افزایش دهید.

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *

استفاه از قالب
کد json زیر را کپی و در صفحه ورکفلو خود پیست کنید!
کپی قالب به کپی بورد (json)
۵۰ هزار تومان اعتبار هدیه، برای شروعی قدرتمند!
{
  "nodes": [
    {
      "parameters": {},
      "id": "07a89505-a7b9-478c-bedc-bdd9db0af4e5",
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [-560, -100]
    },
    {
      "parameters": {
        "resource": "order",
        "operation": "getAll",
        "returnAll": true,
        "options": {
          "after": "={{ $now.minus(1, 'year').toISO() }}",
          "status": "completed"
        }
      },
      "id": "29752350-f5fe-4e39-9c7d-6f2bf5bf4774",
      "name": "Get WooCommerce Orders",
      "type": "n8n-nodes-base.wooCommerce",
      "typeVersion": 1,
      "position": [-360, -100],
      "credentials": {
        "wooCommerceApi": {
          "id": "tAsPd5dQuTnXMwnu",
          "name": "WooCommerce account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// گروه‌بندی سفارشات بر اساس مشتری و محاسبه RFM\nconst orders = $input.all();\nconst customers = {};\nconst today = new Date();\n\n// پردازش سفارشات\norders.forEach(order => {\n  const customerId = order.json.customer_id || order.json.billing.email;\n  if (!customerId) return;\n\n  if (!customers[customerId]) {\n    customers[customerId] = {\n      customerId: customerId,\n      customerName: `${order.json.billing.first_name} ${order.json.billing.last_name}`,\n      email: order.json.billing.email,\n      orders: [],\n      totalSpent: 0,\n      orderCount: 0\n    };\n  }\n\n  const orderDate = new Date(order.json.date_created);\n  customers[customerId].orders.push({\n    date: orderDate,\n    total: parseFloat(order.json.total)\n  });\n  customers[customerId].totalSpent += parseFloat(order.json.total);\n  customers[customerId].orderCount++;\n});\n\n// محاسبه مقادیر RFM\nconst customerData = Object.values(customers).map(customer => {\n  // Recency: تعداد روز از آخرین خرید\n  const lastOrderDate = Math.max(...customer.orders.map(o => o.date));\n  const recency = Math.floor((today - new Date(lastOrderDate)) / (1000 * 60 * 60 * 24));\n\n  // Frequency: تعداد سفارشات\n  const frequency = customer.orderCount;\n\n  // Monetary: مجموع خرید\n  const monetary = customer.totalSpent;\n\n  return {\n    customerId: customer.customerId,\n    customerName: customer.customerName,\n    email: customer.email,\n    recency: recency,\n    frequency: frequency,\n    monetary: monetary,\n    lastOrderDate: new Date(lastOrderDate).toISOString().split('T')[0]\n  };\n});\n\n// مرتب‌سازی برای محاسبه چارک‌ها\nconst sortedByRecency = [...customerData].sort((a, b) => a.recency - b.recency);\nconst sortedByFrequency = [...customerData].sort((a, b) => b.frequency - a.frequency);\nconst sortedByMonetary = [...customerData].sort((a, b) => b.monetary - a.monetary);\n\n// محاسبه چارک‌ها\nfunction getQuartile(sortedArray, value, field, ascending = false) {\n  const index = sortedArray.findIndex(item => item[field] === value);\n  const quartile = Math.ceil((index + 1) / sortedArray.length * 4);\n  return ascending ? quartile : 5 - quartile;\n}\n\n// اختصاص امتیاز RFM\nconst rfmScores = customerData.map(customer => {\n  const rScore = getQuartile(sortedByRecency, customer.recency, 'recency', true);\n  const fScore = getQuartile(sortedByFrequency, customer.frequency, 'frequency');\n  const mScore = getQuartile(sortedByMonetary, customer.monetary, 'monetary');\n\n  const rfmScore = `${rScore}${fScore}${mScore}`;\n\n  // تعیین segment\n  let segment = '';\n  if (rScore >= 4 && fScore >= 4 && mScore >= 4) {\n    segment = 'Champions';\n  } else if (rScore >= 3 && fScore >= 3 && mScore >= 4) {\n    segment = 'Loyal Customers';\n  } else if (rScore >= 3 && fScore >= 1 && mScore >= 3) {\n    segment = 'Potential Loyalists';\n  } else if (rScore >= 4 && fScore <= 2) {\n    segment = 'New Customers';\n  } else if (rScore >= 3 && fScore >= 3 && mScore <= 2) {\n    segment = 'Promising';\n  } else if (rScore <= 2 && fScore >= 3) {\n    segment = 'Need Attention';\n  } else if (rScore <= 2 && fScore <= 2 && mScore >= 3) {\n    segment = 'About to Sleep';\n  } else if (rScore <= 2 && fScore >= 3 && mScore >= 3) {\n    segment = 'At Risk';\n  } else if (rScore <= 2 && fScore <= 2 && mScore <= 2) {\n    segment = 'Lost';\n  } else {\n    segment = 'Others';\n  }\n\n  return {\n    ...customer,\n    rScore,\n    fScore,\n    mScore,\n    rfmScore,\n    segment,\n    avgOrderValue: customer.monetary / customer.frequency\n  };\n});\n\nreturn rfmScores;"
      },
      "id": "70a268f3-e951-43d3-9e17-14d8bf50a13c",
      "name": "Calculate RFM Scores",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [-160, -100]
    },
    {
      "parameters": {
        "operation": "removeDuplicates",
        "compare": "allFieldsExcept",
        "fieldsToExclude": "customerId",
        "options": {}
      },
      "id": "d98c1d78-6451-4275-8c1d-511a36d100c2",
      "name": "Segment Summary",
      "type": "n8n-nodes-base.itemLists",
      "typeVersion": 3,
      "position": [40, -100]
    },
    {
      "parameters": {
        "rule": {
          "interval": [{}]
        }
      },
      "id": "e4d81773-eccf-424d-9703-a99c5103623d",
      "name": "Weekly Schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.1,
      "position": [-560, 100]
    },
    {
      "parameters": {
        "html": "<head>\n  <meta charset=\"UTF-8\">\n  <style>\n    body {\n      font-family: sans-serif;\n      direction: rtl;\n      background-color: #f7f7f7;\n      padding: 20px;\n    }\n    h2 {\n      text-align: center;\n      color: #333;\n    }\n    table {\n      width: 100%;\n      border-collapse: collapse;\n      margin-top: 20px;\n      background-color: #fff;\n    }\n    th, td {\n      border: 1px solid #ccc;\n      padding: 8px 12px;\n      font-size: 14px;\n      text-align: center;\n    }\n    th {\n      background-color: #e6f2ff;\n    }\n    tr:nth-child(even) {\n      background-color: #f9f9f9;\n    }\n    .segment {\n      font-weight: bold;\n      color: #2e7d32;\n    }\n  </style>\n</head>\n{{ $json.html }}\n"
      },
      "type": "n8n-nodes-base.html",
      "typeVersion": 1.2,
      "position": [720, -100],
      "id": "5464ccda-93bd-4296-be27-517026851b4f",
      "name": "HTML"
    },
    {
      "parameters": {
        "jsCode": "const items = $input.all();\n\n// تعریف ترجمه‌ها و اولویت نمایش\nconst segmentDetails = {\n  'Champions': { fa: 'قهرمان‌ها', priority: 1, action: 'ارسال پیشنهاد VIP و کد تخفیف اختصاصی' },\n  'Loyal Customers': { fa: 'مشتریان وفادار', priority: 2, action: 'عضویت در باشگاه مشتریان و معرفی محصولات جدید' },\n  'Potential Loyalists': { fa: 'وفاداران بالقوه', priority: 3, action: 'پیگیری تعامل بیشتر و پیشنهاد محصول مکمل' },\n  'New Customers': { fa: 'مشتریان جدید', priority: 4, action: 'پیام خوش‌آمدگویی و تشویق به خرید دوم' },\n  'Promising': { fa: 'امیدوارکننده', priority: 5, action: 'یادآوری محصول و آموزش بیشتر' },\n  'Need Attention': { fa: 'نیازمند توجه', priority: 6, action: 'بررسی دلایل عدم خرید و کمپین بازگشت' },\n  'About to Sleep': { fa: 'نزدیک به خواب رفتن', priority: 7, action: 'ارسال محصولات جدید و انگیزه بازگشت' },\n  'At Risk': { fa: 'در معرض ریزش', priority: 8, action: 'پیام شخصی‌سازی‌شده و تخفیف سنگین' },\n  'Lost': { fa: 'از دست‌رفته', priority: 9, action: 'پیشنهاد بازگشت و کمپین «ما برگشتیم»' },\n  'Others': { fa: 'سایر', priority: 10, action: 'بررسی دستی برای تعیین رفتار' },\n};\n\n// شمارش دسته‌ها\nconst segmentCounts = {};\n\nfor (const item of items) {\n  const seg = item.json.segment || 'Others';\n  if (!segmentCounts[seg]) segmentCounts[seg] = 0;\n  segmentCounts[seg]++;\n}\n\n// ساخت جدول HTML\nlet html = `<h2 style=\"text-align: center;\">گزارش خلاصه RFM - ${new Date().toISOString().split('T')[0]}</h2>`;\nhtml += `<table border=\"1\" cellpadding=\"8\" cellspacing=\"0\" style=\"width:90%; margin:auto; border-collapse:collapse; font-family:sans-serif;\">\n  <thead style=\"background:#e6f2ff;\">\n    <tr>\n      <th>دسته‌بندی</th>\n      <th>تعداد مشتری</th>\n      <th>پیشنهاد مارکتینگ</th>\n    </tr>\n  </thead>\n  <tbody>`;\n\nObject.entries(segmentCounts)\n  .map(([key, count]) => ({\n    key,\n    count,\n    priority: segmentDetails[key]?.priority || 999,\n    label: segmentDetails[key]?.fa || key,\n    action: segmentDetails[key]?.action || '-'\n  }))\n  .sort((a, b) => a.priority - b.priority)\n  .forEach(({ label, count, action }) => {\n    html += `<tr><td>${label}</td><td>${count}</td><td>${action}</td></tr>`;\n  });\n\nhtml += `</tbody></table>`;\n\nreturn [{ json: { html } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [320, -100],
      "id": "ab7e5915-fc77-41d3-9c94-aae4b3518f4a"
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Get WooCommerce Orders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get WooCommerce Orders": {
      "main": [
        [
          {
            "node": "Calculate RFM Scores",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate RFM Scores": {
      "main": [
        [
          {
            "node": "Segment Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Segment Summary": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Weekly Schedule": {
      "main": [
        [
          {
            "node": "Get WooCommerce Orders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code": {
      "main": [
        [
          {
            "node": "HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "efb648c3d02d0e1a97b3874b46cf3a22aa83f9050bae739aa2a95fc50a1643f4"
  }
}
لینک کپی شد!