Skip to content

Commit 559a41f

Browse files
committed
feat: [AB#16656] refactor api_submit analytics
1 parent f3b6c85 commit 559a41f

File tree

7 files changed

+69
-5
lines changed

7 files changed

+69
-5
lines changed

web/src/components/tasks/anytime-action/tax-clearance-certificate/steps/Review.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,21 @@ export const Review = (props: Props): ReactElement => {
122122
const taxClearanceResponse = await api.postTaxClearanceCertificate(userData);
123123
if ("error" in taxClearanceResponse) {
124124
analytics.event.tax_clearance.submit.validation_error();
125+
analytics.event.api_submit.error(
126+
"treasury.taxation.tax_clearance_submission",
127+
taxClearanceResponse.error.message,
128+
);
125129
props.setResponseErrorType(taxClearanceResponse.error.type);
126130
return;
127131
}
128132

129133
if (taxClearanceResponse.certificatePdfArray) {
130134
analytics.event.tax_clearance.appears.validation_success();
135+
analytics.event.api_submit.success(
136+
"treasury.taxation.tax_clearance_submission",
137+
"successfully submitted tax clearance certificate",
138+
);
139+
131140
const blob = new Blob(
132141
[
133142
new Uint8Array(
@@ -144,6 +153,10 @@ export const Review = (props: Props): ReactElement => {
144153
}
145154
} catch {
146155
analytics.event.tax_clearance.submit.validation_error();
156+
analytics.event.api_submit.error(
157+
"treasury.taxation.tax_clearance_submission",
158+
"there was an issue submitting tax clearance",
159+
);
147160
props.setResponseErrorType("SYSTEM_ERROR");
148161
} finally {
149162
setIsLoading(false);

web/src/components/tasks/business-formation/BusinessFormationPaginator.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,17 @@ export const BusinessFormationPaginator = (): ReactElement => {
335335
router
336336
) {
337337
analytics.event.business_formation.submit.go_to_NIC_formation_processing();
338+
analytics.event.api_submit.success(
339+
"treasury.revenue.formation_submission",
340+
"successfully submitted formation",
341+
);
338342
await router.replace(newBusiness.formationData.formationResponse.redirect);
339343
} else {
340344
analytics.event.business_formation.submit.error_remain_at_formation();
345+
analytics.event.api_submit.error(
346+
"treasury.revenue.formation_submission",
347+
"error submitting formation",
348+
);
341349
setIsLoading(false);
342350
}
343351
};

web/src/components/tasks/cigarette-license/CigaretteLicenseReview.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,20 @@ export const CigaretteLicenseReview = (props: Props): ReactElement => {
257257
},
258258
})
259259
.update();
260+
analytics.event.api_submit.success(
261+
"treasury.revenue.cigarette_prepare_payment",
262+
"successfully prepared payment for cigarette license",
263+
);
260264
await router.replace(cigaretteLicenseResponse.paymentInfo?.htmL5RedirectUrl);
261265
}
262266
}
263267
} catch {
264268
setLoading(false);
265269
analytics.event.cigarette_license.submit.service_error();
270+
analytics.event.api_submit.error(
271+
"treasury.revenue.cigarette_prepare_payment",
272+
"error preparing payment for cigarette license",
273+
);
266274
props.setSubmissionError("UNAVAILABLE");
267275
setTimeout(() => {
268276
if (props.errorAlertRef.current) {

web/src/components/tasks/cigarette-license/Confirmation.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ export const ConfirmationPage = (props: Props): ReactElement => {
115115

116116
if (status === "CONFIRMED") {
117117
analytics.event.cigarette_license.appears.validation_success();
118+
analytics.event.api_submit.success(
119+
"treasury.revenue.cigarette_submission",
120+
"successfully submitted cigarette license",
121+
);
118122
return (
119123
<>
120124
<div className="maxw-tablet margin-x-auto">

web/src/lib/data-hooks/useBusinessNameSearch.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,18 @@ export const useBusinessNameSearch = ({
130130
});
131131
}
132132
setNameAvailability({ ...result });
133+
analytics.event.api_submit.success(
134+
"treasury.revenue.formation_submission",
135+
"name is available",
136+
);
133137
return { nameAvailability: result, submittedName: currentName };
134138
})
135139
.catch((api_error) => {
136140
resetState();
137141
setIsLoading(false);
138-
if (api_error === 400) {
139-
setError("BAD_INPUT");
140-
} else {
141-
setError("SEARCH_FAILED");
142-
}
142+
const errorMessage = api_error === 400 ? "BAD_INPUT" : "SEARCH_FAILED";
143+
setError(errorMessage);
144+
analytics.event.api_submit.error("treasury.revenue.formation_submission", errorMessage);
143145
throw new Error("ERROR");
144146
});
145147
};

web/src/lib/utils/analytics-legacy.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1+
export type LegacyEventApiName =
2+
| "treasury.revenue.check_name"
3+
| "treasury.revenue.formation_submission"
4+
| "treasury.taxation.tax_clearance_submission"
5+
| "treasury.revenue.cigarette_prepare_payment"
6+
| "treasury.revenue.cigarette_submission";
7+
18
export type LegacyEventCategory =
9+
| LegacyEventApiName
210
| "account_menu_myNJ_account"
311
| "account_menu_my_profile"
412
| "account_name"
@@ -193,6 +201,8 @@ export type LegacyEventAction =
193201
| "response"
194202
| "scroll"
195203
| "submit"
204+
| "api_submit_success"
205+
| "api_submit_error"
196206
| string;
197207

198208
export type LegacyEventLabel =

web/src/lib/utils/analytics.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable @typescript-eslint/explicit-function-return-type */
22
import {
33
LegacyEventAction,
4+
LegacyEventApiName,
45
LegacyEventCategory,
56
LegacyEventLabel,
67
} from "@/lib/utils/analytics-legacy";
@@ -885,6 +886,24 @@ export default {
885886
},
886887
},
887888
},
889+
api_submit: {
890+
success: (apiName: LegacyEventApiName, apiDetails?: string) => {
891+
eventRunner.track({
892+
event: "form_submits",
893+
legacy_event_category: apiName,
894+
legacy_event_action: "api_submit_success",
895+
legacy_event_label: apiDetails,
896+
});
897+
},
898+
error: (api_name: string, api_details?: string) => {
899+
eventRunner.track({
900+
event: "form_submits",
901+
legacy_event_category: api_name,
902+
legacy_event_action: "api_submit_error",
903+
legacy_event_label: api_details,
904+
});
905+
},
906+
},
888907
profile_save: {
889908
click: {
890909
save_profile_changes: () => {

0 commit comments

Comments
 (0)