From 5d1908a1cbba1b3f5ce2862f1183189f0cc3d0cb Mon Sep 17 00:00:00 2001 From: Maxime Le Duc Date: Sat, 30 Nov 2024 14:29:27 +0100 Subject: [PATCH] Send tracking on view achievements --- src/features/navigation/RootNavigator/types.ts | 2 +- .../profile/components/Achievements/BadgeBanner.tsx | 1 + .../components/Modals/AchievementSuccessModal.tsx | 2 +- .../profile/pages/Achievements/Achievements.tsx | 13 +++++++++++-- .../profile/pages/Achievements/useAchievements.ts | 4 ++-- src/features/profile/pages/Profile.native.test.tsx | 2 +- src/libs/analytics/logEventAnalytics.ts | 2 ++ 7 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/features/navigation/RootNavigator/types.ts b/src/features/navigation/RootNavigator/types.ts index 21dbab21a29..e51c289c814 100644 --- a/src/features/navigation/RootNavigator/types.ts +++ b/src/features/navigation/RootNavigator/types.ts @@ -310,7 +310,7 @@ export type RootStackParamList = { ThematicHeaders: undefined MarketingBlocks: undefined MovieCalendar: undefined - Achievements: undefined + Achievements: { from: 'profile' | 'success' } } & AccessibilityRootStackParamList & CulturalSurveyRootStackParamList & TutorialRootStackParamList & diff --git a/src/features/profile/components/Achievements/BadgeBanner.tsx b/src/features/profile/components/Achievements/BadgeBanner.tsx index 7c759b57da4..eca15161a60 100644 --- a/src/features/profile/components/Achievements/BadgeBanner.tsx +++ b/src/features/profile/components/Achievements/BadgeBanner.tsx @@ -11,6 +11,7 @@ export const BadgeBanner: React.FC = () => { }> Mes badges diff --git a/src/features/profile/components/Modals/AchievementSuccessModal.tsx b/src/features/profile/components/Modals/AchievementSuccessModal.tsx index 408dbe1862e..3b4405c4a4c 100644 --- a/src/features/profile/components/Modals/AchievementSuccessModal.tsx +++ b/src/features/profile/components/Modals/AchievementSuccessModal.tsx @@ -67,7 +67,7 @@ export const AchievementSuccessModal = ({ visible, hideModal, ids }: Props) => { { hideModal() }} diff --git a/src/features/profile/pages/Achievements/Achievements.tsx b/src/features/profile/pages/Achievements/Achievements.tsx index db3d5264f67..edb44d7beff 100644 --- a/src/features/profile/pages/Achievements/Achievements.tsx +++ b/src/features/profile/pages/Achievements/Achievements.tsx @@ -1,9 +1,11 @@ -import React, { FC } from 'react' +import { useRoute } from '@react-navigation/native' +import React, { FC, useEffect } from 'react' import { View } from 'react-native' import { FlatList } from 'react-native-gesture-handler' import { useTheme } from 'styled-components' import styled from 'styled-components/native' +import { UseRouteType } from 'features/navigation/RootNavigator/types' import { Badge } from 'features/profile/components/Achievements/Badge' import { achievementCategoryDisplayNames, @@ -28,12 +30,19 @@ const emptyBadge = { } export const Achievements = () => { + const { + params: { from }, + } = useRoute>() const { uniqueColors } = useTheme() - const { categories } = useAchievements({ + const { categories, track } = useAchievements({ achievements: mockAchievements, completedAchievements: mockCompletedAchievements, }) + useEffect(() => { + track(from) + }, [from, track]) + return ( diff --git a/src/features/profile/pages/Achievements/useAchievements.ts b/src/features/profile/pages/Achievements/useAchievements.ts index a17b426cb70..85b98514116 100644 --- a/src/features/profile/pages/Achievements/useAchievements.ts +++ b/src/features/profile/pages/Achievements/useAchievements.ts @@ -20,7 +20,7 @@ type Categories = { }[] }[] -type UseAchivements = { +type UseAchievements = { categories: Categories track: (from: 'profile' | 'success') => void } @@ -33,7 +33,7 @@ export type UseAchivementsProps = { export const useAchievements = ({ achievements, completedAchievements, -}: UseAchivementsProps): UseAchivements => { +}: UseAchivementsProps): UseAchievements => { const categories = getAchievementsCategories(achievements).map( createCategory(achievements, completedAchievements) ) diff --git a/src/features/profile/pages/Profile.native.test.tsx b/src/features/profile/pages/Profile.native.test.tsx index 1eb0a472b58..024de5ad3e1 100644 --- a/src/features/profile/pages/Profile.native.test.tsx +++ b/src/features/profile/pages/Profile.native.test.tsx @@ -191,7 +191,7 @@ describe('Profile component', () => { fireEvent.press(badgeBanner) - expect(navigate).toHaveBeenCalledWith('Achievements', undefined) + expect(navigate).toHaveBeenCalledWith('Achievements', { from: 'profile' }) }) }) diff --git a/src/libs/analytics/logEventAnalytics.ts b/src/libs/analytics/logEventAnalytics.ts index 06aab740318..eccb56a9b04 100644 --- a/src/libs/analytics/logEventAnalytics.ts +++ b/src/libs/analytics/logEventAnalytics.ts @@ -299,6 +299,8 @@ export const logEventAnalytics = { analytics.logEvent({ firebase: AnalyticsEvent.DISMISS_NOTIFICATIONS }), logDismissShareApp: (type: ShareAppModalType) => analytics.logEvent({ firebase: AnalyticsEvent.DISMISS_SHARE_APP }, { type }), + logDisplayAchievements: (params: { from: 'profile' | 'success'; numberUnlocked: number }) => + analytics.logEvent({ firebase: AnalyticsEvent.DISPLAY_ACHIEVEMENTS }, params), logDisplayForcedLoginHelpMessage: () => analytics.logEvent({ firebase: AnalyticsEvent.DISPLAY_FORCED_LOGIN_HELP_MESSAGE }), logEduconnectExplanationClicked: () =>