{
  "name": "New client SEO audit from a form: quick wins, cannibalization, indexing and Core Web Vitals by email (GSC Magic)",
  "nodes": [
    {
      "id": "002c7ac9-9bd9-4c9d-a4d7-a2caa00aaafb",
      "name": "Audit request form",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [
        0,
        0
      ],
      "webhookId": "gsc-magic-new-client-audit",
      "parameters": {
        "formTitle": "New client SEO audit",
        "formDescription": "Runs a first-look audit from the client's Search Console data and emails it to you. The site must already be in Search Console with your Google account as a user.",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Client name",
              "placeholder": "Acme Inc.",
              "requiredField": true
            },
            {
              "fieldLabel": "Website",
              "placeholder": "acme.com or sc-domain:acme.com",
              "requiredField": true
            },
            {
              "fieldLabel": "Send the audit to",
              "fieldType": "email",
              "placeholder": "you@your-agency.com",
              "requiredField": true
            },
            {
              "fieldLabel": "Check Core Web Vitals",
              "fieldType": "dropdown",
              "fieldOptions": {
                "values": [
                  {
                    "option": "Yes"
                  },
                  {
                    "option": "No"
                  }
                ]
              },
              "requiredField": true
            }
          ]
        },
        "responseMode": "onReceived",
        "options": {
          "respondWithOptions": {
            "values": {
              "respondWith": "text",
              "formSubmittedText": "Thanks. The audit is running and will arrive by email in a few minutes."
            }
          }
        }
      }
    },
    {
      "id": "bf0fcfcf-0cc2-4481-a551-a2b202954893",
      "name": "Settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        308,
        0
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "87522bf4-5ad7-4822-a266-003b2ba4c371",
              "name": "agencyName",
              "value": "Your Agency",
              "type": "string"
            },
            {
              "id": "4741b06c-2724-4cfb-a5cb-41516c4dcde0",
              "name": "senderEmail",
              "value": "audits@your-agency.com",
              "type": "string"
            },
            {
              "id": "c6018049-0d8a-4962-ae8b-b0d11c55a16b",
              "name": "brandColor",
              "value": "#2563eb",
              "type": "string"
            },
            {
              "id": "7251549c-3c5a-41ba-aab7-826492a3f220",
              "name": "inspectUrls",
              "value": 10,
              "type": "number"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "fdca05d5-908c-41fe-a79f-1189441cdc6e",
      "name": "Read the form",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        616,
        0
      ],
      "parameters": {
        "jsCode": "const f = $('Audit request form').first().json;\nconst raw = String(f['Website'] || '').trim();\nconst host = raw.toLowerCase().replace(/^sc-domain:/, '').replace(/^https?:\\/\\//, '').replace(/\\/.*$/, '');\nif (!host || !/^[a-z0-9.-]+\\.[a-z]{2,}$/.test(host)) throw new Error('Website must be a domain like acme.com, got: ' + raw);\nreturn [{ json: {\n  client: String(f['Client name'] || host).trim(),\n  site: raw.startsWith('sc-domain:') || /^https?:/.test(raw) ? raw : host,\n  host,\n  origin: 'https://' + host,\n  to: String(f['Send the audit to']).trim(),\n  checkCwv: f['Check Core Web Vitals'] !== 'No',\n} }];\n"
      }
    },
    {
      "id": "351118ce-8adb-4555-ac80-152061cd6542",
      "name": "GSC Magic: quick wins",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        924,
        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: 50, limit: 10 } } }) }}",
        "options": {
          "batching": {
            "batch": {
              "batchSize": 1,
              "batchInterval": 300
            }
          },
          "timeout": 180000
        }
      }
    },
    {
      "id": "c2bb9550-2b93-4a0e-a7d4-0941ced4f874",
      "name": "Site found in Search Console?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1232,
        0
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "37074ee3-7dfe-4124-a0a1-cf18563c974c",
              "leftValue": "={{ !($json.result && $json.result.isError && /No Search Console property/i.test(JSON.stringify($json.result.content))) }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "b9ef43e2-a484-4d24-a2b5-af9f365db47e",
      "name": "GSC Magic: cannibalization",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1540,
        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_cannibalization', arguments: { site: $('Read the form').first().json.site, range: 'last_28_days', limit: 10 } } }) }}",
        "options": {
          "batching": {
            "batch": {
              "batchSize": 1,
              "batchInterval": 300
            }
          },
          "timeout": 180000
        }
      }
    },
    {
      "id": "aef3c766-0cb7-43f9-a214-02bf2e550dbf",
      "name": "GSC Magic: index health",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1848,
        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_index_health', arguments: { site: $('Read the form').first().json.site, max_urls: Math.min(20, Math.max(1, Number($('Settings').first().json.inspectUrls) || 10)) } } }) }}",
        "options": {
          "batching": {
            "batch": {
              "batchSize": 1,
              "batchInterval": 300
            }
          },
          "timeout": 180000
        }
      }
    },
    {
      "id": "a7df360b-a0a0-4d8a-a3bc-f2e675923947",
      "name": "Core Web Vitals wanted?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        2156,
        0
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "7681cada-49c7-436b-a7e1-2a3f69e3ef5a",
              "leftValue": "={{ $('Read the form').first().json.checkCwv }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "7cb1aa35-7ee7-4443-aa60-17f629b6fc8a",
      "name": "GSC Magic: Core Web Vitals",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        2464,
        -120
      ],
      "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: 'cwv_get_origin', arguments: { origin: $('Read the form').first().json.origin, form_factor: 'PHONE' } } }) }}",
        "options": {
          "batching": {
            "batch": {
              "batchSize": 1,
              "batchInterval": 300
            }
          },
          "timeout": 180000
        }
      }
    },
    {
      "id": "d54455db-0ff1-4f9b-a607-729c27e60365",
      "name": "Write the audit",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2772,
        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\n// ---- email kit: layout and components (inline styles, works in Gmail, Outlook, Apple Mail) ----\nconst K = { ink: '#111827', muted: '#6b7280', faint: '#9ca3af', line: '#e5e7eb', bg: '#f3f4f6', soft: '#f9fafb',\n  good: '#166534', goodBg: '#dcfce7', bad: '#b91c1c', badBg: '#fee2e2', warn: '#92400e', warnBg: '#fef3c7', info: '#1e40af', infoBg: '#dbeafe' };\nconst FONT = \"-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif\";\nconst esc = (s) => String(s ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\"/g, '&quot;');\nconst fmt = (n) => (n === null || n === undefined || Number.isNaN(Number(n)) ? '-' : Number(n).toLocaleString('en-US'));\nconst urlPath = (u) => String(u).replace(/^https?:\\/\\/[^/]+/i, '') || '/';\nconst short = (s, n) => (String(s).length > n ? String(s).slice(0, n - 1) + '...' : String(s));\nfunction pill(text, tone) {\n  const c = { good: [K.good, K.goodBg], bad: [K.bad, K.badBg], warn: [K.warn, K.warnBg], info: [K.info, K.infoBg] }[tone] || [K.muted, K.bg];\n  return '<span style=\"display:inline-block;padding:2px 8px;border-radius:999px;background:' + c[1] + ';color:' + c[0] + ';font-size:12px;font-weight:700;line-height:18px;white-space:nowrap;\">' + esc(text) + '</span>';\n}\nfunction change(now, before, goodWhenUp = true) {\n  if (!before) return now ? pill('new', 'info') : '';\n  const d = Math.round(((now - before) / before) * 100);\n  if (d === 0) return pill('0%', 'neutral');\n  return pill((d > 0 ? '+' : '') + d + '%', (d > 0) === goodWhenUp ? 'good' : 'bad');\n}\nfunction link(url, text, accent) {\n  return '<a href=\"' + esc(url) + '\" style=\"color:' + accent + ';text-decoration:none;font-weight:600;\">' + esc(text) + '</a>';\n}\nfunction kpis(items) {\n  const w = Math.floor(100 / items.length);\n  return '<table role=\"presentation\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse:separate;border-spacing:8px 0;margin:4px -8px 0;\"><tr>'\n    + items.map((k) => '<td width=\"' + w + '%\" valign=\"top\" style=\"background:' + K.soft + ';border:1px solid ' + K.line + ';border-radius:10px;padding:14px 12px;\">'\n      + '<div style=\"font-size:11px;letter-spacing:.06em;text-transform:uppercase;color:' + K.muted + ';font-weight:700;\">' + esc(k.label) + '</div>'\n      + '<div style=\"font-size:22px;font-weight:800;margin:4px 0 6px;color:' + K.ink + ';\">' + esc(k.value) + '</div>'\n      + '<div style=\"min-height:20px;\">' + (k.badge || '') + '</div></td>').join('')\n    + '</tr></table>';\n}\nfunction section(title, body, note) {\n  return '<div style=\"margin:30px 0 0;\"><div style=\"font-size:17px;font-weight:800;color:' + K.ink + ';margin:0 0 4px;\">' + esc(title) + '</div>'\n    + (note ? '<div style=\"font-size:13px;color:' + K.muted + ';margin:0 0 12px;\">' + note + '</div>' : '<div style=\"height:8px\"></div>') + body + '</div>';\n}\nfunction table(cols, rows) {\n  const th = cols.map((c) => '<td align=\"' + (c.align || 'left') + '\" style=\"padding:8px 10px;font-size:11px;letter-spacing:.05em;text-transform:uppercase;color:' + K.muted + ';font-weight:700;border-bottom:1px solid ' + K.line + ';\">' + esc(c.label) + '</td>').join('');\n  const tr = rows.map((r) => '<tr>' + r.map((cell, i) => '<td align=\"' + (cols[i].align || 'left') + '\" valign=\"top\" style=\"padding:10px;font-size:14px;border-bottom:1px solid ' + K.line + ';\">' + cell + '</td>').join('') + '</tr>').join('');\n  return '<table role=\"presentation\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse:collapse;\"><tr>' + th + '</tr>' + tr + '</table>';\n}\nfunction bar(share, accent) {\n  const p = Math.max(2, Math.min(100, Math.round(share * 100)));\n  return '<table role=\"presentation\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse:collapse;\"><tr>'\n    + '<td width=\"' + p + '%\" style=\"background:' + accent + ';height:6px;line-height:6px;font-size:0;border-radius:3px;\">&nbsp;</td>'\n    + (p < 100 ? '<td style=\"background:' + K.line + ';height:6px;line-height:6px;font-size:0;border-radius:3px;\">&nbsp;</td>' : '') + '</tr></table>';\n}\nfunction callout(html, tone) {\n  const c = { good: [K.good, K.goodBg], bad: [K.bad, K.badBg], warn: [K.warn, K.warnBg] }[tone] || [K.info, K.infoBg];\n  return '<div style=\"background:' + c[1] + ';border-left:4px solid ' + c[0] + ';border-radius:8px;padding:14px 16px;margin:18px 0 0;font-size:14px;color:' + K.ink + ';\">' + html + '</div>';\n}\nfunction bullets(items) {\n  return '<table role=\"presentation\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse:collapse;\">' + items.map((t) => '<tr><td valign=\"top\" style=\"padding:3px 8px 3px 0;color:' + K.muted + ';\">&#9679;</td><td style=\"padding:3px 0;font-size:14px;\">' + t + '</td></tr>').join('') + '</table>';\n}\nfunction numbered(items) {\n  return '<table role=\"presentation\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse:collapse;\">' + items.map((t, i) => '<tr><td valign=\"top\" style=\"padding:4px 10px 4px 0;\"><span style=\"display:inline-block;width:22px;height:22px;line-height:22px;border-radius:11px;background:' + K.bg + ';color:' + K.ink + ';font-size:12px;font-weight:800;text-align:center;\">' + (i + 1) + '</span></td><td style=\"padding:5px 0;font-size:14px;\">' + t + '</td></tr>').join('') + '</table>';\n}\nfunction emailLayout(o) {\n  const a = o.accent || '#2563eb';\n  return '<!doctype html><html><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><meta name=\"color-scheme\" content=\"light\"></head>'\n    + '<body style=\"margin:0;padding:0;background:' + K.bg + ';\">'\n    + '<div style=\"display:none;max-height:0;overflow:hidden;opacity:0;\">' + esc(o.preheader || '') + '</div>'\n    + '<table role=\"presentation\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"background:' + K.bg + ';\"><tr><td align=\"center\" style=\"padding:28px 12px;\">'\n    + '<table role=\"presentation\" width=\"600\" cellpadding=\"0\" cellspacing=\"0\" style=\"width:100%;max-width:600px;background:#ffffff;border:1px solid ' + K.line + ';border-radius:14px;font-family:' + FONT + ';color:' + K.ink + ';\">'\n    + '<tr><td style=\"background:' + a + ';height:6px;line-height:6px;font-size:0;border-radius:14px 14px 0 0;\">&nbsp;</td></tr>'\n    + '<tr><td style=\"padding:26px 28px 6px;\">'\n    + '<div style=\"font-size:12px;letter-spacing:.08em;text-transform:uppercase;color:' + a + ';font-weight:800;\">' + esc(o.eyebrow || '') + '</div>'\n    + '<div style=\"font-size:24px;line-height:1.25;font-weight:800;margin:6px 0 4px;\">' + esc(o.title) + '</div>'\n    + (o.subtitle ? '<div style=\"font-size:14px;color:' + K.muted + ';\">' + esc(o.subtitle) + '</div>' : '')\n    + '</td></tr>'\n    + '<tr><td style=\"padding:10px 28px 28px;font-size:15px;line-height:1.55;\">' + o.body + '</td></tr>'\n    + '<tr><td style=\"padding:16px 28px 20px;border-top:1px solid ' + K.line + ';font-size:12px;line-height:1.5;color:' + K.muted + ';\">' + (o.footer || '') + '</td></tr>'\n    + '</table></td></tr></table></body></html>';\n}\n// ---- end of email kit ----\n\nconst cfg = $('Settings').first().json;\nconst f = $('Read the form').first().json;\nconst accent = /^#[0-9a-f]{6}$/i.test(String(cfg.brandColor)) ? cfg.brandColor : '#2563eb';\nconst read = (name) => ($(name).isExecuted ? unwrap($(name).first().json) : null);\nconst winsRes = unwrap($('GSC Magic: quick wins').first().json);\nconst canRes = read('GSC Magic: cannibalization');\nconst idxRes = read('GSC Magic: index health');\nconst cwvRes = read('GSC Magic: Core Web Vitals');\nconst today = new Date().toLocaleDateString('en-GB', { day: 'numeric', month: 'long', year: 'numeric' });\nconst footer = 'Prepared by ' + esc(cfg.agencyName) + ' on ' + today + '. Data: Google Search Console (last 28 days), URL Inspection API and the Chrome UX Report, through GSC Magic.';\n\n// No Search Console access yet: one clear email instead of a broken audit.\nif (!canRes) {\n  const html = emailLayout({\n    accent, eyebrow: cfg.agencyName, title: 'Audit not run yet', subtitle: f.client + ' (' + f.host + ')',\n    preheader: 'Search Console access is missing for ' + f.host,\n    body: callout('<b>No Search Console access for ' + esc(f.host) + '.</b><br>GSC Magic answered: ' + esc(winsRes.error), 'warn')\n      + section('How to fix it', numbered([\n        'Ask ' + esc(f.client) + ' to open Search Console and pick the property for ' + esc(f.host) + '.',\n        'Go to <b>Settings &gt; Users and permissions &gt; Add user</b>.',\n        'Add the Google account you connected to GSC Magic as a <b>Full</b> user.',\n        'Submit the audit form again.',\n      ])),\n    footer: 'Prepared by ' + esc(cfg.agencyName) + ' on ' + today + '.',\n  });\n  return [{ json: { subject: 'Audit not run: no Search Console access for ' + f.host, html } }];\n}\n\nconst failed = (res) => res && !res.ok;\nconst failNote = (res) => callout('Could not load this part: ' + esc(res.error), 'bad');\n\n// Quick wins\nconst winRows = winsRes.ok ? winsRes.data.rows || [] : [];\nconst extra = winRows.reduce((s, r) => s + r.potential_extra_clicks, 0);\nconst winsHtml = section('Quick wins', winsRes.ok && !winRows.length ? 'No query ranks between positions 4 and 20 with 50+ impressions in the last 28 days.'\n  : failed(winsRes) ? failNote(winsRes)\n  : table(\n    [{ label: 'Query' }, { label: 'Page' }, { label: 'Position', align: 'right' }, { label: 'Impr.', align: 'right' }, { label: 'Gain', align: 'right' }],\n    winRows.map((r) => [esc(r.query), link(r.page, short(urlPath(r.page), 34), accent), String(r.position), fmt(r.impressions), pill('+' + r.potential_extra_clicks, 'good')]),\n  ), 'Rankings at positions 4 to 20. Gain = extra clicks a month at position 3.');\n\n// Cannibalization\nconst canRows = canRes.ok ? canRes.data.rows || [] : [];\nconst canCount = canRes.ok ? (canRes.data.found ?? canRows.length) : 0;\nconst canHtml = section('Queries split between several pages', failed(canRes) ? failNote(canRes) : !canRows.length ? 'No query sends a meaningful share of impressions to two or more pages.'\n  : canRows.slice(0, 8).map((r) => '<div style=\"border:1px solid ' + K.line + ';border-radius:10px;padding:12px 14px;margin:0 0 10px;\">'\n    + '<div style=\"font-weight:700;margin:0 0 8px;\">' + esc(r.query) + ' <span style=\"color:' + K.muted + ';font-weight:400;font-size:13px;\">' + fmt(r.total_impressions) + ' impressions</span></div>'\n    + r.pages.map((p) => '<table role=\"presentation\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse:collapse;margin:0 0 6px;\"><tr>'\n      + '<td style=\"font-size:13px;padding:0 10px 2px 0;\">' + link(p.page, short(urlPath(p.page), 48), accent) + '</td>'\n      + '<td width=\"44\" align=\"right\" style=\"font-size:13px;font-weight:700;padding:0 0 2px;\">' + Math.round(p.share * 100) + '%</td></tr>'\n      + '<tr><td colspan=\"2\">' + bar(p.share, accent) + '</td></tr></table>').join('')\n    + '</div>').join('') + (canRows.length > 8 ? '<div style=\"color:' + K.muted + ';font-size:13px;\">and ' + (canRows.length - 8) + ' more</div>' : ''),\n  'Several pages share the impressions for the same query, so none of them ranks as well as one strong page could.');\n\n// Indexing\nlet notIndexed = null;\nlet idxHtml;\nif (failed(idxRes)) idxHtml = section('Indexing', failNote(idxRes));\nelse {\n  const d = idxRes.data;\n  const bad = d.not_indexed || [];\n  notIndexed = { bad: bad.length, total: d.urls_checked || 0 };\n  idxHtml = section('Indexing', !d.urls_checked ? 'No sitemap URLs could be read. Submit a sitemap in Search Console.'\n    : '<div style=\"margin:0 0 10px;\">' + Object.entries(d.coverage || {}).map(([k, v]) => pill(v + ' ' + k, /indexed/i.test(k) && !/not indexed/i.test(k) ? 'good' : 'warn')).join(' ') + '</div>'\n      + (bad.length ? table([{ label: 'Not indexed' }, { label: 'Google says' }], bad.slice(0, 20).map((u) => [link(u.url, short(urlPath(u.url), 40), accent), esc(u.coverageState || '')])) : ''),\n    'A sample of the first ' + (d.urls_checked || 0) + ' URLs from ' + esc((d.sitemaps || []).join(', ')) + ', checked one by one with Google\\'s URL Inspection API.');\n}\n\n// Core Web Vitals\nlet cwvBadge = pill('not checked', 'neutral');\nlet cwvValue = '-';\nlet cwvHtml = '';\nif (cwvRes) {\n  if (failed(cwvRes)) {\n    const noData = /no data|not found|404/i.test(cwvRes.error);\n    cwvBadge = pill(noData ? 'no data' : 'failed', 'neutral');\n    cwvValue = noData ? 'No data' : '-';\n    cwvHtml = section('Core Web Vitals on phones', noData ? 'The Chrome UX Report has too little real-user traffic for this site yet.' : failNote(cwvRes));\n  } else {\n    const m = cwvRes.data.metrics || {};\n    const LIMITS = [['largest_contentful_paint', 'LCP', 'Loading', 2500, 4000, ' ms'], ['interaction_to_next_paint', 'INP', 'Responsiveness', 200, 500, ' ms'], ['cumulative_layout_shift', 'CLS', 'Visual stability', 0.1, 0.25, '']];\n    let worst = 'good';\n    const rows = LIMITS.map(([key, label, what, good, poor, unit]) => {\n      if (!m[key]) return [esc(label), esc(what), '-', pill('no data', 'neutral')];\n      const v = Number(m[key].p75);\n      const rating = v <= good ? 'good' : v <= poor ? 'needs work' : 'poor';\n      if (rating === 'poor' || (rating === 'needs work' && worst === 'good')) worst = rating;\n      return [esc(label), esc(what), fmt(v) + unit, pill(rating, rating === 'good' ? 'good' : rating === 'poor' ? 'bad' : 'warn')];\n    });\n    cwvBadge = pill('on phones', 'info');\n    cwvValue = worst === 'good' ? 'Good' : worst === 'poor' ? 'Poor' : 'Needs work';\n    cwvHtml = section('Core Web Vitals on phones', table([{ label: 'Metric' }, { label: 'What it measures' }, { label: 'p75', align: 'right' }, { label: 'Rating', align: 'right' }], rows),\n      'Real Chrome users over the last 28 days (75th percentile). Good means LCP under 2.5 s, INP under 200 ms and CLS under 0.1.');\n  }\n}\n\n// Summary\nconst tiles = kpis([\n  { label: 'Extra clicks', value: winsRes.ok ? '+' + fmt(extra) : '-', badge: pill('a month', 'info') },\n  { label: 'Split queries', value: canRes.ok ? fmt(canCount) : '-', badge: canCount ? pill('to fix', 'warn') : pill('none', 'good') },\n  { label: 'Not indexed', value: notIndexed ? notIndexed.bad + ' of ' + notIndexed.total : '-', badge: notIndexed && notIndexed.bad ? pill('check', 'warn') : pill('ok', 'good') },\n  { label: 'Page speed', value: cwvValue, badge: cwvBadge },\n]);\nconst todo = [];\nif (winRows.length) todo.push('Improve <b>' + esc(winRows[0].query) + '</b> on ' + link(winRows[0].page, urlPath(winRows[0].page), accent) + ': about ' + winRows[0].potential_extra_clicks + ' more clicks a month at position 3.');\nif (canRows.length) todo.push('Pick one page for <b>' + esc(canRows[0].query) + '</b> and point the others to it.');\nif (notIndexed && notIndexed.bad) todo.push('Find out why ' + notIndexed.bad + ' sitemap URL' + (notIndexed.bad === 1 ? ' is' : 's are') + ' not indexed (internal links, thin content, canonicals).');\n\nconst html = emailLayout({\n  accent, eyebrow: cfg.agencyName, title: 'SEO audit: ' + f.client, subtitle: f.host + ' - last 28 days - ' + today,\n  preheader: (winsRes.ok ? '+' + extra + ' clicks a month in quick wins, ' : '') + canCount + ' split queries' + (notIndexed ? ', ' + notIndexed.bad + ' of ' + notIndexed.total + ' URLs not indexed' : ''),\n  body: tiles + (todo.length ? callout('<div style=\"font-weight:800;margin:0 0 6px;\">Start here</div>' + bullets(todo), 'info') : '')\n    + winsHtml + canHtml + idxHtml + cwvHtml,\n  footer,\n});\n\nreturn [{ json: { subject: 'SEO audit: ' + f.client + ' (' + f.host + ')', html } }];\n"
      }
    },
    {
      "id": "e05a8d17-1497-4957-af80-43b75cfddc07",
      "name": "Send the audit",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        3080,
        0
      ],
      "parameters": {
        "fromEmail": "={{ $('Settings').first().json.senderEmail }}",
        "toEmail": "={{ $('Read the form').first().json.to }}",
        "subject": "={{ $json.subject }}",
        "emailFormat": "html",
        "html": "={{ $json.html }}",
        "options": {
          "appendAttribution": false
        }
      }
    },
    {
      "id": "591a19ae-7be1-411b-aaa1-6a5a8371cd6d",
      "name": "Step 1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -327
      ],
      "parameters": {
        "content": "## Step 1: Configure and open the form\n- **agencyName**: shown in the email.\n- **senderEmail**: the From address.\n- **brandColor**: your accent color as a hex code, e.g. `#2563eb`. Used for the top bar, links and charts.\n- **inspectUrls**: how many sitemap URLs to check for indexing, 1 to 20. Google checks them one by one (about 7 seconds each), so 10 takes about a minute and 20 about two and a half.",
        "width": 796,
        "height": 517,
        "color": 7
      }
    },
    {
      "id": "5133c6a3-8746-41d0-acbf-b2c30ebb9a16",
      "name": "Step 2",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        884,
        -327
      ],
      "parameters": {
        "content": "## Step 2: Check access\nThe first report also tells whether Search Console has this site. If not, the rest is skipped and you get an email on how the client adds you.",
        "width": 488,
        "height": 517,
        "color": 7
      }
    },
    {
      "id": "c52fad99-2880-43c4-ab6e-61359b94fbfa",
      "name": "Step 3",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1500,
        -327
      ],
      "parameters": {
        "content": "## Step 3: Run the audit\nQueries split between pages, indexing of sitemap URLs and, if asked, Core Web Vitals on phones.",
        "width": 1104,
        "height": 517,
        "color": 7
      }
    },
    {
      "id": "cb7e7c10-e2f0-42b1-aad2-b6b4d96191b4",
      "name": "Step 4",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        2732,
        -327
      ],
      "parameters": {
        "content": "## Step 4: Email the audit\nOne HTML audit with a short summary at the top.",
        "width": 488,
        "height": 517,
        "color": 7
      }
    },
    {
      "id": "e04ee60f-69b4-4258-a0fd-3223f81464db",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -740,
        -327
      ],
      "parameters": {
        "content": "## New client SEO audit from a form\nWhen a new client gives you access to their Search Console, fill in a short n8n form. A few minutes later you get a first-look audit by email, built from the client's own Google data: where the quick wins are, which queries are split between several pages, which sitemap URLs Google has not indexed, and how real users experience the site's speed.\n\n**Who it is for:** agencies and consultants preparing a kickoff call or a proposal.\n\n**How it works**\n1. The form takes the client name, the site and who should get the report.\n2. Four GSC Magic reports run: quick wins, cannibalization, index health (sitemap URLs through URL Inspection) and, if asked, Core Web Vitals from the Chrome UX Report.\n3. If Search Console has no property for that site yet, the email says so and explains how the client adds you as a user.\n4. Otherwise you get one HTML audit with a short summary at the top.\n\n**Before using it:** the client must add the Google account you connected to GSC Magic as a user of their Search Console property.\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**, add an SMTP credential to both email nodes, activate.\n5. Open the production URL of **Audit request form** and submit a site you manage.\n\n**Calls per audit:** 4, or 3 without Core Web Vitals. Index health also uses `inspectUrls` URL Inspection requests (Google allows 2,000 a day per property).\n\n### Errors and limits\n- No Search Console access for the site: the other reports are skipped (no calls spent) and you get one email explaining how the client adds you.\n- Any single report that fails shows its reason in its own section; the rest of the audit still goes out.\n- Index health reads URLs from the sitemaps submitted in Search Console, so a site without a submitted sitemap shows no indexing data.\n- Indexing is a sample: at most 20 URLs, because Google inspects one URL at a time (about 7 seconds each) and a GSC Magic request is cut after 3 minutes. For a full check of new pages use the indexing watchdog template.\n- Each form submission runs the audit again and spends the calls again.",
        "width": 640,
        "height": 951
      }
    }
  ],
  "connections": {
    "Audit request form": {
      "main": [
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Settings": {
      "main": [
        [
          {
            "node": "Read the form",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read the form": {
      "main": [
        [
          {
            "node": "GSC Magic: quick wins",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GSC Magic: quick wins": {
      "main": [
        [
          {
            "node": "Site found in Search Console?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Site found in Search Console?": {
      "main": [
        [
          {
            "node": "GSC Magic: cannibalization",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Write the audit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GSC Magic: cannibalization": {
      "main": [
        [
          {
            "node": "GSC Magic: index health",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GSC Magic: index health": {
      "main": [
        [
          {
            "node": "Core Web Vitals wanted?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Core Web Vitals wanted?": {
      "main": [
        [
          {
            "node": "GSC Magic: Core Web Vitals",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Write the audit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GSC Magic: Core Web Vitals": {
      "main": [
        [
          {
            "node": "Write the audit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write the audit": {
      "main": [
        [
          {
            "node": "Send the audit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "active": false
}
