Skip to content

Commit

Permalink
(PC-31095) feat(profile): Add analytics for DeletProfileReason (#6751)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucasbeneston authored Aug 9, 2024
1 parent 4d1280c commit 30f8584
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,30 +195,37 @@ exports[`<DeleteProfileReason /> 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",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -21,11 +22,21 @@ describe('<DeleteProfileReason />', () => {
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(<DeleteProfileReason />)

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(<DeleteProfileReason />)

fireEvent.press(screen.getByText('Autre'))

expect(analytics.logSelectDeletionReason).toHaveBeenNthCalledWith(1, 'other')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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',
},
]

Expand Down Expand Up @@ -91,12 +100,13 @@ export function DeleteProfileReason() {
contentContainerStyle={flatListStyles}
data={reasonButtons}
renderItem={({ item }) => {
const { wording, navigateTo } = item
const { wording, navigateTo, analyticsReason } = item
return (
<ItemContainer>
<HeroButtonList
Title={<Typo.ButtonText>{wording}</Typo.ButtonText>}
navigateTo={{ screen: navigateTo }}
onBeforeNavigate={() => analytics.logSelectDeletionReason(analyticsReason)}
accessibilityLabel={wording}
/>
</ItemContainer>
Expand Down
1 change: 1 addition & 0 deletions src/libs/analytics/__mocks__/logEventAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions src/libs/analytics/logEventAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
3 changes: 2 additions & 1 deletion src/libs/firebase/analytics/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 30f8584

Please sign in to comment.