From 7d18ec11ae18f9fd854a74632c020e0b42a62c6d Mon Sep 17 00:00:00 2001 From: ~latter-bolden Date: Fri, 10 Jan 2025 14:49:18 -0500 Subject: [PATCH] throttle the logs a bit --- packages/shared/src/store/lure.ts | 33 ++++++++++++------- .../components/InviteFriendsToTlonButton.tsx | 1 + 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/packages/shared/src/store/lure.ts b/packages/shared/src/store/lure.ts index 6c7d4d37a4..37b341b1a7 100644 --- a/packages/shared/src/store/lure.ts +++ b/packages/shared/src/store/lure.ts @@ -1,6 +1,6 @@ import { useQuery } from '@tanstack/react-query'; import produce from 'immer'; -import { useCallback, useEffect, useMemo, useRef } from 'react'; +import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import create from 'zustand'; import { getCurrentUserId, poke, scry, subscribeOnce } from '../api/urbit'; @@ -374,6 +374,7 @@ export function useLureLinkStatus({ inviteServiceEndpoint: string; inviteServiceIsDev: boolean; }) { + const [lastLoggedStatus, setLastLoggedStatus] = useState(''); const { supported, fetched, enabled, url, deepLinkUrl, toggle, describe } = useLure({ flag, @@ -423,17 +424,25 @@ export function useLureLinkStatus({ return 'ready'; }, [supported, fetched, enabled, url, checked, deepLinkUrl, good, flag]); - if (status === 'error') { - lureLogger.trackEvent(AnalyticsEvent.InviteError, { - context: 'useLureLinkStatus has error status', - inviteInfo, - }); - } else { - lureLogger.trackEvent(AnalyticsEvent.InviteDebug, { - context: 'useLureLinkStatus log', - status, - inviteInfo, - }); + // prevent over zealous logging + const statusKey = useMemo(() => { + return `${status}-${fetched}-${checked}`; + }, [status, fetched, checked]); + + if (statusKey !== lastLoggedStatus) { + if (status === 'error') { + lureLogger.trackEvent(AnalyticsEvent.InviteError, { + context: 'useLureLinkStatus has error status', + inviteInfo, + }); + } else { + lureLogger.trackEvent(AnalyticsEvent.InviteDebug, { + context: 'useLureLinkStatus log', + status, + inviteInfo, + }); + } + setLastLoggedStatus(statusKey); } return { status, shareUrl: deepLinkUrl, toggle, describe }; diff --git a/packages/ui/src/components/InviteFriendsToTlonButton.tsx b/packages/ui/src/components/InviteFriendsToTlonButton.tsx index e3cf39efbf..a97ae2a91d 100644 --- a/packages/ui/src/components/InviteFriendsToTlonButton.tsx +++ b/packages/ui/src/components/InviteFriendsToTlonButton.tsx @@ -107,6 +107,7 @@ export function InviteFriendsToTlonButton({ linkIsDisabled || status === 'error' || status === 'unsupported'; useEffect(() => { + // eslint-disable-next-line logger.trackEvent('Invite Button Shown', { group: group?.id }); }, []);