Merge pull request #3260 from Safelite/feature/CASH-2934

Feature/CASH 2934
This commit is contained in:
Chris 2026-07-10 09:18:31 -04:00 committed by GitHub
commit fa97372c36
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 58 additions and 11 deletions

View file

@ -87,18 +87,36 @@ export default {
}).then( }).then(
(response) => { (response) => {
if (logApiCall) { if (logApiCall) {
let additionalEventData = "";
if (additionalSuccessEventDataHandler) {
additionalEventData = "_" + additionalSuccessEventDataHandler(response);
}
const endpointWithoutParams = const endpointWithoutParams =
analyticsMixIn.methods.removeParamsFromEndpoint(endpoint); analyticsMixIn.methods.removeParamsFromEndpoint(endpoint);
analyticsMixIn.methods.pushEventToGA( const gaAction = `${pageNameToLog}_${endpointWithoutParams}`;
GaCategories.API_RESPONSE,
`${pageNameToLog}_${endpointWithoutParams}`, if (additionalSuccessEventDataHandler) {
`${GaLabels.SUCCESS}${additionalEventData}`, const handlerResult = additionalSuccessEventDataHandler(response);
true 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); 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", () => { it("Global Methods - Call Http Client - Should Reject Promise", () => {
//Arrange //Arrange
const endpoint = "https://mock.safelite.com"; const endpoint = "https://mock.safelite.com";

View file

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