From 30f85847b7bcd6ab58464488590448f8b8583892 Mon Sep 17 00:00:00 2001
From: Lucas BENESTON <62059034+Lucasbeneston@users.noreply.github.com>
Date: Fri, 9 Aug 2024 12:49:01 +0200
Subject: [PATCH] (PC-31095) feat(profile): Add analytics for
DeletProfileReason (#6751)
---
...eProfileReason.native.test.tsx.native-snap | 7 +++++++
.../DeleteProfileReason.native.test.tsx | 19 +++++++++++++++----
.../DeleteProfileReason.tsx | 12 +++++++++++-
.../analytics/__mocks__/logEventAnalytics.ts | 1 +
src/libs/analytics/logEventAnalytics.ts | 2 ++
src/libs/firebase/analytics/events.ts | 3 ++-
6 files changed, 38 insertions(+), 6 deletions(-)
diff --git a/__snapshots__/features/profile/pages/DeleteProfileReason/DeleteProfileReason.native.test.tsx.native-snap b/__snapshots__/features/profile/pages/DeleteProfileReason/DeleteProfileReason.native.test.tsx.native-snap
index 2459f477540..2901912fe22 100644
--- a/__snapshots__/features/profile/pages/DeleteProfileReason/DeleteProfileReason.native.test.tsx.native-snap
+++ b/__snapshots__/features/profile/pages/DeleteProfileReason/DeleteProfileReason.native.test.tsx.native-snap
@@ -195,30 +195,37 @@ exports[` should match snapshot 1`] = `
data={
[
{
+ "analyticsReason": "changeEmail",
"navigateTo": "ConfirmDeleteProfile",
"wording": "J’aimerais créer un compte avec une adresse e-mail différente",
},
{
+ "analyticsReason": "noLongerUsed",
"navigateTo": "ConfirmDeleteProfile",
"wording": "Je n’utilise plus l’application",
},
{
+ "analyticsReason": "noMoreCredit",
"navigateTo": "ConfirmDeleteProfile",
"wording": "Je n’ai plus de crédit ou très peu de crédit restant",
},
{
+ "analyticsReason": "dataDeletion",
"navigateTo": "ConfirmDeleteProfile",
"wording": "Je souhaite supprimer mes données personnelles",
},
{
+ "analyticsReason": "hackedMailBox",
"navigateTo": "ConfirmDeleteProfile",
"wording": "Ma boite mail a été piratée",
},
{
+ "analyticsReason": "hackedAccount",
"navigateTo": "ConfirmDeleteProfile",
"wording": "Je pense que quelqu’un d’autre a accès à mon compte",
},
{
+ "analyticsReason": "other",
"navigateTo": "ConfirmDeleteProfile",
"wording": "Autre",
},
diff --git a/src/features/profile/pages/DeleteProfileReason/DeleteProfileReason.native.test.tsx b/src/features/profile/pages/DeleteProfileReason/DeleteProfileReason.native.test.tsx
index a220850122a..bd97abb962b 100644
--- a/src/features/profile/pages/DeleteProfileReason/DeleteProfileReason.native.test.tsx
+++ b/src/features/profile/pages/DeleteProfileReason/DeleteProfileReason.native.test.tsx
@@ -3,7 +3,8 @@ import React from 'react'
import { navigate } from '__mocks__/@react-navigation/native'
import * as LogoutRoutine from 'features/auth/helpers/useLogoutRoutine'
import { DeleteProfileReason } from 'features/profile/pages/DeleteProfileReason/DeleteProfileReason'
-import { fireEvent, render, screen } from 'tests/utils'
+import { analytics } from 'libs/analytics'
+import { fireEvent, render, screen, waitFor } from 'tests/utils'
jest.mock('features/navigation/helpers/navigateToHome')
jest.mock('features/navigation/navigationRef')
@@ -21,11 +22,21 @@ describe('', () => {
expect(screen).toMatchSnapshot()
})
- it('should redirect to Home page when clicking on "Autre"', () => {
+ it('should redirect to Home page when clicking on "Autre"', async () => {
render()
- fireEvent.press(screen.getByText(`Autre`))
+ fireEvent.press(screen.getByText('Autre'))
- expect(navigate).toHaveBeenCalledWith('ConfirmDeleteProfile', undefined)
+ await waitFor(() => {
+ expect(navigate).toHaveBeenCalledWith('ConfirmDeleteProfile', undefined)
+ })
+ })
+
+ it('should log analytics when clicking on reasonButton', () => {
+ render()
+
+ fireEvent.press(screen.getByText('Autre'))
+
+ expect(analytics.logSelectDeletionReason).toHaveBeenNthCalledWith(1, 'other')
})
})
diff --git a/src/features/profile/pages/DeleteProfileReason/DeleteProfileReason.tsx b/src/features/profile/pages/DeleteProfileReason/DeleteProfileReason.tsx
index d3457fe2139..aaa7d0f51e7 100644
--- a/src/features/profile/pages/DeleteProfileReason/DeleteProfileReason.tsx
+++ b/src/features/profile/pages/DeleteProfileReason/DeleteProfileReason.tsx
@@ -6,6 +6,7 @@ import styled from 'styled-components/native'
import { RootScreenNames } from 'features/navigation/RootNavigator/types'
import { useOnViewableItemsChanged } from 'features/subscription/helpers/useOnViewableItemsChanged'
+import { analytics } from 'libs/analytics'
import { AnimatedViewRefType, createAnimatableComponent } from 'libs/react-native-animatable'
import { theme } from 'theme'
import { HeroButtonList } from 'ui/components/buttons/HeroButtonList'
@@ -26,36 +27,44 @@ const isWeb = Platform.OS === 'web'
type ReasonButton = {
wording: string
navigateTo: RootScreenNames
+ analyticsReason: string
}
const reasonButtons: ReasonButton[] = [
{
wording: 'J’aimerais créer un compte avec une adresse e-mail différente',
navigateTo: 'ConfirmDeleteProfile',
+ analyticsReason: 'changeEmail',
},
{
wording: 'Je n’utilise plus l’application',
navigateTo: 'ConfirmDeleteProfile',
+ analyticsReason: 'noLongerUsed',
},
{
wording: 'Je n’ai plus de crédit ou très peu de crédit restant',
navigateTo: 'ConfirmDeleteProfile',
+ analyticsReason: 'noMoreCredit',
},
{
wording: 'Je souhaite supprimer mes données personnelles',
navigateTo: 'ConfirmDeleteProfile',
+ analyticsReason: 'dataDeletion',
},
{
wording: 'Ma boite mail a été piratée',
navigateTo: 'ConfirmDeleteProfile',
+ analyticsReason: 'hackedMailBox',
},
{
wording: 'Je pense que quelqu’un d’autre a accès à mon compte',
navigateTo: 'ConfirmDeleteProfile',
+ analyticsReason: 'hackedAccount',
},
{
wording: 'Autre',
navigateTo: 'ConfirmDeleteProfile',
+ analyticsReason: 'other',
},
]
@@ -91,12 +100,13 @@ export function DeleteProfileReason() {
contentContainerStyle={flatListStyles}
data={reasonButtons}
renderItem={({ item }) => {
- const { wording, navigateTo } = item
+ const { wording, navigateTo, analyticsReason } = item
return (
{wording}}
navigateTo={{ screen: navigateTo }}
+ onBeforeNavigate={() => analytics.logSelectDeletionReason(analyticsReason)}
accessibilityLabel={wording}
/>
diff --git a/src/libs/analytics/__mocks__/logEventAnalytics.ts b/src/libs/analytics/__mocks__/logEventAnalytics.ts
index bee0c9aff33..15edf180014 100644
--- a/src/libs/analytics/__mocks__/logEventAnalytics.ts
+++ b/src/libs/analytics/__mocks__/logEventAnalytics.ts
@@ -161,6 +161,7 @@ export const logEventAnalytics: typeof actualLogEventAnalytics = {
logSearchScrollToPage: jest.fn(),
logSeeMyBooking: jest.fn(),
logSelectAge: jest.fn(),
+ logSelectDeletionReason: jest.fn(),
logSelectIdStatusClicked: jest.fn(),
logSendActivationMailAgain: jest.fn(),
logSetAddressClicked: jest.fn(),
diff --git a/src/libs/analytics/logEventAnalytics.ts b/src/libs/analytics/logEventAnalytics.ts
index 14f0c423232..e31bbe2b9e9 100644
--- a/src/libs/analytics/logEventAnalytics.ts
+++ b/src/libs/analytics/logEventAnalytics.ts
@@ -622,6 +622,8 @@ export const logEventAnalytics = {
},
{ age, from }
),
+ logSelectDeletionReason: (type: string) =>
+ analytics.logEvent({ firebase: AnalyticsEvent.SELECT_DELETION_REASON }, { type }),
logSelectIdStatusClicked: (type: IDStatus) =>
analytics.logEvent({ amplitude: AmplitudeEvent.SELECT_ID_STATUS_CLICKED }, { type }),
logSendActivationMailAgain: (numberOfTimes: number) =>
diff --git a/src/libs/firebase/analytics/events.ts b/src/libs/firebase/analytics/events.ts
index 9cd825a13c7..76494e19c70 100644
--- a/src/libs/firebase/analytics/events.ts
+++ b/src/libs/firebase/analytics/events.ts
@@ -77,9 +77,9 @@ export enum AnalyticsEvent {
HAS_ADDED_OFFER_TO_FAVORITES = 'HasAddedOfferToFavorites',
HAS_APPLIED_FAVORITES_SORTING = 'HasAppliedFavoritesSorting',
HAS_CHANGED_PASSWORD = 'HasChangedPassword',
- HAS_CLICKED_DUO_STEP = 'HasClickedDuoStep',
HAS_CHOSEN_PRICE = 'HasChosenPrice',
HAS_CHOSEN_TIME = 'HasChosenTime',
+ HAS_CLICKED_DUO_STEP = 'HasClickedDuoStep',
HAS_CLICKED_MISSING_CODE = 'HasClickedMissingCode',
HAS_CORRECTED_EMAIL = 'HasCorrectedEmail',
HAS_DISMISSED_APP_SHARING_MODAL = 'HasDismissedAppSharingModal',
@@ -141,6 +141,7 @@ export enum AnalyticsEvent {
SEE_MORE_CLICKED = 'SeeMoreClicked',
SEE_MY_BOOKING = 'SeeMyBooking',
SELECT_AGE = 'SelectAge',
+ SELECT_DELETION_REASON = 'SelectDeletionReason',
SEND_ACTIVATION_MAIL_AGAIN = 'SendActivationMailAgain',
SHARE = 'Share',
SHARE_APP = 'ShareApp',