From d9fca985c75efd25e78cea697335d1750ec459d2 Mon Sep 17 00:00:00 2001 From: capJavert Date: Thu, 16 Jan 2025 14:29:06 +0100 Subject: [PATCH] feat: prompt click analytics --- .../streak/popup/ReadingStreakPopup.tsx | 36 ++++++++++++++++--- packages/shared/src/lib/log.ts | 7 ++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/packages/shared/src/components/streak/popup/ReadingStreakPopup.tsx b/packages/shared/src/components/streak/popup/ReadingStreakPopup.tsx index bd1cc4b824..5889c0a534 100644 --- a/packages/shared/src/components/streak/popup/ReadingStreakPopup.tsx +++ b/packages/shared/src/components/streak/popup/ReadingStreakPopup.tsx @@ -33,6 +33,12 @@ import { } from '../../../hooks/streaks/useStreakTimezoneOk'; import { usePrompt } from '../../../hooks/usePrompt'; import usePersistentContext from '../../../hooks/usePersistentContext'; +import { useLogContext } from '../../../contexts/LogContext'; +import { + LogEvent, + StreakTimezonePromptAction, + TargetId, +} from '../../../lib/log'; const getStreak = ({ value, @@ -111,10 +117,9 @@ export function ReadingStreakPopup({ const [showStreakConfig, toggleShowStreakConfig] = useToggle(false); const isTimezoneOk = useStreakTimezoneOk(); const { showPrompt } = usePrompt(); - const [, setTimezoneMismatchIgnore] = usePersistentContext( - timezoneMismatchIgnoreKey, - '', - ); + const [timezoneMismatchIgnore, setTimezoneMismatchIgnore] = + usePersistentContext(timezoneMismatchIgnoreKey, ''); + const { logEvent } = useLogContext(); const streaks = useMemo(() => { const today = new Date(); @@ -201,6 +206,18 @@ export function ReadingStreakPopup({ onClick={async (event) => { const deviceTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone; + const eventExtra = { + device_timezone: deviceTimezone, + user_timezone: user.timezone, + timezone_ok: isTimezoneOk, + timezone_ignore: timezoneMismatchIgnore, + }; + + logEvent({ + event_name: LogEvent.Click, + target_type: TargetId.StreakTimezoneLabel, + extra: JSON.stringify(eventExtra), + }); if (isTimezoneOk) { return; @@ -224,6 +241,17 @@ export function ReadingStreakPopup({ shouldCloseOnOverlayClick: false, }); + logEvent({ + event_name: LogEvent.Click, + target_type: TargetId.StreakTimezoneMismatchPrompt, + extra: JSON.stringify({ + ...eventExtra, + action: promptResult + ? StreakTimezonePromptAction.Settings + : StreakTimezonePromptAction.Ignore, + }), + }); + if (!promptResult) { setTimezoneMismatchIgnore(deviceTimezone); diff --git a/packages/shared/src/lib/log.ts b/packages/shared/src/lib/log.ts index f63463d2cb..7391340ab1 100644 --- a/packages/shared/src/lib/log.ts +++ b/packages/shared/src/lib/log.ts @@ -313,6 +313,8 @@ export enum TargetId { BookmarkFolder = 'bookmark folder', FeedSettings = 'feed settings', ClickbaitShield = 'clickbait shield', + StreakTimezoneLabel = 'streak timezone label', + StreakTimezoneMismatchPrompt = 'streak timezone mismatch prompt', } export enum NotificationChannel { @@ -361,3 +363,8 @@ export enum UserAcquisitionEvent { Dismiss = 'dismiss ua', Submit = 'choose ua', } + +export enum StreakTimezonePromptAction { + Settings = 'settings', + Ignore = 'ignore', +}