Skip to content

Commit

Permalink
fix(PN-10821): Fix some Mixpanel regressions and track super profile …
Browse files Browse the repository at this point in the history
…properties (#1200)

* fix: mixpanel events and add super properties

* fixed randomic message problems into the DomicileBanner component

---------

Co-authored-by: Andrea Cimini <[email protected]>
  • Loading branch information
alessandrogelmi and AndreaCimini90 authored May 9, 2024
1 parent 665d324 commit 8dd9c41
Show file tree
Hide file tree
Showing 20 changed files with 208 additions and 74 deletions.
4 changes: 4 additions & 0 deletions packages/pn-personafisica-login/src/pages/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ const Login = () => {
SPID_IDP_NAME: 'CIE',
SPID_IDP_ID: SPID_CIE_ENTITY_ID,
});

PFLoginEventStrategyFactory.triggerEvent(PFLoginEventsType.SEND_LOGIN_METHOD, {
entityID: 'cie',
});
};

if (showIDPS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ const DigitalContactElem = forwardRef<{ editContact: () => void }, Props>(
if (onDeleteCbk) {
onDeleteCbk();
}
PFEventStrategyFactory.triggerEvent(getEventByContactType(contactType), {
senderId,
});
PFEventStrategyFactory.triggerEvent(getEventByContactType(contactType), senderId);
})
.catch((error) => {
console.error('Error occurred:', error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ const DigitalContactsCodeVerificationProvider: FC<{ children?: ReactNode }> = ({
const [isConfirmationModalVisible, setIsConfirmationModalVisible] = useState(false);
const [errorMessage, setErrorMessage] = useState<ErrorMessage>();

const [isSpecialContactMode, setIsSpecialContactMode] = useState(false);

const initialProps = {
labelRoot: '',
labelType: '',
Expand Down Expand Up @@ -112,18 +110,17 @@ const DigitalContactsCodeVerificationProvider: FC<{ children?: ReactNode }> = ({

const sendSuccessEvent = (type: LegalChannelType | CourtesyChannelType) => {
if (type === LegalChannelType.PEC) {
PFEventStrategyFactory.triggerEvent(PFEventsType.SEND_ADD_PEC_UX_SUCCESS, {
isSpecialContact: isSpecialContactMode,
});
PFEventStrategyFactory.triggerEvent(
PFEventsType.SEND_ADD_PEC_UX_SUCCESS,
modalProps.senderId
);
return;
}
PFEventStrategyFactory.triggerEvent(
type === CourtesyChannelType.SMS
? PFEventsType.SEND_ADD_SMS_UX_SUCCESS
: PFEventsType.SEND_ADD_EMAIL_UX_SUCCESS,
{
isSpecialContact: isSpecialContactMode,
}
modalProps.senderId
);
};
const handleCodeVerification = (verificationCode?: string, noCallback: boolean = false) => {
Expand All @@ -136,17 +133,20 @@ const DigitalContactsCodeVerificationProvider: FC<{ children?: ReactNode }> = ({
}
if (verificationCode) {
if (modalProps.digitalDomicileType === LegalChannelType.PEC) {
PFEventStrategyFactory.triggerEvent(PFEventsType.SEND_ADD_PEC_UX_CONVERSION, {
isSpecialContact: isSpecialContactMode,
});
PFEventStrategyFactory.triggerEvent(
PFEventsType.SEND_ADD_PEC_UX_CONVERSION,
modalProps.senderId
);
} else if (modalProps.digitalDomicileType === CourtesyChannelType.SMS) {
PFEventStrategyFactory.triggerEvent(PFEventsType.SEND_ADD_SMS_UX_CONVERSION, {
isSpecialContact: isSpecialContactMode,
});
PFEventStrategyFactory.triggerEvent(
PFEventsType.SEND_ADD_SMS_UX_CONVERSION,
modalProps.senderId
);
} else if (modalProps.digitalDomicileType === CourtesyChannelType.EMAIL) {
PFEventStrategyFactory.triggerEvent(PFEventsType.SEND_ADD_EMAIL_UX_CONVERSION, {
isSpecialContact: isSpecialContactMode,
});
PFEventStrategyFactory.triggerEvent(
PFEventsType.SEND_ADD_EMAIL_UX_CONVERSION,
modalProps.senderId
);
}
}
if (!actionToBeDispatched) {
Expand Down Expand Up @@ -203,30 +203,24 @@ const DigitalContactsCodeVerificationProvider: FC<{ children?: ReactNode }> = ({
recipientId: string,
senderId: string,
senderName?: string,
callbackOnValidation?: (status: 'validated' | 'cancelled') => void,
isSpecialContact?: boolean
callbackOnValidation?: (status: 'validated' | 'cancelled') => void
) => {
setIsSpecialContactMode(!!isSpecialContact);
/* eslint-disable functional/no-let */
let labelRoot = '';
let labelType = '';
/* eslint-enable functional/no-let */
if (digitalDomicileType === LegalChannelType.PEC) {
labelRoot = 'legal-contacts';
labelType = 'pec';
PFEventStrategyFactory.triggerEvent(PFEventsType.SEND_ADD_PEC_START, {
isSpecialContact,
});
PFEventStrategyFactory.triggerEvent(PFEventsType.SEND_ADD_PEC_START, senderId);
} else {
labelRoot = 'courtesy-contacts';
labelType = digitalDomicileType === CourtesyChannelType.SMS ? 'phone' : 'email';
PFEventStrategyFactory.triggerEvent(
digitalDomicileType === CourtesyChannelType.SMS
? PFEventsType.SEND_ADD_SMS_START
: PFEventsType.SEND_ADD_EMAIL_START,
{
isSpecialContact,
}
senderId
);
}
setModalProps({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,21 @@ const DomicileBanner = forwardRef(({ source = 'home_notifiche' }: Props, ref) =>
navigate(routes.RECAPITI);
}, []);

const lackingAddressTypes = useMemo(
() =>
[LegalChannelType.PEC, CourtesyChannelType.EMAIL, CourtesyChannelType.IOMSG].filter(
(type) => !defaultAddresses.some((address) => address.channelType === type)
),
[defaultAddresses]
);

const messageIndex = Math.floor(Math.random() * lackingAddressTypes.length);
const messageType = lackingAddressTypes[messageIndex] as string;

/* if (returnDomicileBannerType) {
returnDomicileBannerType(messageType);
} */
const messageType = useMemo(() => {
const lackingAddressTypes = [
LegalChannelType.PEC,
CourtesyChannelType.EMAIL,
CourtesyChannelType.IOMSG,
].filter((type) => !defaultAddresses.some((address) => address.channelType === type));
const messageIndex = Math.floor(Math.random() * lackingAddressTypes.length);
return lackingAddressTypes.length > 0 ? (lackingAddressTypes[messageIndex] as string) : null;
}, [defaultAddresses]);

useEffect(() => {
if (lackingAddressTypes.length === 0) {
if (!messageType) {
dispatch(closeDomicileBanner());
}
}, [lackingAddressTypes]);
}, [messageType]);

useImperativeHandle(ref, () => messageType);

Expand Down
7 changes: 4 additions & 3 deletions packages/pn-personafisica-webapp/src/pages/AppStatus.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ const AppStatus = () => {
};

useEffect(() => {
PFEventStrategyFactory.triggerEvent(PFEventsType.SEND_SERVICE_STATUS, {
service_status_OK: appStatus.currentStatus?.appIsFullyOperative,
});
PFEventStrategyFactory.triggerEvent(
PFEventsType.SEND_SERVICE_STATUS,
appStatus.currentStatus?.appIsFullyOperative
);
}, [getCurrentAppStatus]);

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createSlice } from '@reduxjs/toolkit';

import { DigitalAddress } from '../../models/contacts';
import { acceptDelegation, rejectDelegation } from '../delegation/actions';
import { Delegator } from '../delegation/types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import {
} from '@pagopa-pn/pn-commons';

export class SendAddContactActionStrategy implements EventStrategy {
performComputations(isSpecialContact: boolean): TrackedEvent<{ other_contact: string }> {
performComputations(senderId: string): TrackedEvent<{ other_contact: string }> {
return {
[EventPropertyType.TRACK]: {
event_category: EventCategory.UX,
event_type: EventAction.ACTION,
other_contact: isSpecialContact ? 'yes' : 'no',
other_contact: senderId !== 'default' ? 'yes' : 'no',
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import {
} from '@pagopa-pn/pn-commons';

export class SendAddContactScreenViewStrategy implements EventStrategy {
performComputations(isSpecialContact: boolean): TrackedEvent<{ other_contact: string }> {
performComputations(senderId: string): TrackedEvent<{ other_contact: string }> {
return {
[EventPropertyType.TRACK]: {
event_category: EventCategory.UX,
event_type: EventAction.SCREEN_VIEW,
other_contact: isSpecialContact ? 'yes' : 'no',
other_contact: senderId !== 'default' ? 'yes' : 'no',
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ export class SendAddCourtesyAddressStrategy implements EventStrategy {
[EventPropertyType.PROFILE]: {
SEND_HAS_EMAIL: 'yes',
},
[EventPropertyType.SUPER_PROPERTY]: {
SEND_HAS_EMAIL: 'yes',
},
};
}

return {
[EventPropertyType.PROFILE]: {
SEND_HAS_SMS: 'yes',
},
[EventPropertyType.SUPER_PROPERTY]: {
SEND_HAS_SMS: 'yes',
},
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class SendAddLegalAddressStrategy implements EventStrategy {

return {
[EventPropertyType.PROFILE]: { SEND_HAS_PEC: 'yes' },
[EventPropertyType.SUPER_PROPERTY]: { SEND_HAS_PEC: 'yes' },
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export class SendHasAddressesStrategy implements EventStrategy {
SEND_HAS_SMS: hasCourtesySmsAddresses ? 'yes' : 'no',
SEND_APPIO_STATUS: ioStatus,
},
[EventPropertyType.SUPER_PROPERTY]: {
SEND_HAS_PEC: hasLegalAddresses ? 'yes' : 'no',
SEND_HAS_EMAIL: hasCourtesyEmailAddresses ? 'yes' : 'no',
SEND_HAS_SMS: hasCourtesySmsAddresses ? 'yes' : 'no',
SEND_APPIO_STATUS: ioStatus,
},
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,29 @@ export class SendRemoveCourtesyAddressStrategy implements EventStrategy {
performComputations({
params,
}: SendRemoveCourtesyAddressData): TrackedEvent<SendRemoveCourtesyAddressReturn> {
if (params.channelType === CourtesyChannelType.EMAIL) {
// If i'm removing a special contact (senderId !== 'default') I don't want to update the profile property
if (params.senderId === 'default') {
if (params.channelType === CourtesyChannelType.EMAIL) {
return {
[EventPropertyType.PROFILE]: {
SEND_HAS_EMAIL: 'no',
},
[EventPropertyType.SUPER_PROPERTY]: {
SEND_HAS_EMAIL: 'no',
},
};
}

return {
[EventPropertyType.PROFILE]: {
SEND_HAS_EMAIL: 'no',
SEND_HAS_SMS: 'no',
},
[EventPropertyType.SUPER_PROPERTY]: {
SEND_HAS_SMS: 'no',
},
};
} else {
return {};
}

return {
[EventPropertyType.PROFILE]: {
SEND_HAS_SMS: 'no',
},
};
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
import { EventPropertyType, EventStrategy, TrackedEvent } from '@pagopa-pn/pn-commons';

import { DeleteDigitalAddressParams } from '../../../redux/contact/types';

type SendRemoveLegalAddress = {
SEND_HAS_PEC: 'no';
};

type SendRemoveLegalAddressData = {
payload: string;
params: DeleteDigitalAddressParams;
};

export class SendRemoveLegalAddressStrategy implements EventStrategy {
performComputations(): TrackedEvent<SendRemoveLegalAddress> {
return {
[EventPropertyType.PROFILE]: {
SEND_HAS_PEC: 'no',
},
};
performComputations({
params,
}: SendRemoveLegalAddressData): TrackedEvent<SendRemoveLegalAddress> {
// If i'm removing a special contact (senderId !== 'default') I don't want to update the profile property
if (params.senderId === 'default') {
return {
[EventPropertyType.PROFILE]: {
SEND_HAS_PEC: 'no',
},
[EventPropertyType.SUPER_PROPERTY]: {
SEND_HAS_PEC: 'no',
},
};
} else {
return {};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('Mixpanel - Add contact action Strategy', () => {
it('should return add contact action event', () => {
const strategy = new SendAddContactActionStrategy();

const isOtherContactEvent = strategy.performComputations(true);
const isOtherContactEvent = strategy.performComputations('1233456');
expect(isOtherContactEvent).toEqual({
[EventPropertyType.TRACK]: {
event_category: EventCategory.UX,
Expand All @@ -15,7 +15,7 @@ describe('Mixpanel - Add contact action Strategy', () => {
},
});

const isNotOtherContactEvent = strategy.performComputations(false);
const isNotOtherContactEvent = strategy.performComputations('default');
expect(isNotOtherContactEvent).toEqual({
[EventPropertyType.TRACK]: {
event_category: EventCategory.UX,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('Mixpanel - Add contact screen view Strategy', () => {
it('should return add contact screen view event', () => {
const strategy = new SendAddContactScreenViewStrategy();

const isOtherContactEvent = strategy.performComputations(true);
const isOtherContactEvent = strategy.performComputations('123456');
expect(isOtherContactEvent).toEqual({
[EventPropertyType.TRACK]: {
event_category: EventCategory.UX,
Expand All @@ -15,7 +15,7 @@ describe('Mixpanel - Add contact screen view Strategy', () => {
},
});

const isNotOtherContactEvent = strategy.performComputations(false);
const isNotOtherContactEvent = strategy.performComputations('default');
expect(isNotOtherContactEvent).toEqual({
[EventPropertyType.TRACK]: {
event_category: EventCategory.UX,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ describe('Mixpanel - Add Courtesy Address Strategy', () => {
[EventPropertyType.PROFILE]: {
SEND_HAS_EMAIL: 'yes',
},
[EventPropertyType.SUPER_PROPERTY]: {
SEND_HAS_EMAIL: 'yes',
},
});
});

Expand All @@ -63,6 +66,9 @@ describe('Mixpanel - Add Courtesy Address Strategy', () => {
[EventPropertyType.PROFILE]: {
SEND_HAS_SMS: 'yes',
},
[EventPropertyType.SUPER_PROPERTY]: {
SEND_HAS_SMS: 'yes',
},
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ describe('Mixpanel - Add Legal Address Strategy', () => {
[EventPropertyType.PROFILE]: {
SEND_HAS_PEC: 'yes',
},
[EventPropertyType.SUPER_PROPERTY]: {
SEND_HAS_PEC: 'yes',
},
});
});
});
Loading

0 comments on commit 8dd9c41

Please sign in to comment.