{
  "nodes": [
    {
      "id": "1bec1f61-e93c-464c-9e50-4e3bd70a91b8",
      "name": "Weekly Workflow Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        1040,
        144
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 6
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "62891386-ff79-476d-b48d-b5cc2c6038f0",
      "name": "Fetch Customers from Google Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1264,
        144
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "",
          "cachedResultName": ""
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "3edda02b-acce-4439-b483-2b47461663ad",
      "name": "Get Customer Tech Stack (PredictLeads)",
      "type": "@predictleads/n8n-nodes-predictleads.predictLeads",
      "position": [
        1552,
        144
      ],
      "parameters": {
        "domain": "={{ $json.company_domain }}",
        "resource": "technologyDetections",
        "operation": "retrieveTechnologiesUsedByCompany",
        "requestOptions": {}
      },
      "credentials": {},
      "typeVersion": 1
    },
    {
      "id": "bfab1a69-a035-443a-99fb-8455cb08923e",
      "name": "Split Technologies Per Customer",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        1776,
        144
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "data"
      },
      "typeVersion": 1
    },
    {
      "id": "d3a3ff25-538f-4df5-ae72-8d142e57e0f8",
      "name": "Limit Technologies for Processing",
      "type": "n8n-nodes-base.limit",
      "position": [
        1984,
        144
      ],
      "parameters": {
        "maxItems": 2
      },
      "typeVersion": 1
    },
    {
      "id": "3f8d44d3-6cae-4d69-8237-b5e9cb691b7d",
      "name": "Extract Technology ID",
      "type": "n8n-nodes-base.set",
      "position": [
        2192,
        144
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "858600f7-8f80-4843-afe0-6b50c76ac40d",
              "name": "tech_Id",
              "type": "string",
              "value": "={{ $json.relationships.technology.data.id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "799d2322-d3ca-4362-85f6-37267f2684b7",
      "name": "Get Technology Details by ID",
      "type": "@predictleads/n8n-nodes-predictleads.predictLeads",
      "position": [
        2480,
        144
      ],
      "parameters": {
        "resource": "technologies",
        "operation": "retrieveSingleTechnologyByIdOrFuzzyName",
        "idOrFuzzyName": "={{ $json.tech_Id }}",
        "requestOptions": {}
      },
      "credentials": {},
      "typeVersion": 1
    },
    {
      "id": "9d741aae-4e52-42d3-8dd7-ecf984de69f8",
      "name": "Detect Competitor Usage",
      "type": "n8n-nodes-base.code",
      "position": [
        2720,
        144
      ],
      "parameters": {
        "jsCode": "const competitors = [\n  \"HubSpot\",\n  \"Salesforce\",\n  \"Zoho CRM\"\n];\n\n// \u2705 correct way to get all items in n8n\n\nconst items = $input.all();\n\nreturn items.map(item => {\n\n  const techName = item.json.data?.[0]?.attributes?.name || \"\";\n  const domain = (item.json.company_domain || \"\").toLowerCase();\n\n  const techLower = techName.toLowerCase();\n\n  const isCompetitor = competitors.some(c =>\n    techLower.includes(c.toLowerCase())\n  );\n\n  const isSameCompany = domain.includes(techLower);\n\n  return {\n    json: {\n      ...item.json,\n      techName,\n      competitorDetected: isCompetitor && !isSameCompany\n    }\n  };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "761e6d97-ab67-4964-80b9-6597378e85c2",
      "name": "Is Competitor Detected?",
      "type": "n8n-nodes-base.if",
      "position": [
        2960,
        144
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "84ded6f1-8eb5-43af-b09f-04bf26b5a588",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              },
              "leftValue": "={{$json[\"competitorDetected\"]}}",
              "rightValue": false
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "480e1730-c5a7-437c-9a86-22e5561f7425",
      "name": "Notify Team (No Competitor - Safe Account)",
      "type": "n8n-nodes-base.slack",
      "position": [
        3168,
        272
      ],
      "parameters": {
        "text": "=\ud83d\udcca Weekly Customer Tech Check Update  Company: {{ $json.data[0].attributes.domain }} Detected Tool: {{$json[\"techName\"]}}  Status: \u2705 No competitor detected  Insight: Customer is currently not using any tracked competitor tools. No immediate churn risk based on tech adoption.  Next Step: Continue regular engagement and monitor in upcoming cycles.  \u2014 Automated Churn Monitoring System",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": ""
        },
        "otherOptions": {},
        "authentication": "oAuth2"
      },
      "typeVersion": 2.4
    },
    {
      "id": "d62d80eb-8311-474d-afb3-554e1e716fd2",
      "name": "Calculate Renewal Risk (90 Days)",
      "type": "n8n-nodes-base.code",
      "position": [
        3504,
        128
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\n\nreturn items.map((item, index) => {\n\n  // \u2705 har item ke corresponding row se renewal_date lo (index fix)\n  const sheetItem = $items(\"Fetch Customers from Google Sheet\")[index];\n  const renewalDate = new Date(sheetItem.json.renewal_date);\n\n  const today = new Date();\n\n  const diffTime = renewalDate - today;\n  const diffDays = diffTime / (1000 * 60 * 60 * 24);\n\n  return {\n    json: {\n      ...item.json,\n      daysToRenewal: Math.round(diffDays),\n      within90Days: diffDays <= 90\n    }\n  };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "fbe4db1f-fb40-4bb6-9be6-68f374d39674",
      "name": "Is Renewal Within 90 Days?",
      "type": "n8n-nodes-base.if",
      "position": [
        3728,
        128
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "ac0bf309-8dc3-4826-895b-fd6d78dfc854",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              },
              "leftValue": "={{$json[\"within90Days\"]}}",
              "rightValue": true
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "d38fd0ca-5176-474e-9e4e-de54d62670d9",
      "name": "Ignore (No Immediate Risk)",
      "type": "n8n-nodes-base.noOp",
      "position": [
        3984,
        224
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "ffc89e94-9dab-4842-8d21-7b4f96b4601c",
      "name": "Send Churn Risk Alert Email to CSM",
      "type": "n8n-nodes-base.gmail",
      "position": [
        3984,
        0
      ],
      "parameters": {
        "sendTo": "={{ $('Fetch Customers from Google Sheet').item.json.csm_email }}",
        "message": "=Hi,\n\nChurn Risk Alert for your assigned account:\n\nCompany: {{ $json.data[0].attributes.domain }}\nDetected Tool: {{$json[\"techName\"]}}\nDays to Renewal: {{$json[\"daysToRenewal\"]}}\nRenewal Window: Within 90 days\n\nRecommended Action:\nPlease engage with the customer proactively to prevent potential churn.\n\nAutomated Churn Monitoring System",
        "options": {},
        "subject": "=\ud83d\udea8 Churn Risk Alert - {{ $json.data[0].attributes.domain }}",
        "emailType": "text"
      },
      "typeVersion": 2.2
    },
    {
      "id": "f3bc1760-f6be-4e9f-8824-89ebba4bbc75",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        464,
        -144
      ],
      "parameters": {
        "color": 5,
        "width": 400,
        "height": 912,
        "content": "## Churn Risk Detection via Competitor Tech Adoption Using Predict leads\n\n### How it works\n1. Scheduled trigger runs weekly and loads customer domains from Google Sheets\n2. Fetches each customer's tech stack from PredictLeads API\n3. Detects if customer adopted competitor tools (HubSpot, Salesforce, Zoho CRM)\n4. Flags accounts where competitors are detected\n5. Calculates renewal timing - alerts CSM for high-risk accounts (competitor + within 90 days)\n\n### Setup\n1. Create Google Sheet with columns: company_domain, renewal_date, csm_email\n2. Connect Gmail OAuth2 for CSM alerts\n3. Connect Slack OAuth2 for team notifications (optional)\n4. Add PredictLeads API credentials (X-Api-Key, X-Api-Token)\n\n### Customization\n- Adjust competitor list in \"Detect Competitor Usage\" Code node\n- Modify 90-day threshold in \"Calculate Renewal Risk\" node"
      },
      "typeVersion": 1
    },
    {
      "id": "5c120068-56ea-4844-9e89-cc1cc6f5d48e",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        944,
        -48
      ],
      "parameters": {
        "color": 0,
        "width": 496,
        "height": 400,
        "content": "## Trigger & Customer Source\nWeekly trigger loads customer data from Google Sheets."
      },
      "typeVersion": 1
    },
    {
      "id": "93d3d437-3bb6-48de-b1c3-71acb0da3176",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1520,
        -48
      ],
      "parameters": {
        "color": 0,
        "width": 840,
        "height": 496,
        "content": "## Tech Stack Analysis with Predict Leads\nFetches tech stack, splits records, limits processing, extracts IDs."
      },
      "typeVersion": 1
    },
    {
      "id": "0b11f379-1514-4c76-9e41-64392bf5f46b",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2400,
        -48
      ],
      "parameters": {
        "color": 0,
        "width": 696,
        "height": 528,
        "content": "## Competitor Detection\nLooks up tech details, detects competitor tools, routes accounts."
      },
      "typeVersion": 1
    },
    {
      "id": "d6607254-b295-45c2-9a4f-1a438807fc4d",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3392,
        -48
      ],
      "parameters": {
        "color": 0,
        "width": 808,
        "height": 480,
        "content": "## Renewal Risk & Alerting\nCalculates days to renewal, alerts CSM for high-risk accounts."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Extract Technology ID": {
      "main": [
        [
          {
            "node": "Get Technology Details by ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Detect Competitor Usage": {
      "main": [
        [
          {
            "node": "Is Competitor Detected?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Competitor Detected?": {
      "main": [
        [
          {
            "node": "Calculate Renewal Risk (90 Days)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Notify Team (No Competitor - Safe Account)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Weekly Workflow Trigger": {
      "main": [
        [
          {
            "node": "Fetch Customers from Google Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Renewal Within 90 Days?": {
      "main": [
        [
          {
            "node": "Send Churn Risk Alert Email to CSM",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Ignore (No Immediate Risk)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Technology Details by ID": {
      "main": [
        [
          {
            "node": "Detect Competitor Usage",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Technologies Per Customer": {
      "main": [
        [
          {
            "node": "Limit Technologies for Processing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Renewal Risk (90 Days)": {
      "main": [
        [
          {
            "node": "Is Renewal Within 90 Days?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Customers from Google Sheet": {
      "main": [
        [
          {
            "node": "Get Customer Tech Stack (PredictLeads)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Limit Technologies for Processing": {
      "main": [
        [
          {
            "node": "Extract Technology ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Customer Tech Stack (PredictLeads)": {
      "main": [
        [
          {
            "node": "Split Technologies Per Customer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}