Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions gatsby/onPreBootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,18 @@ posthog.init("${process.env.GATSBY_POSTHOG_API_KEY}", {
error_tracking: {
__capturePostHogExceptions: true,
},
// Drop exceptions coming from local dev servers so developers' local
// exceptions (e.g. Gatsby dev-server ChunkLoadErrors on hot recompiles)
// don't pollute production error tracking. Real users are never on localhost.
// Drop exceptions that no real visitor can hit, so they don't pollute
// production error tracking. Local dev servers (localhost/127.0.0.1) throw
// Gatsby ChunkLoadErrors on hot recompiles. A page saved to disk and opened
// over file:// boots Gatsby, finds no page-data for the local file path, and
// throws; its hostname is empty, so check the protocol too.
before_send: function (event) {
var hostname = window.location.hostname
if (event && event.event === '$exception' && (hostname === 'localhost' || hostname === '127.0.0.1')) {
if (
event &&
event.event === '$exception' &&
(hostname === 'localhost' || hostname === '127.0.0.1' || window.location.protocol === 'file:')
) {
return null
}
return event
Expand Down
Loading