From d499720a229e4202ef29c33c2cd5241f3830a54b Mon Sep 17 00:00:00 2001 From: Mohamed Khelif Date: Fri, 21 Jun 2024 18:37:08 -0400 Subject: [PATCH] DEVPROD-8345 Remove tab active/not active events (#196) --- .../activity/useActivityAnalytics.ts | 7 ----- apps/spruce/src/analytics/index.ts | 1 - apps/spruce/src/components/Header/index.tsx | 29 +++++++------------ apps/spruce/src/hooks/useNetworkStatus.ts | 19 +----------- apps/spruce/src/hooks/usePageVisibility.ts | 25 +--------------- 5 files changed, 13 insertions(+), 68 deletions(-) delete mode 100644 apps/spruce/src/analytics/activity/useActivityAnalytics.ts diff --git a/apps/spruce/src/analytics/activity/useActivityAnalytics.ts b/apps/spruce/src/analytics/activity/useActivityAnalytics.ts deleted file mode 100644 index 61ec32b6e..000000000 --- a/apps/spruce/src/analytics/activity/useActivityAnalytics.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { useAnalyticsRoot } from "analytics/useAnalyticsRoot"; - -type Action = - | { name: "Tab Active"; status: "online" | "visible" } - | { name: "Tab Not Active" }; - -export const useActivityAnalytics = () => useAnalyticsRoot("Polling"); diff --git a/apps/spruce/src/analytics/index.ts b/apps/spruce/src/analytics/index.ts index ce6664fc8..9756daad1 100644 --- a/apps/spruce/src/analytics/index.ts +++ b/apps/spruce/src/analytics/index.ts @@ -1,4 +1,3 @@ -export { useActivityAnalytics } from "./activity/useActivityAnalytics"; export { useAnalyticsAttributes } from "./useAnalyticsAttributes"; export { useAnnotationAnalytics } from "./task/useAnnotationAnalytics"; export { useBreadcrumbAnalytics } from "./breadcrumb/useBreadcrumbAnalytics"; diff --git a/apps/spruce/src/components/Header/index.tsx b/apps/spruce/src/components/Header/index.tsx index 50a0c6515..0e1e05e34 100644 --- a/apps/spruce/src/components/Header/index.tsx +++ b/apps/spruce/src/components/Header/index.tsx @@ -5,26 +5,19 @@ import { SlackNotificationBanner, GithubUsernameBanner, } from "components/Banners"; -import { useNetworkStatus, usePageVisibility } from "hooks"; import { Navbar } from "./Navbar"; -// Since the Header is present on all Spruce pages, we can monitor network status and page visibility -// for the entire app here. -export const Header: React.FC = () => { - usePageVisibility(true); - useNetworkStatus(true); - return ( - - - - - ); -}; +export const Header: React.FC = () => ( + + + + +); const StyledHeader = styled.header` grid-area: header; diff --git a/apps/spruce/src/hooks/useNetworkStatus.ts b/apps/spruce/src/hooks/useNetworkStatus.ts index f0f3dbe16..6df1f69bd 100644 --- a/apps/spruce/src/hooks/useNetworkStatus.ts +++ b/apps/spruce/src/hooks/useNetworkStatus.ts @@ -1,34 +1,17 @@ import { useEffect, useState } from "react"; -import { useActivityAnalytics } from "analytics"; - -type useNetworkStatusType = { - (sendAnalytics?: boolean): boolean; -}; /** * This hook sets an eventListener to monitor if the browser is online or offline. - * @param sendAnalytics - whether or not to send an analytics event when the browser goes online * @returns boolean - true if online, false if offline */ -export const useNetworkStatus: useNetworkStatusType = ( - sendAnalytics = false, -) => { +export const useNetworkStatus = () => { const [isOnline, setIsOnline] = useState(true); - const { sendEvent } = useActivityAnalytics(); - - const sendOnlineEvent = () => { - if (sendAnalytics) { - sendEvent({ name: "Tab Active", status: "online" }); - } - }; useEffect(() => { const handleOffline = () => { - // Don't send event because we can't send events if the browser is offline. setIsOnline(false); }; const handleOnline = () => { - sendOnlineEvent(); setIsOnline(true); }; window.addEventListener("offline", handleOffline); diff --git a/apps/spruce/src/hooks/usePageVisibility.ts b/apps/spruce/src/hooks/usePageVisibility.ts index 11c1c027d..947be3394 100644 --- a/apps/spruce/src/hooks/usePageVisibility.ts +++ b/apps/spruce/src/hooks/usePageVisibility.ts @@ -1,40 +1,17 @@ import { useEffect, useState } from "react"; -import { useActivityAnalytics } from "analytics"; - -type usePageVisibilityType = { - (sendAnalytics?: boolean): boolean; -}; /** * This hook sets an eventListener to monitor if the tab is visible or hidden. - * @param sendAnalytics - whether or not to send an analytics event when the tab goes visible * @returns boolean - true if visible, false if hidden */ -export const usePageVisibility: usePageVisibilityType = ( - sendAnalytics = false, -) => { +export const usePageVisibility = () => { const [isVisible, setIsVisible] = useState(true); - const { sendEvent } = useActivityAnalytics(); - - const sendVisibleEvent = () => { - if (sendAnalytics) { - sendEvent({ name: "Tab Active", status: "visible" }); - } - }; - - const sendHiddenEvent = () => { - if (sendAnalytics) { - sendEvent({ name: "Tab Not Active" }); - } - }; useEffect(() => { const handleVisibilityChange = () => { if (document.visibilityState === "visible") { - sendVisibleEvent(); setIsVisible(true); } else { - sendHiddenEvent(); setIsVisible(false); } };