From bc9a8146acaff53b586e2ff6d7732b227c92ec92 Mon Sep 17 00:00:00 2001 From: Claire Chabas Date: Mon, 13 Jan 2025 18:43:12 +0100 Subject: [PATCH] test reverting something --- .../components/Insights/InsightsProvider.tsx | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/gitbook/src/components/Insights/InsightsProvider.tsx b/packages/gitbook/src/components/Insights/InsightsProvider.tsx index 2e65ab8c5..66e956a17 100644 --- a/packages/gitbook/src/components/Insights/InsightsProvider.tsx +++ b/packages/gitbook/src/components/Insights/InsightsProvider.tsx @@ -192,14 +192,31 @@ export function InsightsProvider(props: InsightsProviderProps) { React.useEffect(() => { getVisitorId().then((visitorId) => { visitorIdRef.current = visitorId; - // When the page is unloaded, flush all events, but only if the visitor ID is set - window.addEventListener('beforeunload', flushEventsSync); }); + }, []); + + // When the page is unloaded, flush all events + React.useEffect(() => { + window.addEventListener('beforeunload', flushEventsSync); return () => { window.removeEventListener('beforeunload', flushEventsSync); }; }, [flushEventsSync]); + /** + * Get the visitor ID and store it in a ref. + */ + // React.useEffect(() => { + // getVisitorId().then((visitorId) => { + // visitorIdRef.current = visitorId; + // // When the page is unloaded, flush all events, but only if the visitor ID is set + // window.addEventListener('beforeunload', flushEventsSync); + // }); + // return () => { + // window.removeEventListener('beforeunload', flushEventsSync); + // }; + // }, [flushEventsSync]); + return (