Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ts/features/itwallet/analytics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ type TrackItWalletCieCardReadingFailure = {
};

type TrackItWalletCieCardReadingUnexpectedFailure = {
reason: string | undefined;
reason: string | unknown | undefined;
cie_reading_progress: number;
};

Expand Down
10 changes: 6 additions & 4 deletions ts/features/itwallet/common/utils/itwStoreUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ export const serializeFailureReason = (
| IssuanceFailure
| CredentialIssuanceFailure
| RemoteFailure
| ProximityFailure
| ProximityFailure,
origin?: string
) => {
const reason = !failure.reason
? "Reason not provided"
: failure.reason instanceof Error
? createReasonObject(failure.reason.message)
? createReasonObject(failure.reason.message, origin)
: failure.reason;

return {
Expand All @@ -87,7 +88,8 @@ export const serializeFailureReason = (
* This logic was agreed upon with the Mixpanel team to allow them to filter these specific error cases.
* Instead of sending a plain string, we return a structured object with a code and errorDescription
*/
const createReasonObject = (message: string) => ({
const createReasonObject = (message: string, origin?: string) => ({
code: "UNEXPECTED",
errorDescription: message
errorDescription: message,
origin
});
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ type ItwCieCardReadFailureContentProps = Extract<
export const ItwCieCardReadFailureContent = ({
failure,
progress,
onRetry
onRetry,
origin
}: ItwCieCardReadFailureContentProps) => {
const issuanceActor = ItwEidIssuanceMachineContext.useActorRef();
const isL3 = ItwEidIssuanceMachineContext.useSelector(
Expand All @@ -54,7 +55,7 @@ export const ItwCieCardReadFailureContent = ({
useDebugInfo({ failure });

// Track error on mount
useEffect(() => trackError(failure, isL3, progress));
useEffect(() => trackError(failure, isL3, progress, origin));

const dismissalDialog = useItwDismissalDialog({
handleDismiss: () => issuanceActor.send({ type: "close" })
Expand Down Expand Up @@ -213,7 +214,8 @@ export const ItwCieCardReadFailureContent = ({
const trackError = (
failure: CieManagerFailure,
isL3: boolean,
readProgress?: number
readProgress?: number,
origin?: string
) => {
const itw_flow: ItwFlow = isL3 ? "L3" : "L2";
// readProgress is a number between 0 and 1, mixpanel needs a number between 0 and 100
Expand Down Expand Up @@ -273,7 +275,10 @@ const trackError = (
}

trackItWalletCieCardReadingUnexpectedFailure({
reason: failure?.name ?? "UNEXPECTED_ERROR",
reason: {
origin: origin ?? "ITW_CIE_CARD_READING",
name: failure.name ?? "UNEXPECTED_ERROR"
},
cie_reading_progress: progress
});
};
20 changes: 17 additions & 3 deletions ts/features/itwallet/identification/cie/hooks/useCieManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ export type CieManagerFailure = CieError | NfcError;
export type CieManagerState =
| { state: "idle" }
| { state: "reading"; progress: number }
| { state: "failure"; failure: CieManagerFailure; progress?: number }
| {
state: "failure";
failure: CieManagerFailure;
progress?: number;
origin?: string;
}
| { state: "success" };

type UseCieManager = (params: {
Expand Down Expand Up @@ -123,7 +128,12 @@ export const useCieManager: UseCieManager = ({
setState(prev => {
// For the failure state we want to preserve the current progress
const currentProgress = prev.state === "reading" ? prev.progress : 0;
return { state: "failure", failure: error, progress: currentProgress };
return {
state: "failure",
failure: error,
progress: currentProgress,
origin: "ITW_CIE_MANAGER"
};
});

// Trigger a warning haptic feedback on TAG_LOST error
Expand Down Expand Up @@ -202,7 +212,11 @@ export const useCieManager: UseCieManager = ({
// Start the CieManager with the provided pin and authentication URL
await CieManager.startReading(pin, serviceProviderUrl);
} catch (error) {
setState({ state: "failure", failure: error as CieManagerFailure });
setState({
state: "failure",
failure: error as CieManagerFailure,
origin: "ITW_CIE_START_READING"
});
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ type Params = {
invalidErrorCode?: string;
};

// Origin generic string for mixpanel tracking
const origin = "ITW_CREDENTIAL_EVENTS_TRACKING";

/**
* Track errors occurred during the credential issuance process for analytics.
*/

export const useCredentialEventsTracking = ({
failure,
isItwL3,
Expand Down Expand Up @@ -95,7 +99,7 @@ export const useCredentialEventsTracking = ({

if (failure.type === CredentialIssuanceFailureType.UNEXPECTED) {
const reasonToTrack = shouldSerializeReason(failure)
? serializeFailureReason(failure)
? serializeFailureReason(failure, origin)
: failure;

return trackAddCredentialUnexpectedFailure({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type Params = {
identification?: IdentificationContext;
};

// Origin generic string for mixpanel tracking
const origin = "ITW_EID_EVENTS_TRACKING";
/**
* Track errors occurred during the eID issuance process for analytics.
*/
Expand Down Expand Up @@ -74,7 +76,7 @@ export const useEidEventsTracking = ({ failure, identification }: Params) => {
*/
return trackItwIdRequestUnexpectedFailure(
shouldSerializeReason(failure)
? serializeFailureReason(failure)
? serializeFailureReason(failure, origin)
: failure
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ import { hasGivenConsentSelector } from "../machine/selectors";
type Params = {
failure: ProximityFailure;
};
// Define a constant origin for mixpanel tracking purposes
const origin = "ITW_PROXIMITY_EVENTS_TRACKING";

/**
* Track errors occurred during the proximity presentation flow for analytics.
*/

export const useItwProximityEventsTracking = ({ failure }: Params) => {
const hasGivenConsent = ItwProximityMachineContext.useSelector(
hasGivenConsentSelector
);
useEffect(() => {
const serializedFailure = serializeFailureReason(failure);
const serializedFailure = serializeFailureReason(failure, origin);
switch (failure.type) {
case ProximityFailureType.RELYING_PARTY_GENERIC:
return trackItwProximityRPGenericFailure({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ const extractTrackingData = (credentials: Array<string>) => ({
count: credentials.length
});

const origin = "ITW_REMOTE_EVENTS_TRACKING";
/**
* Track errors occurred during the remote presentation flow for analytics.
*/
export const useItwRemoteEventsTracking = ({ failure }: Params) => {
useEffect(() => {
const serializedFailure = serializeFailureReason(failure);
const serializedFailure = serializeFailureReason(failure, origin);
switch (failure.type) {
case RemoteFailureType.WALLET_INACTIVE:
return trackItwUpgradeL3Mandatory(ItwL3UpgradeTrigger.REMOTE_QR_CODE);
Expand Down
Loading