Skip to content

Commit

Permalink
fix: remove mixpanel event's tracking from PG
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandrogelmi committed Mar 29, 2024
1 parent 97554a0 commit e5f7ee1
Show file tree
Hide file tree
Showing 19 changed files with 9 additions and 361 deletions.
37 changes: 2 additions & 35 deletions packages/pn-personagiuridica-webapp/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ErrorInfo, useEffect, useMemo, useState } from 'react';
import { useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation } from 'react-router-dom';

Expand All @@ -23,7 +23,6 @@ import {
useHasPermissions,
useMultiEvent,
useTracking,
useUnload,
} from '@pagopa-pn/pn-commons';
import { PartyEntity, ProductEntity } from '@pagopa/mui-italia';

Expand All @@ -37,8 +36,6 @@ import { getDomicileInfo, getSidemenuInformation } from './redux/sidemenu/action
import { RootState } from './redux/store';
import { getConfiguration } from './services/configuration.service';
import { PGAppErrorFactory } from './utility/AppError/PGAppErrorFactory';
import { TrackEventType } from './utility/events';
import { trackEventByType } from './utility/mixpanel';
import './utility/onetrust';

// Cfr. PN-6096
Expand Down Expand Up @@ -77,7 +74,6 @@ const ActualApp = () => {
const currentStatus = useAppSelector((state: RootState) => state.appStatus.currentStatus);
const { pathname } = useLocation();
const path = pathname.split('/');
const source = path[path.length - 1];

const sessionToken = loggedUser.sessionToken;
const jwtUser = useMemo(
Expand Down Expand Up @@ -114,10 +110,6 @@ const ActualApp = () => {
[t, organization?.id, i18n.language]
);

useUnload(() => {
trackEventByType(TrackEventType.APP_UNLOAD);
});

useTracking(MIXPANEL_TOKEN, process.env.NODE_ENV);

useEffect(() => {
Expand Down Expand Up @@ -227,24 +219,11 @@ const ActualApp = () => {
};

const handleAssistanceClick = () => {
trackEventByType(TrackEventType.CUSTOMER_CARE_MAILTO, {
source: sessionToken ? 'postlogin' : 'prelogin',
});
/* eslint-disable-next-line functional/immutable-data */
window.location.href = sessionToken
? `${SELFCARE_BASE_URL}/assistenza`
: `mailto:${PAGOPA_HELP_EMAIL}`;
};
const handleEventTrackingCallbackAppCrash = (e: Error, eInfo: ErrorInfo) => {
trackEventByType(TrackEventType.APP_CRASH, {
route: source,
stacktrace: { error: e, errorInfo: eInfo },
});
};

const handleEventTrackingCallbackProductSwitch = (target: string) => {
trackEventByType(TrackEventType.USER_PRODUCT_SWITCH, { target });
};

const [clickVersion] = useMultiEvent({
callback: () =>
Expand All @@ -267,19 +246,7 @@ const ActualApp = () => {
showHeader={!isPrivacyPage}
showFooter={!isPrivacyPage}
onExitAction={handleUserLogout}
eventTrackingCallbackAppCrash={handleEventTrackingCallbackAppCrash}
eventTrackingCallbackProductSwitch={(target) =>
handleEventTrackingCallbackProductSwitch(target)
}
sideMenu={
<SideMenu
menuItems={menuItems}
selfCareItems={selfcareMenuItems}
eventTrackingCallback={(target) =>
trackEventByType(TrackEventType.USER_NAV_ITEM, { target })
}
/>
}
sideMenu={<SideMenu menuItems={menuItems} selfCareItems={selfcareMenuItems} />}
showSideMenu={
!!sessionToken &&
tosConsent &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ import { CourtesyChannelType, LegalChannelType } from '../../models/contacts';
import { deleteCourtesyAddress, deleteLegalAddress } from '../../redux/contact/actions';
import { DeleteDigitalAddressParams } from '../../redux/contact/types';
import { useAppDispatch } from '../../redux/hooks';
import { getContactEventType } from '../../utility/contacts.utility';
import { EventActions, TrackEventType } from '../../utility/events';
import { trackEventByType } from '../../utility/mixpanel';
import { useDigitalContactsCodeVerificationContext } from './DigitalContactsCodeVerification.context';

type Props = {
Expand Down Expand Up @@ -165,11 +162,8 @@ const DigitalContactElem = forwardRef<{ editContact: () => void }, Props>(
/* eslint-disable-next-line functional/no-let */
let actionToDispatch: AsyncThunk<string, DeleteDigitalAddressParams, any>;
if (contactType === LegalChannelType.PEC) {
trackEventByType(TrackEventType.CONTACT_LEGAL_CONTACT, { action: EventActions.DELETE });
actionToDispatch = deleteLegalAddress;
} else {
const eventTypeByChannel = getContactEventType(contactType);
trackEventByType(eventTypeByChannel, { action: EventActions.DELETE });
actionToDispatch = deleteCourtesyAddress;
}
void dispatch(actionToDispatch({ recipientId, senderId, channelType: contactType }))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ import {
import { SaveDigitalAddressParams } from '../../redux/contact/types';
import { useAppDispatch, useAppSelector } from '../../redux/hooks';
import { RootState } from '../../redux/store';
import { getContactEventType } from '../../utility/contacts.utility';
import { EventActions, TrackEventType } from '../../utility/events';
import { trackEventByType } from '../../utility/mixpanel';

type ModalProps = {
labelRoot: string;
Expand Down Expand Up @@ -111,14 +108,10 @@ const DigitalContactsCodeVerificationProvider: FC<{ children?: ReactNode }> = ({
const handleCodeVerification = (verificationCode?: string, noCallback: boolean = false) => {
/* eslint-disable functional/no-let */
let actionToBeDispatched;
let eventTypeByChannel;
/* eslint-enable functional/no-let */
if (modalProps.digitalDomicileType === LegalChannelType.PEC) {
actionToBeDispatched = createOrUpdateLegalAddress;
eventTypeByChannel = TrackEventType.CONTACT_LEGAL_CONTACT;
} else {
actionToBeDispatched = createOrUpdateCourtesyAddress;
eventTypeByChannel = getContactEventType(modalProps.digitalDomicileType);
}
if (!actionToBeDispatched) {
return;
Expand All @@ -132,7 +125,6 @@ const DigitalContactsCodeVerificationProvider: FC<{ children?: ReactNode }> = ({
code: verificationCode,
};

trackEventByType(eventTypeByChannel, { action: EventActions.ADD });
void dispatch(actionToBeDispatched(digitalAddressParams))
.unwrap()
.then((res) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { TableCell, TableRow, TextField, Typography } from '@mui/material';
import { dataRegex, useIsMobile, useSpecialContactsContext } from '@pagopa-pn/pn-commons';

import { CourtesyChannelType, LegalChannelType } from '../../models/contacts';
import { EventActions, TrackEventType } from '../../utility/events';
import { trackEventByType } from '../../utility/mixpanel';
import DigitalContactElem from './DigitalContactElem';

type Props = {
Expand Down Expand Up @@ -105,7 +103,6 @@ const SpecialContactElem = memo(({ address, recipientId }: Props) => {
if (status === 'cancelled') {
await formik.setFieldValue(id, initialValues[id], true);
}
trackEventByType(TrackEventType.CONTACT_SPECIAL_CONTACTS, { action: EventActions.ADD });
};

const formik = useFormik({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import {
} from '../../../__test__/test-utils';
import * as api from '../../../api/contacts/Contacts.api';
import { DigitalAddress, LegalChannelType } from '../../../models/contacts';
import { TrackEventType } from '../../../utility/events';
import * as trackingFunctions from '../../../utility/mixpanel';
import DigitalContactElem from '../DigitalContactElem';
import { DigitalContactsCodeVerificationProvider } from '../DigitalContactsCodeVerification.context';

Expand Down Expand Up @@ -55,9 +53,6 @@ const fields = [
const mockResetModifyValue = vi.fn();
const mockDeleteCbk = vi.fn();
const mockOnConfirm = vi.fn();
// mock tracking
const createTrackEventSpy = vi.spyOn(trackingFunctions, 'trackEventByType');
const mockTrackEventFn = vi.fn();

/*
In questo test viene testato solo il rendering dei componenti e non il flusso.
Expand All @@ -69,10 +64,6 @@ Andrea Cimini - 11/09/2023
describe('DigitalContactElem Component', () => {
let result: RenderResult | undefined;

beforeEach(() => {
createTrackEventSpy.mockImplementation(mockTrackEventFn);
});

afterEach(() => {
result = undefined;
vi.clearAllMocks();
Expand Down Expand Up @@ -203,10 +194,6 @@ describe('DigitalContactElem Component', () => {
dialog = await waitFor(() => screen.getByRole('dialog'));
dialogButtons = dialog?.querySelectorAll('button');
fireEvent.click(dialogButtons![1]);
expect(mockTrackEventFn).toBeCalledTimes(1);
expect(mockTrackEventFn).toBeCalledWith(TrackEventType.CONTACT_LEGAL_CONTACT, {
action: 'delete',
});
await waitFor(() => {
expect(dialog).not.toBeInTheDocument();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import { DELEGATION_ACTIONS, getDelegatesByCompany } from '../../redux/delegatio
import { useAppDispatch, useAppSelector } from '../../redux/hooks';
import { RootState } from '../../redux/store';
import delegationToItem from '../../utility/delegation.utility';
import { TrackEventType } from '../../utility/events';
import { trackEventByType } from '../../utility/mixpanel';
import DelegationDataSwitch from './DelegationDataSwitch';

type Props = {
Expand Down Expand Up @@ -69,9 +67,8 @@ const DelegatesByCompany = () => {
const data = delegationToItem(delegatesByCompany) as Array<Row<DelegationColumnData>>;
const rows = sortArray(sort.order, sort.orderBy, data);

const handleAddDelegationClick = (source: string) => {
const handleAddDelegationClick = () => {
navigate(routes.NUOVA_DELEGA);
trackEventByType(TrackEventType.DELEGATION_DELEGATE_ADD_CTA, { source });
};

const delegatesColumn: Array<SmartTableData<DelegationColumnData>> = [
Expand Down Expand Up @@ -160,7 +157,7 @@ const DelegatesByCompany = () => {
<Button
id="add-deleghe"
variant="outlined"
onClick={(_e, source = 'default') => handleAddDelegationClick(source)}
onClick={handleAddDelegationClick}
data-testid="addDeleghe"
>
<AddIcon fontSize={'small'} sx={{ marginRight: 1 }} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import {
import { useAppDispatch, useAppSelector } from '../../redux/hooks';
import { RootState } from '../../redux/store';
import { ServerResponseErrorCode } from '../../utility/AppError/types';
import { TrackEventType } from '../../utility/events';
import { trackEventByType } from '../../utility/mixpanel';
import AcceptDelegationModal from './AcceptDelegationModal';
import ConfirmationModal from './ConfirmationModal';

Expand Down Expand Up @@ -93,11 +91,6 @@ export const Menu: React.FC<Props> = ({ menuType, id, userLogged, row, onAction
menuType === 'delegates' ? t('deleghe.confirm_revocation') : t('deleghe.confirm_rejection');

const handleOpenModalClick = () => {
const eventToTrack =
menuType === 'delegates'
? TrackEventType.DELEGATION_DELEGATE_REVOKE
: TrackEventType.DELEGATION_DELEGATOR_REJECT;
trackEventByType(eventToTrack);
setShowConfirmationModal(true);
setAnchorEl(null);
};
Expand All @@ -111,7 +104,6 @@ export const Menu: React.FC<Props> = ({ menuType, id, userLogged, row, onAction
if (row?.name && row?.verificationCode) {
setShowCodeModal(true);
setAnchorEl(null);
trackEventByType(TrackEventType.DELEGATION_DELEGATE_VIEW_CODE);
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useEffect, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router-dom';

import { Alert, Box, Link, Typography } from '@mui/material';

Expand All @@ -9,28 +9,21 @@ import * as routes from '../../navigation/routes.const';
import { useAppDispatch, useAppSelector } from '../../redux/hooks';
import { closeDomicileBanner } from '../../redux/sidemenu/reducers';
import { RootState } from '../../redux/store';
import { TrackEventType } from '../../utility/events';
import { trackEventByType } from '../../utility/mixpanel';

const DomicileBanner = () => {
const { t } = useTranslation(['notifiche']);
const { pathname } = useLocation();
const navigate = useNavigate();
const dispatch = useAppDispatch();
const open = useAppSelector((state: RootState) => state.generalInfoState.domicileBannerOpened);
const defaultAddresses = useAppSelector(
(state: RootState) => state.generalInfoState.defaultAddresses
);
const path = pathname.split('/');
const source = path[path.length - 1] === 'notifica' ? 'detail' : 'list';

const handleClose = useCallback(() => {
trackEventByType(TrackEventType.DIGITAL_DOMICILE_BANNER_CLOSE, { source });
dispatch(closeDomicileBanner());
}, [closeDomicileBanner]);

const handleAddDomicile = useCallback(() => {
trackEventByType(TrackEventType.DIGITAL_DOMICILE_LINK);
navigate(routes.RECAPITI);
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import {
import * as routes from '../../navigation/routes.const';
import { useAppSelector } from '../../redux/hooks';
import { RootState } from '../../redux/store';
import { TrackEventType } from '../../utility/events';
import { trackEventByType } from '../../utility/mixpanel';
import FilterNotifications from './FilterNotifications';

type Props = {
Expand Down Expand Up @@ -134,8 +132,6 @@ const DesktopNotifications = ({
} else {
navigate(routes.GET_DETTAGLIO_NOTIFICA_PATH(row.iun));
}
// log event
trackEventByType(TrackEventType.NOTIFICATION_TABLE_ROW_INTERACTION);
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import {
import { setNotificationFilters } from '../../redux/dashboard/reducers';
import { useAppSelector } from '../../redux/hooks';
import { RootState } from '../../redux/store';
import { TrackEventType } from '../../utility/events';
import { trackEventByType } from '../../utility/mixpanel';
import FilterNotificationsFormActions from './FilterNotificationsFormActions';
import FilterNotificationsFormBody from './FilterNotificationsFormBody';

Expand Down Expand Up @@ -94,7 +92,6 @@ const FilterNotifications = forwardRef(({ showFilters }: Props, ref) => {
validationSchema,
/** onSubmit populates filters */
onSubmit: (values) => {
trackEventByType(TrackEventType.NOTIFICATION_FILTER_SEARCH);
const currentFilters = {
startDate: values.startDate,
endDate: values.endDate,
Expand All @@ -110,7 +107,6 @@ const FilterNotifications = forwardRef(({ showFilters }: Props, ref) => {
});

const cleanFilters = () => {
trackEventByType(TrackEventType.NOTIFICATION_FILTER_REMOVE);
dispatch(setNotificationFilters(emptyValues));
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import { ButtonNaked } from '@pagopa/mui-italia';
import * as routes from '../../navigation/routes.const';
import { useAppSelector } from '../../redux/hooks';
import { RootState } from '../../redux/store';
import { TrackEventType } from '../../utility/events';
import { trackEventByType } from '../../utility/mixpanel';
import FilterNotifications from './FilterNotifications';

type Props = {
Expand Down Expand Up @@ -156,8 +154,6 @@ const MobileNotifications = ({
} else {
navigate(routes.GET_DETTAGLIO_NOTIFICA_PATH(row.iun));
}
// log event
trackEventByType(TrackEventType.NOTIFICATION_TABLE_ROW_INTERACTION);
};

const showFilters = notifications?.length > 0 || filtersApplied;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ import {
} from '../redux/notification/reducers';
import { RootState } from '../redux/store';
import { getConfiguration } from '../services/configuration.service';
import { TrackEventType } from '../utility/events';
import { trackEventByType } from '../utility/mixpanel';

// state for the invocations to this component
// (to include in navigation or Link to the route/s arriving to it)
Expand Down Expand Up @@ -259,7 +257,6 @@ const NotificationDetail = () => {
})
.catch(() => undefined);
}
trackEventByType(TrackEventType.NOTIFICATION_DETAIL_PAYMENT_INTERACTION);
};

const hasNotificationReceivedApiError = hasApiErrors(
Expand Down Expand Up @@ -501,9 +498,6 @@ const NotificationDetail = () => {
historyButtonLabel={t('detail.show-history', { ns: 'notifiche' })}
showMoreButtonLabel={t('detail.show-more', { ns: 'notifiche' })}
showLessButtonLabel={t('detail.show-less', { ns: 'notifiche' })}
eventTrackingCallbackShowMore={() =>
trackEventByType(TrackEventType.NOTIFICATION_TIMELINE_VIEW_MORE)
}
disableDownloads={isCancelled.cancellationInTimeline}
isParty={false}
/>
Expand Down
Loading

0 comments on commit e5f7ee1

Please sign in to comment.