{
  "name": "Monitor Threads keyword mentions in Google Sheets with Apify",
  "nodes": [
    {
      "parameters": {
        "content": "## Monitor Threads keyword mentions in Google Sheets\n\n**Who's it for**\nSocial media, brand and community managers who want a running log of what is posted on Threads about a brand, product, competitor or hashtag.\n\n**How it works**\n1. The schedule starts the workflow every morning.\n2. The Set node holds your keywords, how many days back to look, the posts to keep per keyword and your Google Sheet.\n3. The Apify node runs the [Threads Search Scraper](https://apify.com/logical_scrapers/threads-search-scraper?utm_source=n8n&utm_medium=template&utm_campaign=monitor-threads-keyword-mentions) Actor, which reads the Top, Recent and Tags tabs of public Threads search and keeps the posts from the last few days. No Threads account or cookies are needed.\n4. The query, author, text, like, reply and repost counts, date and URL of each post are kept.\n5. Google Sheets adds new posts as rows and updates the ones it has seen before, matched on the post URL.\n\n**How to set up**\n1. Install the Apify community node (`@apify/n8n-nodes-apify`) and connect your Apify account in the Apify node.\n2. Connect your Google account in the Google Sheets node.\n3. Create a sheet with this header row:\n`searchQuery, username, text, likeCount, replyCount, repostCount, mediaType, createdAt, url`\n4. Open **Set search and sheet** and enter your keywords and the sheet URL.\n\n**Requirements**\nAn Apify account (the Actor is pay per result, see its Store page for the price) and a Google account.\n\nSetup guide: https://www.logicalscrapers.com/integrations/n8n#monitor-threads-keyword-mentions",
        "height": 660,
        "width": 560
      },
      "id": "5c0a7d5e-6f0a-4c1b-9a56-1f2d6f0e1a01",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -680,
        -260
      ]
    },
    {
      "parameters": {
        "content": "### 1. Your settings\nEdit **Set search and sheet**: keywords or hashtags, search tab (`all`, `top`, `recent` or `tags`), how many days back to keep posts from, posts per keyword, spend limit per run and the Google Sheet to write to.",
        "height": 420,
        "width": 440,
        "color": 7
      },
      "id": "5c0a7d5e-6f0a-4c1b-9a56-1f2d6f0e1a02",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -60,
        -260
      ]
    },
    {
      "parameters": {
        "content": "### 2. Search Threads\nRuns the Threads Search Scraper Actor on your Apify account and waits for the posts. `maxItems` is the number of posts kept **per keyword**. Threads search mixes old and new posts, so only posts from the last `postedWithinDays` days are kept.",
        "height": 420,
        "width": 260,
        "color": 7
      },
      "id": "5c0a7d5e-6f0a-4c1b-9a56-1f2d6f0e1a03",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        420,
        -260
      ]
    },
    {
      "parameters": {
        "content": "### 3. Save to the sheet\nKeeps the columns the sheet needs, then appends new posts and updates known ones, matched on `url`. Add or remove fields in **Keep sheet columns** to change the columns.",
        "height": 420,
        "width": 480,
        "color": 7
      },
      "id": "5c0a7d5e-6f0a-4c1b-9a56-1f2d6f0e1a04",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        720,
        -260
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 8
            }
          ]
        }
      },
      "id": "5c0a7d5e-6f0a-4c1b-9a56-1f2d6f0e1a11",
      "name": "Run every morning",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "0d6f4c0e-1b1a-4a8e-8b0b-000000000001",
              "name": "searchQueries",
              "value": "[\"your brand\", \"#yourhashtag\"]",
              "type": "array"
            },
            {
              "id": "0d6f4c0e-1b1a-4a8e-8b0b-000000000002",
              "name": "searchType",
              "value": "all",
              "type": "string"
            },
            {
              "id": "0d6f4c0e-1b1a-4a8e-8b0b-000000000007",
              "name": "postedWithinDays",
              "value": 7,
              "type": "number"
            },
            {
              "id": "0d6f4c0e-1b1a-4a8e-8b0b-000000000003",
              "name": "maxItems",
              "value": 20,
              "type": "number"
            },
            {
              "id": "0d6f4c0e-1b1a-4a8e-8b0b-000000000004",
              "name": "maxCostPerRunUsd",
              "value": 0.25,
              "type": "number"
            },
            {
              "id": "0d6f4c0e-1b1a-4a8e-8b0b-000000000005",
              "name": "googleSheetUrl",
              "value": "https://docs.google.com/spreadsheets/d/YOUR_SHEET_ID/edit",
              "type": "string"
            },
            {
              "id": "0d6f4c0e-1b1a-4a8e-8b0b-000000000006",
              "name": "sheetName",
              "value": "Sheet1",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "5c0a7d5e-6f0a-4c1b-9a56-1f2d6f0e1a12",
      "name": "Set search and sheet",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "resource": "Actors",
        "operation": "Run actor and get dataset",
        "actorId": "logical_scrapers~threads-search-scraper",
        "customBody": "={\n  \"searchQueries\": {{ JSON.stringify($json.searchQueries) }},\n  \"searchType\": \"{{ $json.searchType }}\",\n  \"maxItems\": {{ $json.maxItems }},\n  \"postedAfter\": \"{{ $now.minus({ days: $json.postedWithinDays }).toFormat('yyyy-MM-dd') }}\"\n}",
        "memory": 512,
        "maxTotalChargeUsd": "={{ $json.maxCostPerRunUsd }}"
      },
      "id": "5c0a7d5e-6f0a-4c1b-9a56-1f2d6f0e1a13",
      "name": "Search Threads posts",
      "type": "@apify/n8n-nodes-apify.apify",
      "typeVersion": 1,
      "position": [
        500,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "0d6f4c0e-1b1a-4a8e-8b0b-000000000100",
              "name": "searchQuery",
              "value": "={{ $json.searchQuery }}",
              "type": "string"
            },
            {
              "id": "0d6f4c0e-1b1a-4a8e-8b0b-000000000101",
              "name": "username",
              "value": "={{ $json.username }}",
              "type": "string"
            },
            {
              "id": "0d6f4c0e-1b1a-4a8e-8b0b-000000000102",
              "name": "text",
              "value": "={{ $json.text }}",
              "type": "string"
            },
            {
              "id": "0d6f4c0e-1b1a-4a8e-8b0b-000000000103",
              "name": "likeCount",
              "value": "={{ $json.likeCount }}",
              "type": "number"
            },
            {
              "id": "0d6f4c0e-1b1a-4a8e-8b0b-000000000104",
              "name": "replyCount",
              "value": "={{ $json.replyCount }}",
              "type": "number"
            },
            {
              "id": "0d6f4c0e-1b1a-4a8e-8b0b-000000000105",
              "name": "repostCount",
              "value": "={{ $json.repostCount }}",
              "type": "number"
            },
            {
              "id": "0d6f4c0e-1b1a-4a8e-8b0b-000000000106",
              "name": "mediaType",
              "value": "={{ $json.mediaType }}",
              "type": "string"
            },
            {
              "id": "0d6f4c0e-1b1a-4a8e-8b0b-000000000107",
              "name": "createdAt",
              "value": "={{ $json.createdAt }}",
              "type": "string"
            },
            {
              "id": "0d6f4c0e-1b1a-4a8e-8b0b-000000000108",
              "name": "url",
              "value": "={{ $json.url }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "5c0a7d5e-6f0a-4c1b-9a56-1f2d6f0e1a14",
      "name": "Keep sheet columns",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        800,
        0
      ]
    },
    {
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "value": "={{ $('Set search and sheet').first().json.googleSheetUrl }}",
          "mode": "url"
        },
        "sheetName": {
          "__rl": true,
          "value": "={{ $('Set search and sheet').first().json.sheetName }}",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [
            "url"
          ],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "id": "5c0a7d5e-6f0a-4c1b-9a56-1f2d6f0e1a15",
      "name": "Save posts to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1020,
        0
      ]
    }
  ],
  "connections": {
    "Run every morning": {
      "main": [
        [
          {
            "node": "Set search and sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set search and sheet": {
      "main": [
        [
          {
            "node": "Search Threads posts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search Threads posts": {
      "main": [
        [
          {
            "node": "Keep sheet columns",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Keep sheet columns": {
      "main": [
        [
          {
            "node": "Save posts to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}
