From 5e12c0a9be2f521c0866fa19633b8fc2befe802d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Tue, 27 Feb 2024 16:27:09 +0100 Subject: [PATCH] Ignore errors when tracking page views (#193) --- src/components/PageBody/TrackPageView.tsx | 18 +++++++++++------- src/lib/analytics.ts | 1 + 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/components/PageBody/TrackPageView.tsx b/src/components/PageBody/TrackPageView.tsx index f9302b743..dec39cce3 100644 --- a/src/components/PageBody/TrackPageView.tsx +++ b/src/components/PageBody/TrackPageView.tsx @@ -54,11 +54,15 @@ async function trackPageView(apiHost: string, spaceId: string, pageId: string | const url = new URL(apiHost); url.pathname = `/v1/spaces/${spaceId}/insights/track_view`; - await fetch(url, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(body), - }); + try { + await fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(body), + }); + } catch (error) { + console.error('Failed to track page view', error); + } } diff --git a/src/lib/analytics.ts b/src/lib/analytics.ts index fcf4898fc..35ec38cc4 100644 --- a/src/lib/analytics.ts +++ b/src/lib/analytics.ts @@ -59,6 +59,7 @@ async function fetchVisitorID(): Promise { const { deviceId } = (await resp.json()) as { deviceId: string }; return deviceId; } catch (error) { + console.error('Failed to fetch visitor session ID', error); return proposed; } }