404 頁面是用戶流失高峰,也是內容缺口與斷鏈的線索庫。GA 只需微調追蹤代碼,即可將 404 納入常規報表分析。
gtag.js 或 analytics.js)。<script>
// gtag.js (GA4 / Universal Analytics)
gtag('config', 'GA_MEASUREMENT_ID', {
'page_path': '/404.html',
'page_title': '404 - Page Not Found',
'page_location': window.location.href
});
</script>
舊版 analytics.js:
ga('send', 'pageview', {
'page': '/404.html?url=' + encodeURIComponent(window.location.href) + '&ref=' + encodeURIComponent(document.referrer),
'title': '404 - Page Not Found'
});
/404.html:查看 404 發生次數趨勢。gtag('event', '404_error', {
'page_path': location.pathname + location.search,
'referrer': document.referrer,
'user_agent': navigator.userAgent
});
事件不計入頁面瀏覽量,不干擾跳出率、頁面價值等指標,適合高流量站點。