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

chore: Added new metrics event nft image viewed #2587

Merged
merged 3 commits into from
Aug 4, 2023
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
18 changes: 15 additions & 3 deletions apps/wallet-mobile/src/NftDetails/NftDetailsImage.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
import {RouteProp, useRoute} from '@react-navigation/native'
import React from 'react'
import {Dimensions, StyleSheet, View} from 'react-native'
import ViewTransformer from 'react-native-easy-view-transformer'

import {FadeIn} from '../components'
import {NftPreview} from '../components/NftPreview'
import {NftRoutes} from '../navigation'
import {useMetrics} from '../metrics/metricsManager'
import {NftRoutes, useParams} from '../navigation'
import {useSelectedWallet} from '../SelectedWallet'
import {isEmptyString} from '../utils/utils'
import {useNft} from '../yoroi-wallets/hooks'

type Params = NftRoutes['nft-details']

const isParams = (params?: Params | object | undefined): params is Params => {
return !!params && 'id' in params && !isEmptyString(params.id)
}

export const NftDetailsImage = () => {
const {id} = useRoute<RouteProp<NftRoutes, 'nft-details'>>().params
const {id} = useParams<Params>(isParams)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jorbuedo we have useParams which takes a ts safe guard fn, since .params are unsafe.

const wallet = useSelectedWallet()
const nft = useNft(wallet, {id})
const {track} = useMetrics()

React.useEffect(() => {
if (!isEmptyString(nft?.id)) track.nftGalleryDetailsImageViewed()
}, [nft?.id, track])

const dimensions = Dimensions.get('window')
const imageSize = Math.min(dimensions.width, dimensions.height)
Expand Down
19 changes: 19 additions & 0 deletions apps/wallet-mobile/src/metrics/ampli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,10 @@ export interface SwapProperties {
to_asset: string;
}

export class NftGalleryDetailsImageViewed implements BaseEvent {
event_type = 'NFT Gallery Details Image Viewed';
}

export class NftGalleryDetailsPageViewed implements BaseEvent {
event_type = 'NFT Gallery Details Page Viewed';
}
Expand Down Expand Up @@ -872,6 +876,21 @@ export class Ampli {
return this.amplitude!.flush();
}

/**
* NFT Gallery Details Image Viewed
*
* [View in Tracking Plan](https://data.amplitude.com/emurgo/Yoroi/events/main/latest/NFT%20Gallery%20Details%20Image%20Viewed)
*
* This event tracks when a user views the NFT image at full screen
*
* @param options Amplitude event options.
*/
nftGalleryDetailsImageViewed(
options?: EventOptions,
) {
return this.track(new NftGalleryDetailsImageViewed(), options);
}

/**
* NFT Gallery Details Page Viewed
*
Expand Down
3 changes: 3 additions & 0 deletions apps/wallet-mobile/src/metrics/metricsManager.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const mockAmpli = {
nftGalleryPageViewed: jest.fn(),
nftGallerySearchActivated: jest.fn(),
nftGalleryDetailsPageViewed: jest.fn(),
nftGalleryDetailsImageViewed: jest.fn(),

sendInitiated: jest.fn(),
sendSelectAssetPageViewed: jest.fn(),
Expand Down Expand Up @@ -119,6 +120,7 @@ describe('makeMetricsManager', () => {
metricsManager.track.nftGalleryPageViewed({nft_count: 10})
metricsManager.track.nftGallerySearchActivated({nft_search_term: 'test', nft_count: 10})
metricsManager.track.nftGalleryDetailsPageViewed()
metricsManager.track.nftGalleryDetailsImageViewed()

metricsManager.track.sendInitiated()
metricsManager.track.sendSelectAssetPageViewed()
Expand All @@ -131,6 +133,7 @@ describe('makeMetricsManager', () => {
expect(mockAmpli.nftGalleryPageViewed).toHaveBeenCalledWith({nft_count: 10})
expect(mockAmpli.nftGallerySearchActivated).toHaveBeenCalledWith({nft_search_term: 'test', nft_count: 10})
expect(mockAmpli.nftGalleryDetailsPageViewed).toHaveBeenCalled()
expect(mockAmpli.nftGalleryDetailsImageViewed).toHaveBeenCalled()

expect(mockAmpli.sendInitiated).toHaveBeenCalled()
expect(mockAmpli.sendSelectAssetPageViewed).toHaveBeenCalled()
Expand Down
1 change: 1 addition & 0 deletions apps/wallet-mobile/src/metrics/metricsManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const makeMetricsManager = (
nftGalleryPageViewed: metricsModule.nftGalleryPageViewed.bind(metricsModule),
nftGallerySearchActivated: metricsModule.nftGallerySearchActivated.bind(metricsModule),
nftGalleryDetailsPageViewed: metricsModule.nftGalleryDetailsPageViewed.bind(metricsModule),
nftGalleryDetailsImageViewed: metricsModule.nftGalleryDetailsImageViewed.bind(metricsModule),

sendInitiated: metricsModule.sendInitiated.bind(metricsModule),
sendSelectAssetPageViewed: metricsModule.sendSelectAssetPageViewed.bind(metricsModule),
Expand Down
1 change: 1 addition & 0 deletions apps/wallet-mobile/src/metrics/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const mockMetricsManager = (): MetricsManager => {
nftGalleryPageViewed: e,
nftGallerySearchActivated: e,
nftGalleryDetailsPageViewed: e,
nftGalleryDetailsImageViewed: e,

sendInitiated: e,
sendSelectAssetPageViewed: e,
Expand Down