{
  "name": "Turn pages with steadily falling Google clicks into content refresh cards in Trello (GSC Magic)",
  "nodes": [
    {
      "id": "d8eda59a-44fe-4d56-af99-d3a70729f4d5",
      "name": "3rd of every month at 09:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "months",
              "triggerAtDayOfMonth": 3,
              "triggerAtHour": 9
            }
          ]
        }
      }
    },
    {
      "id": "1a28dbd0-4132-4d75-a281-769d7a82aee8",
      "name": "Settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        308,
        0
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "b3ec14b3-771a-424e-a6ca-aa61b73a6cd2",
              "name": "site",
              "value": "example.com",
              "type": "string"
            },
            {
              "id": "f93a8323-97d6-4bcc-a04c-4a0d8dedbbf3",
              "name": "trelloListId",
              "value": "YOUR_TRELLO_LIST_ID",
              "type": "string"
            },
            {
              "id": "cdb9312f-ddd9-4573-a1fc-9b1ac228bf03",
              "name": "minClicks",
              "value": 20,
              "type": "number"
            },
            {
              "id": "a8abe744-fd9d-4525-a039-ec26778ded6f",
              "name": "minDropPct",
              "value": 25,
              "type": "number"
            },
            {
              "id": "02f0fe01-67bf-4727-a922-434d89220f82",
              "name": "maxCards",
              "value": 5,
              "type": "number"
            },
            {
              "id": "4519e570-d2ef-40d9-a7f1-de8553076ffd",
              "name": "cooldownDays",
              "value": 90,
              "type": "number"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "935ffa3b-4502-47fb-a938-88f36c816041",
      "name": "GSC Magic: find decaying pages",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        616,
        0
      ],
      "onError": "continueRegularOutput",
      "parameters": {
        "method": "POST",
        "url": "https://mcp.gscmagic.com/mcp",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json, text/event-stream"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name: 'report_content_decay', arguments: { site: $json.site, min_clicks: $json.minClicks, min_drop_pct: $json.minDropPct, limit: 50 } } }) }}",
        "options": {
          "batching": {
            "batch": {
              "batchSize": 1,
              "batchInterval": 300
            }
          },
          "timeout": 180000
        }
      }
    },
    {
      "id": "cf86aba8-c1dc-4dd4-aeb5-85dcf5c03ec8",
      "name": "Pick pages without a recent card",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        924,
        0
      ],
      "parameters": {
        "jsCode": "// Turns a GSC Magic response (MCP JSON-RPC) into { ok, data, error, image }.\nfunction unwrap(res) {\n  const result = res && res.result;\n  if (result && Array.isArray(result.content)) {\n    const text = result.content.filter((b) => b.type === 'text').map((b) => b.text).join('\\n');\n    if (result.isError) return { ok: false, error: text || 'GSC Magic reported an error' };\n    let data;\n    try { data = JSON.parse(text); } catch (e) { data = { text }; }\n    const image = result.content.find((b) => b.type === 'image' && b.data);\n    return { ok: true, data, image };\n  }\n  const err = res && res.error;\n  const message = typeof err === 'string' ? err : (err && (err.message || err.description)) || 'No response from GSC Magic';\n  if (/401|unauthori[sz]ed|Authorization failed/i.test(message)) {\n    return { ok: false, error: 'GSC Magic rejected the access token (wrong, expired or revoked). Create a new one in the GSC Magic dashboard: Connect > Access tokens.' };\n  }\n  return { ok: false, error: String(message) };\n}\n\nconst cfg = $('Settings').first().json;\nconst res = unwrap($input.first().json);\nif (!res.ok) throw new Error('Content decay report failed: ' + res.error);\n\nconst store = $getWorkflowStaticData('global');\nstore.carded = store.carded || {};\nconst DAY = 24 * 60 * 60 * 1000;\nconst now = Date.now();\nfor (const [page, at] of Object.entries(store.carded)) if (now - at > cfg.cooldownDays * DAY) delete store.carded[page];\n\nconst windows = res.data.windows || [];\nconst rows = res.data.rows || [];\nconst picked = rows.filter((r) => !store.carded[r.page]).slice(0, cfg.maxCards);\nif (!picked.length) {\n  return [{ json: { skip: true, reason: rows.length\n    ? 'All ' + rows.length + ' decaying pages already got a card in the last ' + cfg.cooldownDays + ' days.'\n    : 'No page lost clicks in each of the last three 28-day windows (min ' + cfg.minClicks + ' clicks, min ' + cfg.minDropPct + '% drop). Nothing to refresh.' } }];\n}\nreturn picked.map((r) => ({ json: { site: res.data.site, page: r.page, clicks: r.clicks, clicksLost: r.clicks_lost, dropPct: r.drop_pct, windows } }));\n"
      }
    },
    {
      "id": "190429e3-5d52-430a-a11f-c046214774de",
      "name": "GSC Magic: top queries of the page",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1540,
        -20
      ],
      "onError": "continueRegularOutput",
      "parameters": {
        "method": "POST",
        "url": "https://mcp.gscmagic.com/mcp",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json, text/event-stream"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name: 'gsc_query_analytics', arguments: { site: $json.site, dimensions: ['query'], range: 'last_28_days', limit: 10, filters: [{ dimension: 'page', operator: 'equals', expression: $json.page }] } } }) }}",
        "options": {
          "batching": {
            "batch": {
              "batchSize": 1,
              "batchInterval": 300
            }
          },
          "timeout": 180000
        }
      }
    },
    {
      "id": "51dff2b2-0952-4314-a59f-84d2d6023d36",
      "name": "Write the card",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1848,
        -20
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Turns a GSC Magic response (MCP JSON-RPC) into { ok, data, error, image }.\nfunction unwrap(res) {\n  const result = res && res.result;\n  if (result && Array.isArray(result.content)) {\n    const text = result.content.filter((b) => b.type === 'text').map((b) => b.text).join('\\n');\n    if (result.isError) return { ok: false, error: text || 'GSC Magic reported an error' };\n    let data;\n    try { data = JSON.parse(text); } catch (e) { data = { text }; }\n    const image = result.content.find((b) => b.type === 'image' && b.data);\n    return { ok: true, data, image };\n  }\n  const err = res && res.error;\n  const message = typeof err === 'string' ? err : (err && (err.message || err.description)) || 'No response from GSC Magic';\n  if (/401|unauthori[sz]ed|Authorization failed/i.test(message)) {\n    return { ok: false, error: 'GSC Magic rejected the access token (wrong, expired or revoked). Create a new one in the GSC Magic dashboard: Connect > Access tokens.' };\n  }\n  return { ok: false, error: String(message) };\n}\n\nconst p = $('Pick pages without a recent card').item.json;\nconst res = unwrap($json);\nconst path = String(p.page).replace(/^https?:\\/\\/[^/]+/i, '') || '/';\nconst fmtDay = (s) => new Date(s + 'T00:00:00Z').toLocaleDateString('en-GB', { day: 'numeric', month: 'short', timeZone: 'UTC' });\n\nconst trend = p.windows.map((w, i) => '- ' + fmtDay(w.startDate) + ' to ' + fmtDay(w.endDate) + ': **' + (p.clicks[i] ?? '?') + '** clicks').join('\\n');\nlet queryBlock;\nif (!res.ok) queryBlock = '_Could not load queries: ' + res.error + '_';\nelse if (!(res.data.rows || []).length) queryBlock = '_No queries with clicks or impressions in the last 28 days._';\nelse queryBlock = res.data.rows.map((r) => '- ' + r.query + ': ' + r.clicks + ' clicks, ' + r.impressions + ' impressions, position ' + r.position).join('\\n');\n\nconst description = [\n  '**Page:** ' + p.page,\n  '**Clicks lost:** ' + p.clicksLost + ' (' + p.dropPct + '% over three 28-day windows)',\n  '', '**Trend**', trend,\n  '', '**Queries it still ranks for (last 28 days)**', queryBlock,\n  '', '**Refresh checklist**',\n  '- Search the top queries and compare the page with what ranks above it now',\n  '- Update facts, dates, screenshots and examples',\n  '- Answer the question in the first paragraph; tighten title and meta description',\n  '- Add internal links from newer related posts',\n  '- Re-request indexing in Search Console after publishing',\n].join('\\n');\n\nreturn { json: { page: p.page, title: 'Refresh ' + path + ' (-' + p.dropPct + '% clicks)', description } };\n"
      }
    },
    {
      "id": "993656b1-72cd-4cd4-aea5-0db5bad1e029",
      "name": "Create Trello card",
      "type": "n8n-nodes-base.trello",
      "typeVersion": 1,
      "position": [
        2156,
        -20
      ],
      "parameters": {
        "listId": "={{ $('Settings').first().json.trelloListId }}",
        "name": "={{ $json.title }}",
        "description": "={{ $json.description }}",
        "additionalFields": {}
      }
    },
    {
      "id": "8578d07b-635b-4c42-a8bb-71fc4d83ceef",
      "name": "Remember carded pages",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2464,
        -20
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const store = $getWorkflowStaticData('global');\nstore.carded = store.carded || {};\nconst page = $('Write the card').item.json.page;\nstore.carded[page] = Date.now();\nreturn { json: { page, card: $json.shortUrl || $json.url || $json.id } };\n"
      }
    },
    {
      "id": "b7e4189e-d568-4fa1-ada5-c9e3ca36e26f",
      "name": "Any page needs a card?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1232,
        0
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "489a7e1e-8f78-42ac-a7ea-ad7e352ff2f8",
              "leftValue": "={{ $json.skip === true }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "262b5b2c-a22b-41ad-a536-b2afea190897",
      "name": "Nothing to refresh this month",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1232,
        200
      ],
      "parameters": {}
    },
    {
      "id": "7edbd534-615a-42a5-a0ba-c9ef02e5a7e2",
      "name": "Step 1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -311
      ],
      "parameters": {
        "content": "## Step 1: Configure\n- **site**: Search Console property or domain.\n- **trelloListId**: the list the cards go to.\n- **minClicks**: clicks the page needed in the oldest window to be considered.\n- **minDropPct**: total drop from the oldest to the newest window, in percent.\n- **maxCards**: cards per run, biggest losses first.\n- **cooldownDays**: no new card for the same page within this many days.",
        "width": 488,
        "height": 701,
        "color": 7
      }
    },
    {
      "id": "73ab2ca3-b060-41fa-aa3c-96cea11088ef",
      "name": "Step 2",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        576,
        -311
      ],
      "parameters": {
        "content": "## Step 2: Find decaying pages\nPages that lost clicks in each of the last three 28-day windows, minus pages carded in the last `cooldownDays`. Nothing found ends on **Nothing to refresh this month**.",
        "width": 796,
        "height": 701,
        "color": 7
      }
    },
    {
      "id": "001452bb-ffe7-4286-a389-71e027069502",
      "name": "Step 3",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1500,
        -311
      ],
      "parameters": {
        "content": "## Step 3: Write the brief\nPulls the queries each page still ranks for and writes the card: trend, queries, refresh checklist.",
        "width": 488,
        "height": 701,
        "color": 7
      }
    },
    {
      "id": "c462f47c-8e8f-4fad-a6d6-adab4c6d1f99",
      "name": "Step 4",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        2116,
        -311
      ],
      "parameters": {
        "content": "## Step 4: Create the card\nCreates the Trello card, then remembers the page so it is not carded again too soon.",
        "width": 488,
        "height": 701,
        "color": 7
      }
    },
    {
      "id": "2edaeae8-d149-400d-a692-3a093712a622",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -740,
        -311
      ],
      "parameters": {
        "content": "## Content decay to refresh tasks\nA page that loses clicks three months in a row rarely recovers by itself. Once a month this workflow finds those pages in Search Console and creates one Trello card per page, with the click trend and the queries the page still ranks for, so a writer can start the refresh without opening Search Console.\n\n**Who it is for:** content teams, SEO freelancers and agencies that run monthly content maintenance.\n\n**How it works**\n1. Finds pages whose clicks fell in each of the last three 28-day windows (a steady slide, not a one-off dip).\n2. Skips pages that already got a card in the last `cooldownDays`.\n3. Pulls the top queries of each remaining page.\n4. Creates a Trello card with the trend, the queries and a short refresh checklist, then remembers the page.\n\n**Connect GSC Magic** (about 2 minutes)\n1. In the [GSC Magic dashboard](https://app.gscmagic.com) open **Connect > Access tokens** and create a token. Copy the `gsm_...` value (shown once).\n2. Open the first node whose name starts with **GSC Magic:**, and under **Credential for Bearer Auth** create a new credential. Paste the token into **Bearer Token**. In every other **GSC Magic:** node, select that same credential.\n3. Never paste the token into a URL, a prompt or a Code node.\n\n**Then**\n4. Fill in **Settings**. To find a Trello list id, open the board, add `.json` to its URL and search for the list name; the `id` next to it is the list id.\n5. Add a Trello credential to **Create Trello card**. Using Asana, ClickUp or Notion instead? Replace that one node and map `title` and `description`.\n6. Execute once, check the cards, activate.\n\nSchedule times use the workflow time zone (Workflow settings > Timezone), which defaults to the instance time zone.\n\n**Calls per run:** 1 + one per new card (at most `maxCards`). With the default 5 it fits the Free plan's 10 calls a day.\n\n### Errors and limits\n- No decaying pages (or all already carded): the run ends on **Nothing to refresh this month**; open **Pick pages without a recent card** to read why.\n- If the decay report fails, the run stops with the reason (set an n8n error workflow to be notified). No cards are created.\n- If loading queries fails for one page, its card is still created with a note instead of the query list.\n- A page is remembered only after its card exists, so a Trello failure means the page is retried next month.\n- Remembering pages uses workflow static data, which n8n saves for active runs only. Manual test runs can create the same card again.",
        "width": 640,
        "height": 1014
      }
    }
  ],
  "connections": {
    "3rd of every month at 09:00": {
      "main": [
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Settings": {
      "main": [
        [
          {
            "node": "GSC Magic: find decaying pages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GSC Magic: find decaying pages": {
      "main": [
        [
          {
            "node": "Pick pages without a recent card",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pick pages without a recent card": {
      "main": [
        [
          {
            "node": "Any page needs a card?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Any page needs a card?": {
      "main": [
        [
          {
            "node": "GSC Magic: top queries of the page",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Nothing to refresh this month",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GSC Magic: top queries of the page": {
      "main": [
        [
          {
            "node": "Write the card",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write the card": {
      "main": [
        [
          {
            "node": "Create Trello card",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Trello card": {
      "main": [
        [
          {
            "node": "Remember carded pages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "active": false
}
