Error Sessions Analysis (JavaScript Errors)
Error sessions are user sessions with one or more JavaScript errors. JS errors break interface functionality, block forms and checkout, directly reducing conversion.
JavaScript Error Capture Setup
// Capture unhandled errors
window.addEventListener('error', function(event) {
const errorInfo = {
message: event.message,
source: event.filename?.split('/').pop(),
line: event.lineno,
col: event.colno,
stack: event.error?.stack?.slice(0, 500),
page: window.location.pathname,
user_agent: navigator.userAgent.slice(0, 100)
}
// Send to GA4
gtag('event', 'js_error', errorInfo)
// Send to Sentry/Bugsnag
Sentry.captureException(event.error, {
extra: errorInfo
})
})
// Capture unhandled Promise rejections
window.addEventListener('unhandledrejection', function(event) {
gtag('event', 'promise_rejection', {
message: event.reason?.message || String(event.reason),
page: window.location.pathname
})
})
// Capture fetch/XHR errors
const originalFetch = window.fetch
window.fetch = async function(...args) {
try {
const response = await originalFetch(...args)
if (!response.ok) {
gtag('event', 'fetch_error', {
url: args[0].toString().split('?')[0],
status: response.status,
page: window.location.pathname
})
}
return response
} catch (err) {
gtag('event', 'fetch_exception', {
url: args[0].toString().split('?')[0],
message: err.message
})
throw err
}
}
Sentry: Full Error Tracking
// sentry.init.js
import * as Sentry from '@sentry/browser'
import { BrowserTracing } from '@sentry/tracing'
Sentry.init({
dsn: 'https://[email protected]/yyy',
integrations: [
new BrowserTracing(),
new Sentry.Replay({
maskAllText: false,
blockAllMedia: false
})
],
tracesSampleRate: 0.1, // 10% for performance
replaysSessionSampleRate: 0.05, // 5% of sessions
replaysOnErrorSampleRate: 1.0, // 100% on error
})
Analyzing Error Impact
Compare conversion rates for sessions with/without errors:
- Sessions with errors typically have 30-50% lower conversion
- Checkout errors have highest impact on revenue
- Navigation/menu errors reduce time on site
Delivery Time
Setting up error capture and analysis — 1 business day.







