如果有在經營網站內容,SEO優化這個詞應該都不陌生,主要就是透過改善網站架構、內容,讓使用者在搜尋相關的關鍵字時,能夠有更好的排名,進而增加流量。那網站文章關鍵字的表現狀況,就會使用 Google Search Console工具來分析。
隨著文章越來越多,所要分析的資料量就越大,那要如何有效找出表現良好的關鍵字,哪些文章能夠再優化,就非常重要,但每週登入Google Search Console逐頁查看資料,既耗時又容易漏掉重點。
這篇文章就來教你使用n8n自動化工具,實作Google Search Console報表自動化,定期撈取網站關鍵字、流量、排名、可優化的文章資料,彙整成報表後,寄到Gmail信箱,讓你每週都能快速掌握網站的優化方向。
一、Google Search Console報表自動化的運作流程
想實作Google Search Console報表自動化的流程,可以分為四個步驟:
- 設定排程,自動執行工作流程
- 撈取Google Search Console關鍵字數據
- 彙整Google Search Console數據
- 將Google Search Console報表寄送至電子郵件
二、n8n串接Google Search Console自動產製報表的解決方案
利用Schedule排程,每週定期撈取Google Search Console的前10名關鍵字,以及高曝光但低點擊的可優化文章資料,接著用程式碼進行彙整與計算,最後把完成的報表自動寄到Gmail電子郵件。
三、n8n串接Google Search Console自動產製報表的實作步驟
1.設定Schedule:排程每週執行一次
使用Schedule節點,設定排程每週執行一次自動化流程,設定如下:
2.設定HTTP Request:撈取Google Search Console資料
透過Google Search Console API,撈取網站的「熱門關鍵字」和「可優化文章」資料。
▍熱門關鍵字資料
Google Search Console熱門關鍵字API的部分,設定如下:
- URL:https://www.googleapis.com/webmasters/v3/sites/sc-domain%3A{你的網域網址}/searchAnalytics/query
- JSON資料:想要分析的開始日期、結束日期、維度(dimensions)為query、資料筆數
接下來,在Code節點中,彙整與排序關鍵字資料,如下:
const rows = $input.first().json.rows || []; //取得所有JSON資料 return rows .sort((a, b) => b.clicks - a.clicks) .slice(0, 10) .map(r => ({ json: { keyword: r.keys[0], clicks: r.clicks, impressions: r.impressions, ctr: (r.ctr * 100).toFixed(1) + '%', position: r.position.toFixed(1), //取小數點後1位 }, }));
▍可優化文章資料
而Google Search Console文章頁面API的部分,設定如下:
- URL:https://www.googleapis.com/webmasters/v3/sites/sc-domain%3A{你的網域網址}/searchAnalytics/query
- JSON資料:想要分析的開始日期、結束日期、維度(dimensions)為page、資料筆數
取得文章頁面資料之後,同樣用Code程式碼,篩選排名8~20名的文章資料,如下:
const rows = $input.first().json.rows || []; //取得所有JSON資料 //篩選排名8~20名的文章資料 return rows .filter(r => r.position >= 8 && r.position <= 20 && r.impressions >= 50) .sort((a, b) => b.impressions - a.impressions) .slice(0, 10) .map(r => ({ json: { page: r.keys[0], clicks: r.clicks, impressions: r.impressions, ctr: (r.ctr * 100).toFixed(1) + '%', position: r.position.toFixed(1), //取小數點後1位 }, }));
3.設定Merge:合併Google Search Console資料
合併彙整好的Google Search Console「熱門關鍵字」、「可優化文章」資料,設定如下:
4.設定Code:彙整Google Search Console資料
把合併後的Google Search Console資料整理成HTML表格資料,程式碼如下:
const keywords = $('熱門關鍵字Top10').all().map(i => i.json).filter(i => Object.keys(i).length > 0); const pages = $('可優化文章').all().map(i => i.json).filter(i => Object.keys(i).length > 0); // 避免 & < > " 等字元破壞版面 const esc = (s) => String(s) .replace(/&/g, '&') .replace(/</g, '<') .replace(/>/g, '>') .replace(/"/g, '"'); // page 欄位:連結保持完整網址,顯示文字移除網域 const renderCell = (col, item) => { if (col === 'page') { const label = item.page.replace('https://www.learncodewithmike.com', '') || '/'; return `<a href="${esc(item.page)}">${esc(label)}</a>`; } return esc(item[col]); }; const toRows = (items, columns) => { if (items.length === 0) { return `<tr><td colspan="${columns.length}">本週無資料</td></tr>`; } return items .map(item => { const cells = columns.map(col => `<td>${renderCell(col, item)}</td>`).join(''); return `<tr>${cells}</tr>`; }) .join('\n'); }; return [{ json: { keywordRows: toRows(keywords, ['keyword', 'clicks', 'impressions', 'ctr', 'position']), pageRows: toRows(pages, ['page', 'clicks', 'impressions', 'ctr', 'position']), }, }];
5.設定 Gmail:寄送Google Search Console報表
最後把Google Search Console報表資料,寄到Gmail電子郵件中,設定如下:
Message郵件內容如下:
<div style="font-family: Arial, 'Microsoft JhengHei', sans-serif; color: #333;"> <h2>Google Search Console 週報</h2> <h3>熱門搜尋關鍵字 Top 10</h3> <table border="1" cellpadding="6" cellspacing="0" style="border-collapse: collapse; font-size: 14px;"> <thead> <tr style="background: #f0f0f0;"> <th>關鍵字</th> <th>點擊</th> <th>曝光</th> <th>CTR</th> <th>平均排名</th> </tr> </thead> <tbody> {{ $json.keywordRows }} </tbody> </table> <h3>可優化文章(排名 8~20 名)</h3> <table border="1" cellpadding="6" cellspacing="0" style="border-collapse: collapse; font-size: 14px;"> <thead> <tr style="background: #f0f0f0;"> <th>頁面</th> <th>點擊</th> <th>曝光</th> <th>CTR</th> <th>平均排名</th> </tr> </thead> <tbody> {{ $json.pageRows }} </tbody> </table> </div>
四、成果總結
在進行SEO優化的過程中,關鍵字表現和文章排名可說是必看的數據。透過n8n串接Google Search Console API,自動彙整重要指標,讓你不用再手動登入後台、匯出資料、複製貼上,只要打開Gmail信箱,就能知道哪些關鍵字表現良好,哪些文章只要再優化一下,就有機會排上首頁。
所以,如果你也在經營網站內容,非常推薦你使用n8n建置Google Search Console報表自動化,提升你的SEO優化效率。











留言
張貼留言