Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
34 changes: 31 additions & 3 deletions app/src/components/NavBar/Points.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { BlurView } from '@react-native-community/blur';
import { useFocusEffect, useNavigation } from '@react-navigation/native';
import type { NativeStackNavigationProp } from '@react-navigation/native-stack';

import { useSelfClient } from '@selfxyz/mobile-sdk-alpha';
import { PointEvents } from '@selfxyz/mobile-sdk-alpha/constants/analytics';

import { PointHistoryList } from '@/components/PointHistoryList';
import { useIncomingPoints, usePoints } from '@/hooks/usePoints';
import BellWhiteIcon from '@/images/icons/bell_white.svg';
Expand Down Expand Up @@ -42,6 +45,8 @@ import {
} from '@/utils/points';

const Points: React.FC = () => {
const selfClient = useSelfClient();

const { bottom } = useSafeAreaInsets();
const navigation =
useNavigation<NativeStackNavigationProp<RootStackParamList>>();
Expand Down Expand Up @@ -99,7 +104,7 @@ const Points: React.FC = () => {
if (isEnabling) {
return;
}

selfClient.trackEvent(PointEvents.EARN_NOTIFICATION);
setIsEnabling(true);
try {
const granted = await requestNotificationPermission();
Expand All @@ -109,6 +114,7 @@ const Points: React.FC = () => {
const response = await recordNotificationPointEvent();
if (response.success) {
setIsNovaSubscribed(true);
selfClient.trackEvent(PointEvents.EARN_NOTIFICATION_SUCCESS);

if (listRefreshRef.current) {
await listRefreshRef.current();
Expand All @@ -126,6 +132,10 @@ const Points: React.FC = () => {
callbackId,
});
} else {
selfClient.trackEvent(PointEvents.EARN_NOTIFICATION_FAILED, {
reason: 'Failed to record points',
});

const callbackId = registerModalCallbacks({
onButtonPress: () => {},
onModalDismiss: () => {},
Expand All @@ -140,6 +150,9 @@ const Points: React.FC = () => {
});
}
} else {
selfClient.trackEvent(PointEvents.EARN_NOTIFICATION_FAILED, {
reason: 'Subscription failed',
});
const callbackId = registerModalCallbacks({
onButtonPress: () => {},
onModalDismiss: () => {},
Expand All @@ -152,6 +165,9 @@ const Points: React.FC = () => {
});
}
} else {
selfClient.trackEvent(PointEvents.EARN_NOTIFICATION_FAILED, {
reason: 'Permission denied',
});
const callbackId = registerModalCallbacks({
onButtonPress: () => {},
onModalDismiss: () => {},
Expand All @@ -165,6 +181,9 @@ const Points: React.FC = () => {
});
}
} catch (error) {
selfClient.trackEvent(PointEvents.EARN_NOTIFICATION_FAILED, {
reason: 'Exception occurred',
});
const callbackId = registerModalCallbacks({
onButtonPress: () => {},
onModalDismiss: () => {},
Expand All @@ -187,6 +206,7 @@ const Points: React.FC = () => {
if (isBackingUp) {
return;
}
selfClient.trackEvent(PointEvents.EARN_BACKUP);

setIsBackingUp(true);
try {
Expand All @@ -195,7 +215,7 @@ const Points: React.FC = () => {

if (response.success) {
setBackupForPointsCompleted();

selfClient.trackEvent(PointEvents.EARN_BACKUP_SUCCESS);
if (listRefreshRef.current) {
await listRefreshRef.current();
}
Expand All @@ -212,6 +232,7 @@ const Points: React.FC = () => {
callbackId,
});
} else {
selfClient.trackEvent(PointEvents.EARN_BACKUP_FAILED);
const callbackId = registerModalCallbacks({
onButtonPress: () => {},
onModalDismiss: () => {},
Expand All @@ -225,6 +246,7 @@ const Points: React.FC = () => {
});
}
} catch (error) {
selfClient.trackEvent(PointEvents.EARN_BACKUP_FAILED);
const callbackId = registerModalCallbacks({
onButtonPress: () => {},
onModalDismiss: () => {},
Expand Down Expand Up @@ -402,7 +424,12 @@ const Points: React.FC = () => {
</XStack>
</Pressable>
)}
<Pressable onPress={() => navigation.navigate('Referral')}>
<Pressable
onPress={() => {
selfClient.trackEvent(PointEvents.EARN_REFERRAL);
navigation.navigate('Referral');
}}
>
<YStack
height={270}
backgroundColor="white"
Expand Down Expand Up @@ -474,6 +501,7 @@ const Points: React.FC = () => {
paddingVertical={14}
borderRadius={5}
height={52}
onPress={() => selfClient.trackEvent(PointEvents.EXPLORE_APPS)}
>
<Text
fontFamily="DIN OT"
Expand Down
1 change: 1 addition & 0 deletions app/src/components/PointHistoryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const PointHistoryList: React.FC<PointHistoryListProps> = ({
onRefreshRef,
onLayout,
}) => {
// why is this not using usePointEventStore((store) => store.events)?
const [pointEvents, setPointEvents] = useState<PointEvent[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [refreshing, setRefreshing] = useState(false);
Expand Down
5 changes: 5 additions & 0 deletions app/src/components/referral/CopyReferralButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import React, { useState } from 'react';
import { Button, Text, XStack } from 'tamagui';
import Clipboard from '@react-native-clipboard/clipboard';

import { useSelfClient } from '@selfxyz/mobile-sdk-alpha';
import { PointEvents } from '@selfxyz/mobile-sdk-alpha/constants/analytics';

import CopyToClipboard from '@/images/icons/copy_to_clipboard.svg';
import { black, green500, white } from '@/utils/colors';
import { dinot } from '@/utils/fonts';
Expand All @@ -20,9 +23,11 @@ export const CopyReferralButton: React.FC<CopyReferralButtonProps> = ({
onCopy,
}) => {
const [isCopied, setIsCopied] = useState(false);
const selfClient = useSelfClient();

const handleCopyLink = async () => {
try {
selfClient.trackEvent(PointEvents.EARN_REFERRAL_COPY_LINK);
await Clipboard.setString(referralLink);
setIsCopied(true);

Expand Down
7 changes: 7 additions & 0 deletions app/src/screens/app/ReferralScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { XStack, YStack } from 'tamagui';
import { useNavigation } from '@react-navigation/native';
import type { NativeStackNavigationProp } from '@react-navigation/native-stack';

import { useSelfClient } from '@selfxyz/mobile-sdk-alpha';
import { PointEvents } from '@selfxyz/mobile-sdk-alpha/constants/analytics';

import { CopyReferralButton } from '@/components/referral/CopyReferralButton';
import { ReferralHeader } from '@/components/referral/ReferralHeader';
import { ReferralInfo } from '@/components/referral/ReferralInfo';
Expand All @@ -27,6 +30,7 @@ import {
} from '@/utils/referralShare';

const ReferralScreen: React.FC = () => {
const selfClient = useSelfClient();
const { bottom } = useSafeAreaInsets();
const navigation =
useNavigation<NativeStackNavigationProp<RootStackParamList>>();
Expand All @@ -37,14 +41,17 @@ const ReferralScreen: React.FC = () => {
const messagesButtonColor = Platform.OS === 'android' ? blue600 : green500;

const handleShareMessages = async () => {
selfClient.trackEvent(PointEvents.EARN_REFERAL_MESSAGES);
await shareViaSMS(message);
};

const handleShare = async () => {
selfClient.trackEvent(PointEvents.EARN_REFERAL_SHARE);
await shareViaNative(message, referralLink, 'Join Self');
};

const handleShareWhatsApp = async () => {
selfClient.trackEvent(PointEvents.EARN_REFERAL_WHATSAPP);
await shareViaWhatsApp(message);
};

Expand Down
10 changes: 8 additions & 2 deletions app/src/screens/home/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import type { NativeStackNavigationProp } from '@react-navigation/native-stack';
import type { DocumentCatalog, IDDocument } from '@selfxyz/common/utils/types';
import type { DocumentMetadata } from '@selfxyz/mobile-sdk-alpha';
import { useSelfClient } from '@selfxyz/mobile-sdk-alpha';
import { DocumentEvents } from '@selfxyz/mobile-sdk-alpha/constants/analytics';
import {
DocumentEvents,
PointEvents,
} from '@selfxyz/mobile-sdk-alpha/constants/analytics';
import { useSafeBottomPadding } from '@selfxyz/mobile-sdk-alpha/hooks/useSafeBottomPadding';

import IdCardLayout from '@/components/homeScreen/idCard';
Expand Down Expand Up @@ -296,7 +299,10 @@ const HomeScreen: React.FC = () => {
borderRadius={5}
borderWidth={1}
borderColor={slate300}
onPress={() => onEarnPointsPress(true)}
onPress={() => {
selfClient.trackEvent(PointEvents.HOME_POINT_EARN_POINTS_OPENED);
onEarnPointsPress(true);
}}
>
<Text
color="#2563EB"
Expand Down
16 changes: 16 additions & 0 deletions packages/mobile-sdk-alpha/src/constants/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,22 @@ export const PassportEvents = {
START_PASSPORT_NFC: 'Passport: Start Passport NFC',
};

export const PointEvents = {
HOME_POINT_EARN_POINTS_OPENED: 'Points: Home Earn Points Opened',
EXPLORE_APPS: 'Points: Explore Apps Opened',
EARN_REFERRAL: 'Points: Earn Referral Opened',
EARN_REFERAL_MESSAGES: 'Points: Earn Referral via Messages',
EARN_REFERAL_WHATSAPP: 'Points: Earn Referral via WhatsApp',
EARN_REFERAL_SHARE: 'Points: Earn Referral via Share',
EARN_REFERRAL_COPY_LINK: 'Points: Earn Referral Copy Link',
EARN_BACKUP: 'Points: Earn with Backup',
EARN_BACKUP_SUCCESS: 'Points: Earn with Backup Success',
EARN_BACKUP_FAILED: 'Points: Earn with Backup Failed',
EARN_NOTIFICATION: 'Points: Earn with Notification',
EARN_NOTIFICATION_FAILED: 'Points: Earn with Notification Failed',
EARN_NOTIFICATION_SUCCESS: 'Points: Earn with Notification Success',
};

export const ProofEvents = {
ALREADY_REGISTERED: 'Proof: Already Registered',
ATTESTATION_RECEIVED: 'Proof: Attestation Received',
Expand Down
Loading