{
  "name": "08 - Multi-Channel Marketing Automation Funnel",
  "nodes": [
    {
      "id": "node-1",
      "name": "Webhook - Behavior Event",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [240, 300],
      "parameters": { "httpMethod": "POST", "path": "track-behavior", "responseMode": "responseNode" }
    },
    {
      "id": "node-2",
      "name": "Code - Parse Event",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [480, 300],
      "parameters": {
        "jsCode": "const d = $input.first().json;\nreturn [{ json: { event: d.event||'unknown', email: d.email||'', first_name: d.first_name||'there', phone: d.phone||'', cart_value: d.cart_value||0, cart_url: d.cart_url||'', previous_score: d.previous_score||0, timestamp: new Date().toISOString() } }];"
      }
    },
    {
      "id": "node-3",
      "name": "Switch - Route by Event",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3,
      "position": [720, 300],
      "parameters": {
        "mode": "rules",
        "rules": {
          "values": [
            { "conditions": { "conditions": [{ "leftValue": "={{ $json.event }}", "operator": { "type": "string", "operation": "equals" }, "rightValue": "cart_abandoned" }] }, "renameOutput": true, "outputKey": "Cart Abandoned" },
            { "conditions": { "conditions": [{ "leftValue": "={{ $json.event }}", "operator": { "type": "string", "operation": "equals" }, "rightValue": "pricing_viewed" }] }, "renameOutput": true, "outputKey": "Pricing Viewed" },
            { "conditions": { "conditions": [{ "leftValue": "={{ $json.event }}", "operator": { "type": "string", "operation": "equals" }, "rightValue": "demo_requested" }] }, "renameOutput": true, "outputKey": "Demo Requested" }
          ]
        }
      }
    },
    {
      "id": "node-4",
      "name": "Gmail - Cart Recovery Email",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [960, 140],
      "credentials": { "gmailOAuth2": { "id": "YOUR_GMAIL_CREDENTIAL_ID", "name": "Gmail account" } },
      "parameters": {
        "resource": "message",
        "operation": "send",
        "sendTo": "={{ $json.email }}",
        "subject": "=Hey {{ $json.first_name }}, you left something behind 👀",
        "message": "=<h2>Your cart misses you!</h2><p>Hi {{ $json.first_name }}, you left <strong>${{ $json.cart_value }}</strong> in your cart. Complete your purchase now with <strong>10% off</strong> using code COMEBACK10.</p><p><a href='{{ $json.cart_url }}'>Complete Purchase →</a></p>",
        "options": { "isHtml": true }
      }
    },
    {
      "id": "node-5",
      "name": "Gmail - Pricing Page Demo Invite",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [960, 300],
      "credentials": { "gmailOAuth2": { "id": "YOUR_GMAIL_CREDENTIAL_ID", "name": "Gmail account" } },
      "parameters": {
        "resource": "message",
        "operation": "send",
        "sendTo": "={{ $json.email }}",
        "subject": "=Saw you checking out our pricing, {{ $json.first_name }} 👋",
        "message": "=<h2>Questions about pricing?</h2><p>Hi {{ $json.first_name }}, I noticed you visited our pricing page. I'd love to walk you through the best plan for your team — no pressure.</p><p><a href='https://calendly.com/yourteam/15min'>Book a 15-min chat →</a></p>",
        "options": { "isHtml": true }
      }
    },
    {
      "id": "node-6",
      "name": "Twilio - Send SMS",
      "type": "n8n-nodes-base.twilio",
      "typeVersion": 1,
      "position": [960, 460],
      "credentials": { "twilioApi": { "id": "YOUR_TWILIO_CREDENTIAL_ID", "name": "Twilio account" } },
      "parameters": {
        "resource": "sms",
        "operation": "send",
        "from": "+1YOUR_TWILIO_NUMBER",
        "to": "={{ $json.phone }}",
        "message": "=Hi {{ $json.first_name }}! Your demo request is confirmed. Check your email for the booking link. Reply STOP to opt out."
      }
    },
    {
      "id": "node-7",
      "name": "Code - Calculate Lead Score",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1200, 300],
      "parameters": {
        "jsCode": "const e = $('Code - Parse Event').first().json;\nconst map = { cart_abandoned: 30, pricing_viewed: 25, demo_requested: 50 };\nconst delta = map[e.event] || 10;\nconst total = (e.previous_score||0) + delta;\nreturn [{ json: { email: e.email, first_name: e.first_name, event: e.event, score_delta: delta, total_score: total, is_hot: total >= 75, timestamp: e.timestamp } }];"
      }
    },
    {
      "id": "node-8",
      "name": "IF - Hot Lead (75+)",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [1440, 300],
      "parameters": {
        "conditions": {
          "conditions": [{ "id": "c1", "leftValue": "={{ $json.is_hot }}", "rightValue": true, "operator": { "type": "boolean", "operation": "true" } }],
          "combinator": "and"
        }
      }
    },
    {
      "id": "node-9",
      "name": "Slack - Hot Lead Alert",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [1680, 160],
      "credentials": { "slackApi": { "id": "YOUR_SLACK_CREDENTIAL_ID", "name": "Slack account" } },
      "parameters": {
        "resource": "message",
        "operation": "send",
        "channel": { "__rl": true, "value": "#hot-leads", "mode": "name" },
        "text": "=🔥 *HOT LEAD!* {{ $json.email }} hit a score of *{{ $json.total_score }}*! Latest action: {{ $json.event }}. Reach out NOW!",
        "otherOptions": {}
      }
    },
    {
      "id": "node-10",
      "name": "Google Sheets - Log Event",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [1680, 440],
      "credentials": { "googleSheetsOAuth2Api": { "id": "YOUR_GOOGLE_SHEETS_CREDENTIAL_ID", "name": "Google Sheets account" } },
      "parameters": {
        "resource": "sheet",
        "operation": "appendOrUpdate",
        "documentId": { "__rl": true, "value": "YOUR_SPREADSHEET_ID", "mode": "id" },
        "sheetName": { "__rl": true, "value": "Events", "mode": "name" },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Timestamp": "={{ $json.timestamp }}",
            "Email": "={{ $json.email }}",
            "Event": "={{ $json.event }}",
            "Score Delta": "={{ $json.score_delta }}",
            "Total Score": "={{ $json.total_score }}",
            "Is Hot Lead": "={{ $json.is_hot }}"
          }
        },
        "options": {}
      }
    },
    {
      "id": "node-11",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [1920, 300],
      "parameters": { "respondWith": "json", "responseBody": "{ \"status\": \"tracked\" }" }
    }
  ],
  "connections": {
    "Webhook - Behavior Event": { "main": [[{ "node": "Code - Parse Event", "type": "main", "index": 0 }]] },
    "Code - Parse Event": { "main": [[{ "node": "Switch - Route by Event", "type": "main", "index": 0 }]] },
    "Switch - Route by Event": {
      "main": [
        [{ "node": "Gmail - Cart Recovery Email", "type": "main", "index": 0 }],
        [{ "node": "Gmail - Pricing Page Demo Invite", "type": "main", "index": 0 }],
        [{ "node": "Twilio - Send SMS", "type": "main", "index": 0 }]
      ]
    },
    "Gmail - Cart Recovery Email": { "main": [[{ "node": "Code - Calculate Lead Score", "type": "main", "index": 0 }]] },
    "Gmail - Pricing Page Demo Invite": { "main": [[{ "node": "Code - Calculate Lead Score", "type": "main", "index": 0 }]] },
    "Twilio - Send SMS": { "main": [[{ "node": "Code - Calculate Lead Score", "type": "main", "index": 0 }]] },
    "Code - Calculate Lead Score": { "main": [[{ "node": "IF - Hot Lead (75+)", "type": "main", "index": 0 }]] },
    "IF - Hot Lead (75+)": {
      "main": [
        [{ "node": "Slack - Hot Lead Alert", "type": "main", "index": 0 }],
        [{ "node": "Google Sheets - Log Event", "type": "main", "index": 0 }]
      ]
    },
    "Slack - Hot Lead Alert": { "main": [[{ "node": "Respond to Webhook", "type": "main", "index": 0 }]] },
    "Google Sheets - Log Event": { "main": [[{ "node": "Respond to Webhook", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" },
  "active": false,
  "tags": [{ "name": "Portfolio" }, { "name": "Marketing" }]
}
