CASH-2934: Allow multiple success events. Added additional event for phone number.
This commit is contained in:
parent
cd31fe8028
commit
2b337b41e4
3 changed files with 58 additions and 11 deletions
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -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";
|
||||||
|
|
|
||||||
|
|
@ -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"),
|
||||||
|
],
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue