{
  "name": "Score WooCommerce Stores Missing Klaviyo and Stage AI Outreach Drafts with Apify, OpenAI & Gmail",
  "nodes": [
    {
      "parameters": {
        "content": "## Score WooCommerce Stores Missing Klaviyo & Stage AI Outreach\n\n### How it works\n1. **Config & $0 Pre-Flight Check:** Calls CartPulse (`ordesign/woocommerce-store-leads`) via built-in **HTTP Request** with `countOnly: true` first to verify matching stores exist before running a paid extraction (sending a Gmail alert if `0` remain).\n2. **Extract, Deduplicate & Score:** Pulls DNS MX-checked WooCommerce leads, removes domains already logged in your **Google Sheets CRM (`Leads`)** via `Merge (Keep Non-Matches)`, and calculates a weighted **0–100 ICP Fit Score** from `email_type`, `price_median_usd`, `sku_count`, ad pixels, and legacy ESP signals.\n3. **AI Agent Copywriting & Tiered CRM Routing:**\n   - **Tier 1 (`icp_score >= 65`):** Uses an **AI Agent** (`gpt-4o-mini` + **Structured Output Parser**) to draft personalized copy, stages a **Gmail Draft**, logs the lead in **Google Sheets**, and emails a **Weekly Pipeline Digest**.\n   - **Tier 2 (`icp_score < 65`):** Routes directly to the **Nurture Queue (Tier 2)** in Google Sheets without cluttering Gmail Drafts.\n\n### Setup (100% Native n8n Nodes — Zero Community Nodes Required)\n- Create an **HTTP Header Auth** credential for Apify (`Name`: `Authorization`, `Value`: `Bearer YOUR_APIFY_API_TOKEN`).\n- Connect **Google Sheets OAuth2**, **OpenAI**, and **Gmail OAuth2**.\n- Create a Google Sheet with a tab named **`Leads`** and header columns: `domain`, `store_name`, `primary_email`, `email_type`, `sku_count`, `price_median_usd`, `icp_score`, `lead_tier`, `outreach_angle`, `outreach_status`, `gmail_draft_id`, `verified_at`.",
        "height": 700,
        "width": 500,
        "color": 5
      },
      "id": "e10f8910-1111-4000-8000-000000000020",
      "name": "Sticky Note: Workflow Overview",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -380,
        120
      ]
    },
    {
      "parameters": {
        "color": 7,
        "content": "### 1. Config & $0 Pre-Flight Pool Guard\nWeekly trigger loads targeting settings in **Campaign Config**, runs a `$0` `countOnly: true` preview via Apify REST API (`ESz1hWOdK7YQeGGQd`), and only proceeds to live extraction if `total_matching_stores > 0`.",
        "height": 600,
        "width": 980
      },
      "id": "e10f8910-1111-4000-8000-000000000021",
      "name": "Sticky Note: 1. Config & $0 Pre-Flight Pool Guard",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        160,
        160
      ]
    },
    {
      "parameters": {
        "color": 7,
        "content": "### 2. Store Extraction, CRM Dedup & ICP Scoring\nPulls live WooCommerce stores via native HTTP Request, reads existing `Leads` from Google Sheets (`alwaysOutputData: true`), removes prior CRM domains (`keepNonMatches`), and computes a 0–100 `icp_score`.",
        "height": 600,
        "width": 840
      },
      "id": "e10f8910-1111-4000-8000-000000000022",
      "name": "Sticky Note: 2. Store Extraction, CRM Dedup & ICP Scoring",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1180,
        160
      ]
    },
    {
      "parameters": {
        "color": 7,
        "content": "### 3. AI Agent Pitch, Gmail Staging & Tiered CRM Sync\n**Tier 1** brands run through an **AI Agent** + **Structured Output Parser** (`gpt-4o-mini`), stage a Gmail draft, and log `Gmail Draft Staged` to Google Sheets. **Tier 2** stores route straight to `Nurture Queue (Tier 2)`.",
        "height": 680,
        "width": 1100
      },
      "id": "e10f8910-1111-4000-8000-000000000023",
      "name": "Sticky Note: 3. Tiered AI Outreach & CRM Sync",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        2060,
        160
      ]
    },
    {
      "parameters": {
        "color": 7,
        "content": "### 4. Weekly Pipeline Digest\nCollects staged Tier-1 draft rows with **Aggregate** and emails a weekly pipeline summary via **Gmail**.",
        "height": 400,
        "width": 560
      },
      "id": "e10f8910-1111-4000-8000-000000000024",
      "name": "Sticky Note: 4. Weekly Pipeline Digest",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        3200,
        160
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "weeksInterval": 1,
              "triggerAtDay": [
                1
              ],
              "triggerAtHour": 8,
              "triggerAtMinute": 0
            }
          ]
        }
      },
      "id": "e10f8910-1111-4000-8000-000000000001",
      "name": "Weekly Schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        200,
        360
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "cfg-target-country",
              "name": "targetCountry",
              "value": "US",
              "type": "string"
            },
            {
              "id": "cfg-max-crux",
              "name": "maxCruxBucket",
              "value": 1000000,
              "type": "number"
            },
            {
              "id": "cfg-installed-tech",
              "name": "installedTech",
              "value": "={{ ['meta-pixel'] }}",
              "type": "array"
            },
            {
              "id": "cfg-missing-tech",
              "name": "missingTech",
              "value": "={{ ['klaviyo', 'omnisend'] }}",
              "type": "array"
            },
            {
              "id": "cfg-min-skus",
              "name": "minSkus",
              "value": 5,
              "type": "number"
            },
            {
              "id": "cfg-min-median-usd",
              "name": "minMedianPriceUsd",
              "value": 25,
              "type": "number"
            },
            {
              "id": "cfg-tier1-threshold",
              "name": "tier1ScoreThreshold",
              "value": 65,
              "type": "number"
            },
            {
              "id": "cfg-batch-max",
              "name": "batchMaxLeads",
              "value": 25,
              "type": "number"
            },
            {
              "id": "cfg-dedup-scope",
              "name": "dedupScope",
              "value": "weekly-us-klaviyo",
              "type": "string"
            },
            {
              "id": "cfg-sheet-id",
              "name": "crmSpreadsheetId",
              "value": "YOUR_GOOGLE_SHEET_ID",
              "type": "string"
            },
            {
              "id": "cfg-digest-email",
              "name": "digestRecipientEmail",
              "value": "you@example.com",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      },
      "id": "e10f8910-1111-4000-8000-000000000002",
      "name": "Campaign Config",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        440,
        360
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.apify.com/v2/acts/ESz1hWOdK7YQeGGQd/run-sync-get-dataset-items",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ country: $json.targetCountry, maxCruxBucket: $json.maxCruxBucket, installedTech: $json.installedTech, missingTech: $json.missingTech, onlyNewLeads: true, dedupScope: $json.dedupScope, countOnly: true }) }}",
        "options": {
          "timeout": 120000
        }
      },
      "id": "e10f8910-1111-4000-8000-000000000003",
      "name": "Pre-Flight Pool Check ($0)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        680,
        360
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "YOUR_APIFY_HEADER_AUTH_ID",
          "name": "Apify API Header Auth"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "cond-matching-pool",
              "leftValue": "={{ $json.total_matching_stores ?? 0 }}",
              "rightValue": 0,
              "operator": {
                "type": "number",
                "operation": "gt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "e10f8910-1111-4000-8000-000000000004",
      "name": "Matching Stores Available?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        920,
        360
      ]
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "send",
        "sendTo": "={{ $('Campaign Config').first().json.digestRecipientEmail }}",
        "subject": "={{ 'CartPulse n8n Alert: 0 unseen stores remaining (' + $('Campaign Config').first().json.dedupScope + ')' }}",
        "emailType": "text",
        "message": "={{ 'Pre-flight countOnly check returned 0 unseen stores for country=' + $('Campaign Config').first().json.targetCountry + ' and dedupScope=' + $('Campaign Config').first().json.dedupScope + '. Widen maxCruxBucket, country, or missingTech in Campaign Config before next Monday.' }}",
        "options": {}
      },
      "id": "e10f8910-1111-4000-8000-000000000005",
      "name": "Send Pool Exhausted Alert",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        920,
        560
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "YOUR_GMAIL_CREDENTIAL_ID",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.apify.com/v2/acts/ESz1hWOdK7YQeGGQd/run-sync-get-dataset-items",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ country: $('Campaign Config').first().json.targetCountry, maxCruxBucket: $('Campaign Config').first().json.maxCruxBucket, installedTech: $('Campaign Config').first().json.installedTech, missingTech: $('Campaign Config').first().json.missingTech, minSkus: $('Campaign Config').first().json.minSkus, minPriceMedianUsd: $('Campaign Config').first().json.minMedianPriceUsd, preferPersonalEmails: true, onlyNewLeads: true, dedupScope: $('Campaign Config').first().json.dedupScope, emailTypes: ['role', 'personal'], maxLeads: $('Campaign Config').first().json.batchMaxLeads }) }}",
        "options": {
          "timeout": 300000
        }
      },
      "id": "e10f8910-1111-4000-8000-000000000006",
      "name": "Run CartPulse WooCommerce Scraper",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        1220,
        280
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "YOUR_APIFY_HEADER_AUTH_ID",
          "name": "Apify API Header Auth"
        }
      }
    },
    {
      "parameters": {
        "resource": "sheet",
        "operation": "read",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Campaign Config').first().json.crmSpreadsheetId }}"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Leads"
        },
        "options": {}
      },
      "id": "e10f8910-1111-4000-8000-000000000007",
      "name": "Fetch Existing CRM Domains",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "alwaysOutputData": true,
      "position": [
        1220,
        540
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "YOUR_GOOGLE_SHEETS_CREDENTIAL_ID",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "mode": "combine",
        "combineBy": "combineByFields",
        "advanced": false,
        "fieldsToMatchString": "domain",
        "joinMode": "keepNonMatches",
        "outputDataFrom": "input1",
        "options": {}
      },
      "id": "e10f8910-1111-4000-8000-000000000008",
      "name": "Exclude Existing CRM Leads",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3,
      "position": [
        1500,
        400
      ]
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const cfg = $('Campaign Config').first().json;\nconst minMedian = Number(cfg.minMedianPriceUsd ?? 25);\nconst tier1Threshold = Number(cfg.tier1ScoreThreshold ?? 65);\nconst adPixels = ['meta-pixel', 'tiktok-pixel', 'pinterest-tag', 'snapchat-pixel', 'bing-ads'];\nconst legacyEsps = ['mailchimp', 'brevo', 'drip', 'activecampaign', 'convertkit'];\n\nconst scored = [];\nfor (const item of $input.all()) {\n  const j = item.json || {};\n  const email = String(j.primary_email || '').trim();\n  if (!email) continue;\n\n  const medianPrice = j.price_median_usd !== null && j.price_median_usd !== undefined\n    ? Number(j.price_median_usd)\n    : null;\n  if (medianPrice !== null && medianPrice < minMedian) continue;\n\n  let score = 0;\n  score += j.email_type === 'personal' ? 30 : 15;\n\n  if (medianPrice !== null) {\n    if (medianPrice >= 75) score += 25;\n    else if (medianPrice >= 40) score += 15;\n    else score += 10;\n  }\n\n  const skuCount = Number(j.sku_count ?? 0);\n  if (skuCount >= 30) score += 20;\n  else if (skuCount >= 10) score += 10;\n  else if (skuCount > 0) score += 5;\n\n  const tech = Array.isArray(j.installed_tech) ? j.installed_tech : [];\n  const pixelCount = adPixels.filter((t) => tech.includes(t)).length;\n  if (pixelCount >= 2) score += 15;\n  else if (pixelCount === 1) score += 8;\n\n  const hasLegacyEsp = legacyEsps.some((t) => tech.includes(t));\n  if (hasLegacyEsp) score += 10;\n\n  const icpScore = Math.min(100, score);\n  const leadTier = icpScore >= tier1Threshold ? 'tier_1' : 'tier_2';\n  const outreachAngle = hasLegacyEsp ? 'Legacy ESP migration' : 'Paid-social lifecycle gap';\n\n  scored.push({\n    json: {\n      ...j,\n      icp_score: icpScore,\n      lead_tier: leadTier,\n      outreach_angle: outreachAngle,\n      brand_display: j.store_name || j.domain || '',\n      top_categories: (Array.isArray(j.categories) ? j.categories : []).slice(0, 4).join(', ') || 'Ecommerce',\n      top_products: (Array.isArray(j.sample_products) ? j.sample_products : []).slice(0, 3).join('; ') || 'N/A'\n    }\n  });\n}\nreturn scored;"
      },
      "id": "e10f8910-1111-4000-8000-000000000009",
      "name": "Score & Segment ICP Leads",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1760,
        400
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "cond-tier1",
              "leftValue": "={{ $json.lead_tier }}",
              "rightValue": "tier_1",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "e10f8910-1111-4000-8000-000000000010",
      "name": "Tier-1 Priority Store?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        2100,
        400
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Store Name: {{ $json.brand_display }}\nWebsite: {{ $json.url }}\nCategories: {{ $json.top_categories }}\nSample Products: {{ $json.top_products }}\nSKU Count: {{ $json.sku_count ?? 'N/A' }}\nMedian Product Price (USD): {{ $json.price_median_usd ? '$' + $json.price_median_usd : 'N/A' }}\nInstalled Tech: {{ ($json.installed_tech || []).join(', ') }}\nOutreach Angle: {{ $json.outreach_angle }}\nMissing Lifecycle Tech: Klaviyo, Omnisend",
        "hasOutputParser": true,
        "options": {
          "systemMessage": "You write concise, natural B2B cold outreach emails for an ecommerce retention agency. Produce a subject line, a 3-sentence plain-text email_body (under 75 words, no bracketed placeholders) referencing their real store name, categories/products, and outreach angle, and a short icebreaker_hook summary. End email_body with a low-friction question."
        }
      },
      "id": "e10f8910-1111-4000-8000-000000000011",
      "name": "Draft Personalized Pitch",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        2360,
        240
      ]
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {
          "temperature": 0.4
        }
      },
      "id": "e10f8910-1111-4000-8000-000000000017",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        2300,
        440
      ],
      "credentials": {
        "openAiApi": {
          "id": "YOUR_OPENAI_CREDENTIAL_ID",
          "name": "OpenAI account"
        }
      }
    },
    {
      "parameters": {
        "jsonSchemaExample": "{ \"subject\": \"Quick lifecycle idea for Acme Coffee\", \"email_body\": \"Three concise plain-text sentences personalized to their store and products.\", \"icebreaker_hook\": \"Ethiopian Yirgacheffe + Mailchimp migration\" }"
      },
      "id": "e10f8910-1111-4000-8000-000000000018",
      "name": "Structured Pitch Output",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [
        2480,
        440
      ]
    },
    {
      "parameters": {
        "resource": "draft",
        "operation": "create",
        "subject": "={{ $json.output.subject || ('Quick idea for ' + $('Tier-1 Priority Store?').item.json.brand_display) }}",
        "emailType": "text",
        "message": "={{ $json.output.email_body }}",
        "options": {
          "sendTo": "={{ $('Tier-1 Priority Store?').item.json.primary_email }}"
        }
      },
      "id": "e10f8910-1111-4000-8000-000000000012",
      "name": "Stage Tier-1 Gmail Draft",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        2680,
        240
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "YOUR_GMAIL_CREDENTIAL_ID",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "resource": "sheet",
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Campaign Config').first().json.crmSpreadsheetId }}"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Leads"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "domain": "={{ $('Tier-1 Priority Store?').item.json.domain }}",
            "store_name": "={{ $('Tier-1 Priority Store?').item.json.brand_display }}",
            "primary_email": "={{ $('Tier-1 Priority Store?').item.json.primary_email }}",
            "email_type": "={{ $('Tier-1 Priority Store?').item.json.email_type }}",
            "sku_count": "={{ $('Tier-1 Priority Store?').item.json.sku_count ?? 0 }}",
            "price_median_usd": "={{ $('Tier-1 Priority Store?').item.json.price_median_usd ?? 0 }}",
            "icp_score": "={{ $('Tier-1 Priority Store?').item.json.icp_score }}",
            "lead_tier": "={{ $('Tier-1 Priority Store?').item.json.lead_tier }}",
            "outreach_angle": "={{ $('Tier-1 Priority Store?').item.json.outreach_angle }}",
            "outreach_status": "Gmail Draft Staged",
            "gmail_draft_id": "={{ $json.id }}",
            "verified_at": "={{ $('Tier-1 Priority Store?').item.json.verified_at }}"
          },
          "matchingColumns": [
            "domain"
          ],
          "schema": [
            {
              "id": "domain",
              "displayName": "domain",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "store_name",
              "displayName": "store_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "primary_email",
              "displayName": "primary_email",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "email_type",
              "displayName": "email_type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "sku_count",
              "displayName": "sku_count",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": false
            },
            {
              "id": "price_median_usd",
              "displayName": "price_median_usd",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": false
            },
            {
              "id": "icp_score",
              "displayName": "icp_score",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": false
            },
            {
              "id": "lead_tier",
              "displayName": "lead_tier",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "outreach_angle",
              "displayName": "outreach_angle",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "outreach_status",
              "displayName": "outreach_status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "gmail_draft_id",
              "displayName": "gmail_draft_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "verified_at",
              "displayName": "verified_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "id": "e10f8910-1111-4000-8000-000000000013",
      "name": "Log Tier-1 Draft to CRM",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        2940,
        240
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "YOUR_GOOGLE_SHEETS_CREDENTIAL_ID",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "resource": "sheet",
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Campaign Config').first().json.crmSpreadsheetId }}"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Leads"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "domain": "={{ $json.domain }}",
            "store_name": "={{ $json.brand_display }}",
            "primary_email": "={{ $json.primary_email }}",
            "email_type": "={{ $json.email_type }}",
            "sku_count": "={{ $json.sku_count ?? 0 }}",
            "price_median_usd": "={{ $json.price_median_usd ?? 0 }}",
            "icp_score": "={{ $json.icp_score }}",
            "lead_tier": "={{ $json.lead_tier }}",
            "outreach_angle": "={{ $json.outreach_angle }}",
            "outreach_status": "Nurture Queue (Tier 2)",
            "gmail_draft_id": "",
            "verified_at": "={{ $json.verified_at }}"
          },
          "matchingColumns": [
            "domain"
          ],
          "schema": [
            {
              "id": "domain",
              "displayName": "domain",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "store_name",
              "displayName": "store_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "primary_email",
              "displayName": "primary_email",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "email_type",
              "displayName": "email_type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "sku_count",
              "displayName": "sku_count",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": false
            },
            {
              "id": "price_median_usd",
              "displayName": "price_median_usd",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": false
            },
            {
              "id": "icp_score",
              "displayName": "icp_score",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": false
            },
            {
              "id": "lead_tier",
              "displayName": "lead_tier",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "outreach_angle",
              "displayName": "outreach_angle",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "outreach_status",
              "displayName": "outreach_status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "gmail_draft_id",
              "displayName": "gmail_draft_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "verified_at",
              "displayName": "verified_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "id": "e10f8910-1111-4000-8000-000000000014",
      "name": "Queue Tier-2 Lead in CRM",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        2360,
        640
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "YOUR_GOOGLE_SHEETS_CREDENTIAL_ID",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "aggregate": "aggregateAllItemData",
        "destinationFieldName": "staged_drafts",
        "include": "allFields",
        "options": {}
      },
      "id": "e10f8910-1111-4000-8000-000000000015",
      "name": "Aggregate Staged Drafts",
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [
        3240,
        240
      ]
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "send",
        "sendTo": "={{ $('Campaign Config').first().json.digestRecipientEmail }}",
        "subject": "={{ 'Weekly WooCommerce Pipeline: ' + ($json.staged_drafts || []).length + ' Tier-1 Gmail Drafts Staged' }}",
        "emailType": "text",
        "message": "={{ 'Weekly CartPulse run complete for ' + $('Campaign Config').first().json.dedupScope + '. Net-new ICP leads scored: ' + $('Score & Segment ICP Leads').all().length + ' | Tier-1 Gmail drafts staged: ' + ($json.staged_drafts || []).length + '.' }}",
        "options": {}
      },
      "id": "e10f8910-1111-4000-8000-000000000016",
      "name": "Send Weekly Pipeline Digest",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        3500,
        240
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "YOUR_GMAIL_CREDENTIAL_ID",
          "name": "Gmail account"
        }
      }
    }
  ],
  "connections": {
    "Weekly Schedule": {
      "main": [
        [
          {
            "node": "Campaign Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Campaign Config": {
      "main": [
        [
          {
            "node": "Pre-Flight Pool Check ($0)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pre-Flight Pool Check ($0)": {
      "main": [
        [
          {
            "node": "Matching Stores Available?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Matching Stores Available?": {
      "main": [
        [
          {
            "node": "Run CartPulse WooCommerce Scraper",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch Existing CRM Domains",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Pool Exhausted Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run CartPulse WooCommerce Scraper": {
      "main": [
        [
          {
            "node": "Exclude Existing CRM Leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Existing CRM Domains": {
      "main": [
        [
          {
            "node": "Exclude Existing CRM Leads",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Exclude Existing CRM Leads": {
      "main": [
        [
          {
            "node": "Score & Segment ICP Leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Score & Segment ICP Leads": {
      "main": [
        [
          {
            "node": "Tier-1 Priority Store?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Tier-1 Priority Store?": {
      "main": [
        [
          {
            "node": "Draft Personalized Pitch",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Queue Tier-2 Lead in CRM",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Draft Personalized Pitch",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Pitch Output": {
      "ai_outputParser": [
        [
          {
            "node": "Draft Personalized Pitch",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Draft Personalized Pitch": {
      "main": [
        [
          {
            "node": "Stage Tier-1 Gmail Draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Stage Tier-1 Gmail Draft": {
      "main": [
        [
          {
            "node": "Log Tier-1 Draft to CRM",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Tier-1 Draft to CRM": {
      "main": [
        [
          {
            "node": "Aggregate Staged Drafts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate Staged Drafts": {
      "main": [
        [
          {
            "node": "Send Weekly Pipeline Digest",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "4.0.0"
}