{
  "name": "Find pages close to page one and draft better titles and meta descriptions with AI in Google Sheets (GSC Magic)",
  "nodes": [
    {
      "id": "6a811889-5f7d-486b-a4ff-d0d0be6903a6",
      "name": "Every Monday at 07:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtDay": [
                1
              ],
              "triggerAtHour": 7
            }
          ]
        }
      }
    },
    {
      "id": "fb0c0ed2-6c52-4001-af94-45ea1a516374",
      "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": "f85db49f-cab2-401a-aeb2-1b6261111ded",
              "name": "sheetUrl",
              "value": "https://docs.google.com/spreadsheets/d/YOUR_SHEET_ID/edit",
              "type": "string"
            },
            {
              "id": "49a9ad95-940a-4ee5-afe7-681cd01c0f0f",
              "name": "maxPages",
              "value": 10,
              "type": "number"
            },
            {
              "id": "2da857c7-f9c2-40eb-a857-c68d7c80e3a4",
              "name": "minImpressions",
              "value": 100,
              "type": "number"
            },
            {
              "id": "55e7b2ed-6945-414c-a5fb-6b3ae001dc8b",
              "name": "language",
              "value": "the language of the page",
              "type": "string"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "49cf768d-10c6-4505-a127-b6eac6f249f1",
      "name": "GSC Magic: quick wins",
      "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_quick_wins', arguments: { site: $json.site, range: 'last_28_days', min_impressions: $json.minImpressions, limit: 300 } } }) }}",
        "options": {
          "batching": {
            "batch": {
              "batchSize": 1,
              "batchInterval": 300
            }
          },
          "timeout": 180000
        }
      }
    },
    {
      "id": "93a23569-4342-4973-a43d-03cff271066a",
      "name": "Group queries by page",
      "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('Quick wins report failed: ' + res.error);\n\nconst pages = {};\nfor (const r of res.data.rows || []) {\n  const p = pages[r.page] = pages[r.page] || { page: r.page, potential: 0, impressions: 0, posWeighted: 0, queries: [] };\n  p.potential += r.potential_extra_clicks;\n  p.impressions += r.impressions;\n  p.posWeighted += r.position * r.impressions;\n  p.queries.push({ query: r.query, impressions: r.impressions, position: r.position });\n}\nconst list = Object.values(pages)\n  .sort((a, b) => b.potential - a.potential)\n  .slice(0, cfg.maxPages)\n  .map((p) => ({\n    page: p.page,\n    potential: p.potential,\n    impressions: p.impressions,\n    avgPosition: Math.round((p.posWeighted / p.impressions) * 10) / 10,\n    queries: p.queries.sort((a, b) => b.impressions - a.impressions).slice(0, 5),\n  }));\nreturn list.map((json) => ({ json }));\n"
      }
    },
    {
      "id": "dca307cb-7fae-4f10-a42b-11b9b97734ea",
      "name": "Fetch the live page",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1232,
        0
      ],
      "onError": "continueRegularOutput",
      "parameters": {
        "url": "={{ $json.page }}",
        "options": {
          "batching": {
            "batch": {
              "batchSize": 1,
              "batchInterval": 500
            }
          },
          "response": {
            "response": {
              "responseFormat": "text",
              "outputPropertyName": "html"
            }
          },
          "timeout": 20000
        }
      }
    },
    {
      "id": "452515c9-d7fd-4220-ac20-e7e99ac970e0",
      "name": "Read current title and description",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1540,
        0
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const p = $('Group queries by page').item.json;\nconst html = String($json.html || '');\nconst decode = (s) => s.replace(/&amp;/g, '&').replace(/&quot;/g, '\"').replace(/&#0?39;|&apos;/g, \"'\").replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/\\s+/g, ' ').trim();\nconst pick = (re) => { const m = html.match(re); return m ? decode(m[1]) : ''; };\nconst title = pick(/<title[^>]*>([\\s\\S]*?)<\\/title>/i);\nconst description = pick(/<meta[^>]+name=[\"']description[\"'][^>]*content=[\"']([^\"']*)[\"']/i)\n  || pick(/<meta[^>]+content=[\"']([^\"']*)[\"'][^>]*name=[\"']description[\"']/i);\nconst h1 = pick(/<h1[^>]*>([\\s\\S]*?)<\\/h1>/i).replace(/<[^>]+>/g, '');\nreturn { json: { ...p, fetched: Boolean(html), currentTitle: title, currentDescription: description, h1 } };\n"
      }
    },
    {
      "id": "c756881b-599d-4ea4-a483-897548daf037",
      "name": "Draft title and description",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.5,
      "position": [
        1848,
        0
      ],
      "onError": "continueRegularOutput",
      "parameters": {
        "promptType": "define",
        "hasOutputParser": true,
        "text": "=You improve search snippets. Write one new HTML title and one meta description for this page.\n\nPage: {{ $json.page }}\nCurrent title: {{ $json.currentTitle || '(none found)' }}\nCurrent meta description: {{ $json.currentDescription || '(none found)' }}\nH1: {{ $json.h1 || '(none found)' }}\nSearch queries that show this page (impressions, average position):\n{{ $json.queries.map(q => '- ' + q.query + ' (' + q.impressions + ', ' + q.position + ')').join('\\n') }}\n\nRules:\n- Write in {{ $('Settings').first().json.language }}.\n- Title: at most 60 characters, main query near the start, no clickbait, keep any brand suffix the current title has.\n- Description: at most 155 characters, says what the page gives the reader, matches the queries' intent.\n- Do not promise anything the current title, description or H1 does not support.\n- notes: one sentence on why the new pair should earn more clicks."
      }
    },
    {
      "id": "6d5dd328-7122-4458-ab29-109b25dacfaf",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        1806,
        220
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {
          "temperature": 0.4
        }
      }
    },
    {
      "id": "c2113a06-2669-49b8-a74d-f7486ade277f",
      "name": "Title and description format",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.2,
      "position": [
        1974,
        220
      ],
      "parameters": {
        "schemaType": "fromJson",
        "jsonSchemaExample": "{\n  \"title\": \"Best hiking boots for wide feet (2026 tests)\",\n  \"description\": \"We tested 14 boots on wide feet...\",\n  \"notes\": \"Leads with the main query.\"\n}"
      }
    },
    {
      "id": "6be2f257-0ea1-444d-ad02-8bc4cfcdf177",
      "name": "Prepare the sheet row",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2212,
        0
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const p = $('Read current title and description').item.json;\nconst draft = $json.output || {};\nconst notes = [];\nif (!p.fetched) notes.push('Could not fetch the page; drafts are based on queries only.');\nif ($json.error) notes.push('AI draft failed: ' + (($json.error && $json.error.message) || $json.error));\nconst title = String(draft.title || '').trim();\nconst description = String(draft.description || '').trim();\nif (title.length > 60) notes.push('Suggested title is ' + title.length + ' characters, trim it.');\nif (description.length > 155) notes.push('Suggested description is ' + description.length + ' characters, trim it.');\nif (draft.notes) notes.push(String(draft.notes));\n\nreturn { json: {\n  'Page': p.page,\n  'Top queries': p.queries.map((q) => q.query).join(', '),\n  'Impressions': p.impressions,\n  'Avg position': p.avgPosition,\n  'Potential clicks': p.potential,\n  'Current title': p.currentTitle,\n  'Suggested title': title,\n  'Current description': p.currentDescription,\n  'Suggested description': description,\n  'Notes': notes.join(' '),\n  'Status': 'To review',\n  'Updated': new Date().toISOString().slice(0, 10),\n} };\n"
      }
    },
    {
      "id": "9f2c5bf9-ab13-459b-ac7b-4fb5ad291cff",
      "name": "Add or update row in Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        2520,
        0
      ],
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": "={{ $('Settings').first().json.sheetUrl }}"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Quick wins"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [
            "Page"
          ],
          "schema": []
        },
        "options": {}
      }
    },
    {
      "id": "7edbd534-615a-42a5-a0ba-c9ef02e5a7e2",
      "name": "Step 1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -249
      ],
      "parameters": {
        "content": "## Step 1: Configure\n- **site**: Search Console property or domain.\n- **sheetUrl**: the Google Sheet with the `Quick wins` tab.\n- **maxPages**: pages per run (one AI request each).\n- **minImpressions**: ignore query + page pairs below this in 28 days.\n- **language**: language of the drafts, e.g. `German`. The default keeps each page's own language.",
        "width": 488,
        "height": 659,
        "color": 7
      }
    },
    {
      "id": "f8881499-cc94-42b4-a0d2-798ece16818a",
      "name": "Step 2",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        576,
        -249
      ],
      "parameters": {
        "content": "## Step 2: Find quick wins\nQuery and page pairs at positions 4 to 20, grouped per page and sorted by potential extra clicks.",
        "width": 488,
        "height": 659,
        "color": 7
      }
    },
    {
      "id": "05e13308-03f1-4649-ae11-ccbf676a1ba1",
      "name": "Step 3",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1192,
        -249
      ],
      "parameters": {
        "content": "## Step 3: Read the live page\nFetches each page and reads its current title, meta description and H1.",
        "width": 488,
        "height": 659,
        "color": 7
      }
    },
    {
      "id": "2c2e92fc-77f2-4492-a9d9-c1ddf5921ff7",
      "name": "Step 4",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1766,
        -249
      ],
      "parameters": {
        "content": "## Step 4: Draft with AI\nThe model writes a title (60 characters) and description (155) around the real queries. Swap in any chat model.",
        "width": 348,
        "height": 659,
        "color": 7
      }
    },
    {
      "id": "a2f3e50b-90f0-4dc1-a655-45d81fc3d29e",
      "name": "Step 5",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        2172,
        -249
      ],
      "parameters": {
        "content": "## Step 5: Save for review\nChecks lengths, then adds or updates one row per page, marked `To review`.",
        "width": 488,
        "height": 659,
        "color": 7
      }
    },
    {
      "id": "9e67dbec-545b-4ca3-a9ca-1985017abfcd",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -740,
        -249
      ],
      "parameters": {
        "content": "## Quick wins: AI drafts for titles and meta descriptions\nPages ranking at positions 4 to 20 with many impressions are the cheapest clicks you can win: a better title or description often lifts CTR without new content. Every Monday this workflow finds those pages, reads their current title and description from the live page, asks an AI model for a better pair built around the queries people actually search, and writes everything into a Google Sheet for a human to approve.\n\n**Who it is for:** freelancers and in-house SEOs who want a weekly, reviewable list instead of a dashboard.\n\n**How it works**\n1. GSC Magic returns query + page pairs at positions 4-20, sorted by potential extra clicks.\n2. Queries are grouped per page; the top `maxPages` pages are kept.\n3. Each page is fetched to read the current `<title>`, meta description and H1.\n4. The model drafts a title (max 60 characters) and description (max 155) that keep the page's topic.\n5. One row per page is added or updated in the sheet (matched on **Page**, so reruns update rows instead of duplicating them). New rows start as `To review`.\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. Create a Google Sheet with a tab named `Quick wins` and this header row:\n`Page | Top queries | Impressions | Avg position | Potential clicks | Current title | Suggested title | Current description | Suggested description | Notes | Status | Updated`\n5. Put the sheet URL in **Settings**, add Google Sheets and OpenAI credentials, execute once, 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 GSC Magic call (Free plan works) + one AI request per page.\n\n### Errors and limits\n- If GSC Magic fails, the run stops with the reason before any AI request is made.\n- Pages that block bots or need JavaScript to render their `<title>` are still processed, with a note that the page could not be read.\n- If the AI request fails for one page, its row is still written with a note, and the other pages continue.\n- An existing row is overwritten on the next run, including **Status**. Copy approved rows to another tab if you want to keep them.",
        "width": 640,
        "height": 1014
      }
    }
  ],
  "connections": {
    "Every Monday at 07:00": {
      "main": [
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Settings": {
      "main": [
        [
          {
            "node": "GSC Magic: quick wins",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GSC Magic: quick wins": {
      "main": [
        [
          {
            "node": "Group queries by page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Group queries by page": {
      "main": [
        [
          {
            "node": "Fetch the live page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch the live page": {
      "main": [
        [
          {
            "node": "Read current title and description",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read current title and description": {
      "main": [
        [
          {
            "node": "Draft title and description",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Draft title and description": {
      "main": [
        [
          {
            "node": "Prepare the sheet row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare the sheet row": {
      "main": [
        [
          {
            "node": "Add or update row in Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Draft title and description",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Title and description format": {
      "ai_outputParser": [
        [
          {
            "node": "Draft title and description",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "active": false
}
