Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: gift tracking #4135

Merged
merged 8 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions packages/shared/src/components/ProfileMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ import { checkIsExtension, isIOSNative } from '../lib/func';
import { useDndContext } from '../contexts/DndContext';
import { LazyModal } from './modals/common/types';
import { usePlusSubscription } from '../hooks/usePlusSubscription';
import { LogEvent, TargetId } from '../lib/log';
import { LogEvent, TargetId, TargetType } from '../lib/log';
import { GiftIcon } from './icons/gift';
import { useLogContext } from '../contexts/LogContext';

interface ListItem {
title: string;
Expand All @@ -55,6 +56,7 @@ export default function ProfileMenu({
const { user, logout, isGdprCovered } = useAuthContext();
const { isActive: isDndActive, setShowDnd } = useDndContext();
const { isPlus, logSubscriptionEvent } = usePlusSubscription();
const { logEvent } = useLogContext();

const items: ListItem[] = useMemo(() => {
const list: ListItem[] = [
Expand Down Expand Up @@ -160,7 +162,14 @@ export default function ProfileMenu({
title: 'Gift daily.dev Plus',
buttonProps: {
icon: <GiftIcon />,
onClick: () => openModal({ type: LazyModal.GiftPlus }),
onClick: () => {
logEvent({
event_name: LogEvent.GiftSubscription,
target_id: TargetId.ProfileDropdown,
target_type: TargetType.Plus,
});
openModal({ type: LazyModal.GiftPlus });
},
},
});

Expand All @@ -174,14 +183,15 @@ export default function ProfileMenu({

return list.filter(Boolean);
}, [
user.permalink,
isGdprCovered,
isDndActive,
isPlus,
logSubscriptionEvent,
logout,
openModal,
isDndActive,
setShowDnd,
user.permalink,
openModal,
logEvent,
logout,
]);

if (!user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from '../buttons/Button';
import { ClickableText } from '../buttons/ClickableText';
import { SimpleTooltip } from '../tooltips/SimpleTooltip';
import { Origin } from '../../lib/log';
import { LogEvent, Origin, TargetId, TargetType } from '../../lib/log';
import type { Post } from '../../graphql/posts';
import { UserVote } from '../../graphql/posts';
import { AuthTriggers } from '../../lib/auth';
Expand All @@ -48,6 +48,7 @@ import { ContentPreferenceType } from '../../graphql/contentPreference';
import { isFollowingContent } from '../../hooks/contentPreference/types';
import { useIsSpecialUser } from '../../hooks/auth/useIsSpecialUser';
import { GiftIcon } from '../icons/gift';
import { useLogContext } from '../../contexts/LogContext';

export interface CommentActionProps {
onComment: (comment: Comment, parentId: string | null) => void;
Expand Down Expand Up @@ -84,6 +85,7 @@ export default function CommentActionButtons({
const { onMenuClick, isOpen, onHide } = useContextMenu({ id });
const { openModal } = useLazyModal();
const { displayToast } = useToastNotification();
const { logEvent } = useLogContext();
const [voteState, setVoteState] = useState<VoteEntityPayload>(() => {
return {
id: comment.id,
Expand Down Expand Up @@ -265,13 +267,19 @@ export default function CommentActionButtons({
if (comment.author.id !== user?.id && !comment.author.isPlus) {
commentOptions.push({
label: 'Gift daily.dev Plus',
action: () =>
action: () => {
logEvent({
event_name: LogEvent.GiftSubscription,
target_id: TargetId.ContextMenu,
target_type: TargetType.Plus,
});
openModal({
type: LazyModal.GiftPlus,
props: {
preselected: comment.author as UserShortProfile,
},
}),
});
},
icon: <GiftIcon />,
});
}
Expand Down
13 changes: 11 additions & 2 deletions packages/shared/src/components/plus/PlusInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ import {
ButtonVariant,
} from '../buttons/Button';
import { usePlusSubscription } from '../../hooks/usePlusSubscription';
import { LogEvent } from '../../lib/log';
import { LogEvent, TargetId, TargetType } from '../../lib/log';
import { useGiftUserContext } from './GiftUserContext';
import { PlusOptionRadio } from './PlusOptionRadio';
import { GiftingSelectedUser } from './GiftingSelectedUser';
import ConditionalWrapper from '../ConditionalWrapper';
import { useLazyModal } from '../../hooks/useLazyModal';
import { LazyModal } from '../modals/common/types';
import { GiftIcon } from '../icons/gift';
import { useLogContext } from '../../contexts/LogContext';

type PlusInfoProps = {
productOptions: ProductOption[];
Expand Down Expand Up @@ -73,6 +74,7 @@ export const PlusInfo = ({
const { openModal } = useLazyModal();
const { logSubscriptionEvent } = usePlusSubscription();
const { giftToUser } = useGiftUserContext();
const { logEvent } = useLogContext();
const { title, description, subtitle } =
copy[giftToUser ? PlusType.Gift : PlusType.Self];

Expand Down Expand Up @@ -109,7 +111,14 @@ export const PlusInfo = ({
icon={<GiftIcon />}
size={ButtonSize.XSmall}
variant={ButtonVariant.Float}
onClick={() => openModal({ type: LazyModal.GiftPlus })}
onClick={() => {
logEvent({
event_name: LogEvent.GiftSubscription,
target_id: TargetId.PlusPage,
target_type: TargetType.Plus,
});
openModal({ type: LazyModal.GiftPlus });
}}
>
Buy as a gift
</Button>
Expand Down
14 changes: 11 additions & 3 deletions packages/shared/src/components/profile/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ import {
import { UpgradeToPlus } from '../UpgradeToPlus';
import { useContentPreferenceStatusQuery } from '../../hooks/contentPreference/useContentPreferenceStatusQuery';
import { usePlusSubscription } from '../../hooks/usePlusSubscription';
import { LogEvent, TargetId } from '../../lib/log';
import { LogEvent, TargetId, TargetType } from '../../lib/log';
import CustomFeedOptionsMenu from '../CustomFeedOptionsMenu';
import { useContentPreference } from '../../hooks/contentPreference/useContentPreference';
import { useLazyModal } from '../../hooks/useLazyModal';
import { LazyModal } from '../modals/common/types';
import { MenuIcon } from '../MenuIcon';
import { GiftIcon } from '../icons/gift';
import type { MenuItemProps } from '../fields/ContextMenu';
import { useLogContext } from '../../contexts/LogContext';

export interface HeaderProps {
user: PublicProfile;
Expand Down Expand Up @@ -55,6 +56,7 @@ export function Header({
entity: ContentPreferenceType.User,
});
const { unblock, block } = useContentPreference();
const { logEvent } = useLogContext();

const onReportUser = React.useCallback(
(defaultBlocked = false) => {
Expand Down Expand Up @@ -103,11 +105,17 @@ export function Header({
options.push({
icon: <MenuIcon Icon={GiftIcon} />,
label: 'Gift daily.dev Plus',
action: () =>
action: () => {
logEvent({
event_name: LogEvent.GiftSubscription,
target_id: TargetId.ProfilePage,
target_type: TargetType.Plus,
});
openModal({
type: LazyModal.GiftPlus,
props: { preselected: user as UserShortProfile },
}),
});
},
});
}

Expand Down
13 changes: 11 additions & 2 deletions packages/shared/src/components/squads/SquadMemberMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { ContextMenu as ContextMenuIds } from '../../hooks/constants';
import { LazyModal } from '../modals/common/types';
import { GiftIcon } from '../icons/gift';
import { useLazyModal } from '../../hooks/useLazyModal';
import { LogEvent, TargetId, TargetType } from '../../lib/log';
import { useLogContext } from '../../contexts/LogContext';

interface SquadMemberMenuProps extends Pick<UseSquadActions, 'onUpdateRole'> {
squad: Squad;
Expand Down Expand Up @@ -127,6 +129,7 @@ export default function SquadMemberMenu({
const { user } = useContext(AuthContext);
const { showPrompt } = usePrompt();
const { displayToast } = useToastNotification();
const { logEvent } = useLogContext();
const onUpdateMember = async (
role: SourceMemberRole,
title: MenuItemTitle,
Expand Down Expand Up @@ -216,11 +219,17 @@ export default function SquadMemberMenu({
if (!member.user.isPlus) {
menu.push({
label: 'Gift daily.dev Plus',
action: () =>
action: () => {
logEvent({
event_name: LogEvent.GiftSubscription,
target_id: TargetId.Squad,
target_type: TargetType.Plus,
});
openModal({
type: LazyModal.GiftPlus,
props: { preselected: member.user },
}),
});
},
icon: <GiftIcon />,
});
}
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/src/lib/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export enum LogEvent {
ReceivePayment = 'receive payment',
OnboardingSkipPlus = 'skip upgrade subscription',
OnboardingUpgradePlus = 'upgrade subscription',
GiftSubscription = 'gift subscription',
// End Plus subscription
// Clickbait Shield
ToggleClickbaitShield = 'toggle clickbait shield',
Expand Down Expand Up @@ -308,6 +309,7 @@ export enum TargetId {
Ads = 'ads',
MyProfile = 'my profile',
PlusBadge = 'plus badge',
PlusPage = 'plus page',
Onboarding = 'onboarding',
BlockedWords = 'block words',
CustomFeed = 'custom feed',
Expand All @@ -316,6 +318,7 @@ export enum TargetId {
ClickbaitShield = 'clickbait shield',
StreakTimezoneLabel = 'streak timezone label',
StreakTimezoneMismatchPrompt = 'streak timezone mismatch prompt',
ContextMenu = 'context',
}

export enum NotificationChannel {
Expand Down
11 changes: 8 additions & 3 deletions packages/webapp/pages/account/invite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,16 @@ const AccountInvitePage = (): ReactElement => {
icon={<GiftIcon size={IconSize.Small} secondary />}
variant={ButtonVariant.Secondary}
color={ButtonColor.Bacon}
onClick={() =>
onClick={() => {
logEvent({
event_name: LogEvent.GiftSubscription,
target_id: TargetId.InviteFriendsPage,
target_type: TargetType.Plus,
});
openModal({
type: LazyModal.GiftPlus,
})
}
});
}}
className="max-w-fit border-action-plus-default text-action-plus-default"
>
Buy as gift
Expand Down