CASH-2934: Allow multiple success events. Added additional event for phone number.

This commit is contained in:
credelinghuys 2026-07-10 08:58:32 -04:00
parent cd31fe8028
commit 2b337b41e4
3 changed files with 58 additions and 11 deletions

View file

@ -87,18 +87,36 @@ export default {
}).then(
(response) => {
if (logApiCall) {
let additionalEventData = "";
if (additionalSuccessEventDataHandler) {
additionalEventData = "_" + additionalSuccessEventDataHandler(response);
}
const endpointWithoutParams =
analyticsMixIn.methods.removeParamsFromEndpoint(endpoint);
analyticsMixIn.methods.pushEventToGA(
GaCategories.API_RESPONSE,
`${pageNameToLog}_${endpointWithoutParams}`,
`${GaLabels.SUCCESS}${additionalEventData}`,
true
);
const gaAction = `${pageNameToLog}_${endpointWithoutParams}`;
if (additionalSuccessEventDataHandler) {
const handlerResult = additionalSuccessEventDataHandler(response);
const additionalEntries = Array.isArray(handlerResult)
? handlerResult
: [handlerResult];
additionalEntries.forEach((entry) => {
if (entry === undefined || entry === null || entry === "") {
return;
}
analyticsMixIn.methods.pushEventToGA(
GaCategories.API_RESPONSE,
gaAction,
`${GaLabels.SUCCESS}_${entry}`,
true
);
});
} else {
analyticsMixIn.methods.pushEventToGA(
GaCategories.API_RESPONSE,
gaAction,
GaLabels.SUCCESS,
true
);
}
}
return resolve(response);

View file

@ -30,6 +30,33 @@ it("Global Methods - Call Http Client - Should Resolve Promise", () => {
});
});
it("Global Methods - Call Http Client - Should log multiple success event entries", async () => {
const endpoint = "https://mock.safelite.com";
const httpArgs = setupMocksForHttpClient({ endpoint: endpoint });
httpArgs.additionalSuccessEventDataHandler = () => [
"Email provided: true",
"Phone provided: false",
];
analyticsMixIn.methods.pushEventToGA = jest.fn();
analyticsMixIn.methods.removeParamsFromEndpoint = jest.fn((url) => url);
await globalMethods.callHttpClient(httpArgs);
expect(analyticsMixIn.methods.pushEventToGA).toHaveBeenCalledTimes(2);
expect(analyticsMixIn.methods.pushEventToGA).toHaveBeenCalledWith(
"Api_Response",
expect.any(String),
"Success_Email provided: true",
true
);
expect(analyticsMixIn.methods.pushEventToGA).toHaveBeenCalledWith(
"Api_Response",
expect.any(String),
"Success_Phone provided: false",
true
);
});
it("Global Methods - Call Http Client - Should Reject Promise", () => {
//Arrange
const endpoint = "https://mock.safelite.com";

View file

@ -2940,8 +2940,10 @@ export const actions = {
},
logApiCall: true,
pageNameToLog: pageNameToLog,
additionalSuccessEventDataHandler: (response) =>
additionalSuccessEventDataHandler: (response) => [
"Email provided: " + (order.customer.emailAddress ? "true" : "false"),
"Phone provided: " + (order.customer.phoneNumber ? "true" : "false"),
],
});
},