Skip to content

Commit

Permalink
feat: prompt click analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
capJavert committed Jan 16, 2025
1 parent f2f94c3 commit d9fca98
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
36 changes: 32 additions & 4 deletions packages/shared/src/components/streak/popup/ReadingStreakPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand Down
7 changes: 7 additions & 0 deletions packages/shared/src/lib/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -361,3 +363,8 @@ export enum UserAcquisitionEvent {
Dismiss = 'dismiss ua',
Submit = 'choose ua',
}

export enum StreakTimezonePromptAction {
Settings = 'settings',
Ignore = 'ignore',
}

0 comments on commit d9fca98

Please sign in to comment.