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

Add shop events #111

Merged
merged 1 commit into from
Jun 22, 2022
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
19 changes: 18 additions & 1 deletion src/components/modal/transact-menu/TransactMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,24 @@ const TransactModal = () => {
img: () => <Icons.BuyGiftCard />,
title: t('Buy Gift Cards'),
description: t('Buy gift cards with crypto'),
onPress: () => {},
onPress: () => {
navigation.navigate('Tabs', {
screen: 'Shop',
params: {
screen: 'Home',
},
});
dispatch(
logSegmentEvent(
'track',
'Clicked Buy Gift Cards',
{
context: 'TransactMenu',
},
true,
),
);
},
},
];

Expand Down
6 changes: 6 additions & 0 deletions src/navigation/tabs/shop/ShopHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {useAppSelector} from '../../../utils/hooks';
import {StackScreenProps} from '@react-navigation/stack';
import {ShopScreens, ShopStackParamList} from './ShopStack';
import {useTranslation} from 'react-i18next';
import {useFocusEffect} from '@react-navigation/native';
import {logSegmentEvent} from '../../../store/app/app.effects';

export enum ShopTabs {
GIFT_CARDS = 'Gift Cards',
Expand Down Expand Up @@ -223,6 +225,10 @@ const ShopHome: React.FC<
curations,
]);

useFocusEffect(() => {
dispatch(logSegmentEvent('track', 'Viewed Shop Tab', undefined, true));
});

return (
<ShopContainer>
<ScrollView ref={scrollViewRef} keyboardDismissMode="on-drag">
Expand Down
9 changes: 7 additions & 2 deletions src/navigation/tabs/shop/components/GiftCardCatalog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ import {useNavigation} from '@react-navigation/native';
import {GiftCardScreens} from '../gift-card/GiftCardStack';
import MyGiftCards from './MyGiftCards';
import FilterSheet, {initializeCategoryMap} from './FilterSheet';
import {useAppSelector} from '../../../../utils/hooks';
import {useAppDispatch, useAppSelector} from '../../../../utils/hooks';
import {APP_NETWORK} from '../../../../constants/config';
import GhostSvg from '../../../../../assets/img/ghost-cheeky.svg';
import {useTranslation} from 'react-i18next';
import {logSegmentEvent} from '../../../../store/app/app.effects';

const Curations = ({
curations,
Expand Down Expand Up @@ -121,6 +122,7 @@ export default ({
categories: CategoryWithGiftCards[];
onSelectedGiftCardsChange: (newNumSelectedGiftCards: number) => void;
}) => {
const dispatch = useAppDispatch();
const {t} = useTranslation();
const navigation = useNavigation();
const theme = useTheme();
Expand Down Expand Up @@ -153,8 +155,11 @@ export default ({
giftCard.displayName.toLowerCase().includes(lowerCaseText),
);
setSearchResults(newSearchResults);
dispatch(
logSegmentEvent('track', 'Searched Gift Cards', {search: text}, true),
);
}, 300),
[availableGiftCards],
[availableGiftCards, dispatch],
);

const underlayColor = theme.dark ? '#121212' : '#fbfbff';
Expand Down
6 changes: 6 additions & 0 deletions src/navigation/tabs/shop/components/ShopOnline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import {
} from './styled/ShopTabComponents';
import GhostSvg from '../../../../../assets/img/ghost-cheeky.svg';
import {useTranslation} from 'react-i18next';
import {useAppDispatch} from '../../../../utils/hooks';
import {logSegmentEvent} from '../../../../store/app/app.effects';

const SearchResults = styled.View`
display: flex;
Expand All @@ -50,6 +52,7 @@ export const ShopOnline = ({
categories: CategoryWithIntegrations[];
}) => {
const {t} = useTranslation();
const dispatch = useAppDispatch();
const navigation = useNavigation();
const theme = useTheme();
const {control} = useForm();
Expand All @@ -62,6 +65,9 @@ export const ShopOnline = ({
integration.displayName.toLowerCase().includes(text.toLocaleLowerCase()),
);
setSearchResults(newSearchResults);
dispatch(
logSegmentEvent('track', 'Searched Online Brands', {search: text}, true),
);
}, 300);

const FullIntegrationsList = () => (
Expand Down
25 changes: 24 additions & 1 deletion src/navigation/tabs/shop/gift-card/screens/BuyGiftCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useLayoutEffect, useState} from 'react';
import React, {useEffect, useLayoutEffect, useState} from 'react';
import {Platform, ScrollView, View} from 'react-native';
import {StackScreenProps} from '@react-navigation/stack';
import LinearGradient from 'react-native-linear-gradient';
Expand Down Expand Up @@ -44,6 +44,7 @@ import {APP_NETWORK} from '../../../../../constants/config';
import {useAppSelector} from '../../../../../utils/hooks';
import {TouchableWithoutFeedback} from 'react-native-gesture-handler';
import {useTranslation} from 'react-i18next';
import {logSegmentEvent} from '../../../../../store/app/app.effects';

const GradientBox = styled(LinearGradient)`
width: ${WIDTH}px;
Expand Down Expand Up @@ -141,6 +142,18 @@ const BuyGiftCard = ({
},
});
});
useEffect(() => {
dispatch(
logSegmentEvent(
'track',
'Viewed Gift Card',
{
giftCardBrand: cardConfig.name,
},
true,
),
);
}, [cardConfig.name, dispatch]);

