Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
12 changes: 7 additions & 5 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 @@ -85,9 +86,10 @@ 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
* Instead of sending a plain string, we return a structured object with a code, errorDescription and an origin.
*/
const createReasonObject = (message: string) => ({
const createReasonObject = (message: string, origin?: string) => ({
code: "UNEXPECTED",
errorDescription: message
errorDescription: message,
origin
});
2 changes: 1 addition & 1 deletion ts/features/itwallet/identification/analytics/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export type TrackItWalletCieCardReadingFailure = {
};

export type TrackItWalletCieCardReadingUnexpectedFailure = {
reason: string | undefined;
reason: string | unknown | undefined;
cie_reading_progress: number;
itw_flow: ItwFlow;
ITW_ID_method?: ItwIdMethod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ type ItwCieCardReadFailureContentProps = Extract<
export const ItwCieCardReadFailureContent = ({
failure,
progress,
onRetry
onRetry,
origin
}: ItwCieCardReadFailureContentProps) => {
const issuanceActor = ItwEidIssuanceMachineContext.useActorRef();
const isL3 = ItwEidIssuanceMachineContext.useSelector(
Expand All @@ -64,8 +65,14 @@ export const ItwCieCardReadFailureContent = ({
useFocusEffect(
useCallback(
() =>
trackError({ failure, isL3, identification, readProgress: progress }),
[failure, isL3, progress, identification]
trackError({
failure,
isL3,
identification,
readProgress: progress,
origin
}),
[failure, isL3, progress, identification, origin]
)
);

Expand Down Expand Up @@ -228,13 +235,15 @@ type TrackErrorParams = {
isL3: boolean;
readProgress?: number;
identification?: IdentificationContext;
origin?: string;
};

const trackError = ({
failure,
isL3,
readProgress,
identification
identification,
origin
}: TrackErrorParams) => {
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 @@ -306,7 +315,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,
itw_flow,
ITW_ID_method: identification?.mode
Expand Down
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 @@ -208,7 +218,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 @@ -26,6 +26,7 @@ type Params = {
/**
* Track errors occurred during the credential issuance process for analytics.
*/

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

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

return trackAddCredentialUnexpectedFailure({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ export const useEidEventsTracking = ({
*/
return trackItwIdRequestUnexpectedFailure(
shouldSerializeReason(failure)
? { ...serializeFailureReason(failure), itw_flow: itwFlow }
? {
...serializeFailureReason(failure, "ITW_EID_EVENTS_TRACKING"),
itw_flow: itwFlow
}
: { ...failure, itw_flow: itwFlow }
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ type Params = {
/**
* 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,
"ITW_PROXIMITY_EVENTS_TRACKING"
);
switch (failure.type) {
case ProximityFailureType.RELYING_PARTY_GENERIC:
return trackItwProximityRPGenericFailure({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ const extractTrackingData = (credentials: Array<string>) => ({
*/
export const useItwRemoteEventsTracking = ({ failure }: Params) => {
useEffect(() => {
const serializedFailure = serializeFailureReason(failure);
const serializedFailure = serializeFailureReason(
failure,
"ITW_REMOTE_EVENTS_TRACKING"
);
switch (failure.type) {
case RemoteFailureType.WALLET_INACTIVE:
return trackItwUpgradeL3Mandatory(ItwL3UpgradeTrigger.REMOTE_QR_CODE);
Expand Down
Loading