const showActivationFeeSheet = (
activationFee: number,
Expand Down Expand Up @@ -287,6 +300,16 @@ const BuyGiftCard = ({
};

const buyGiftCard = () => {
dispatch(
logSegmentEvent(
'track',
'Started Gift Card Purchase',
{
giftCardBrand: cardConfig.name,
},
true,
),
);
const selectedAmount = (cardConfig.supportedAmounts || [])[
selectedAmountIndex
];
Expand Down
19 changes: 16 additions & 3 deletions src/navigation/tabs/shop/gift-card/screens/GiftCardDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {useAppDispatch, useAppSelector} from '../../../../../utils/hooks';
import {DeviceEmitterEvents} from '../../../../../constants/device-emitter-events';
import Icons from '../../../../wallet/components/WalletIcons';
import {useTranslation} from 'react-i18next';
import {logSegmentEvent} from '../../../../../store/app/app.effects';

const maxWidth = 320;

Expand Down Expand Up @@ -350,13 +351,25 @@ const GiftCardDetails = ({
<ActionContainer>
{cardConfig.redeemUrl ? (
<Button
onPress={() =>
onPress={() => {
Linking.openURL(
`${cardConfig.redeemUrl as string}${
giftCard.claimCode
}`,
)
}
);
dispatch(
logSegmentEvent(
'track',
'Redeemed Gift Card',
{
giftCardAmount: giftCard.amount,
giftCardBrand: cardConfig.name,
giftCardCurrency: cardConfig.currency,
},
true,
),
);
}}
buttonStyle={'primary'}>
{t('Redeem Now')}
</Button>
Expand Down
23 changes: 23 additions & 0 deletions src/navigation/wallet/screens/send/confirm/GiftCardConfirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ const Confirm = () => {
setWalletSelectorVisible(true);
};

const getTransactionCurrency = () => {
return wallet
? wallet.currencyAbbreviation.toUpperCase()
: coinbaseAccount!.currency.code;
};

useEffect(() => {
return () => {
dispatch(ShopActions.deletedUnsoldGiftCards());
Expand Down Expand Up @@ -294,6 +300,23 @@ const Confirm = () => {
cardConfig,
},
});
const purchaseEventName =
giftCard.status === 'FAILURE'
? 'Failed Gift Card'
: 'Purchased Gift Card';
dispatch(
logSegmentEvent(
'track',
purchaseEventName,
{
giftCardAmount: amount,
giftCardBrand: cardConfig.name,
giftCardCurrency: cardConfig.currency,
coin: getTransactionCurrency(),
},
true,
),
);
};

const showError = ({
Expand Down