Skip to content

Commit

Permalink
feat: [#173517663] changes the bonusavacanze events dispatched to mix…
Browse files Browse the repository at this point in the history
…panel for troubleshooting (#1963)
  • Loading branch information
fabriziofff authored Jun 26, 2020
1 parent dedb9ea commit 50d77c2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 54 deletions.
46 changes: 24 additions & 22 deletions ts/features/bonusVacanze/utils/bonus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import { fromNullable, Option } from "fp-ts/lib/Option";
import { ITuple2, Tuple2 } from "italia-ts-commons/lib/tuples";
import { BonusActivationStatusEnum } from "../../../../definitions/bonus_vacanze/BonusActivationStatus";
import { BonusActivationWithQrCode } from "../../../../definitions/bonus_vacanze/BonusActivationWithQrCode";
import { EligibilityCheckSuccessEligible } from "../../../../definitions/bonus_vacanze/EligibilityCheckSuccessEligible";
import { format, formatDateAsLocal } from "../../../utils/dates";
import { formatDateAsLocal } from "../../../utils/dates";
import { addEvery } from "../../../utils/strings";
import { EligibilityCheckPayload } from "../store/actions/bonusVacanze";
import {
BonusVacanzeActivationPayload,
EligibilityCheckPayload
} from "../store/actions/bonusVacanze";
import { BonusActivationProgressEnum } from "../store/reducers/activation";
import { EligibilityRequestProgressEnum } from "../store/reducers/eligibility";

export const ID_BONUS_VACANZE_TYPE = 1;

Expand Down Expand Up @@ -40,24 +44,22 @@ export const getBonusCodeFormatted = (
bonus: BonusActivationWithQrCode
): string => addEvery(bonus.id, " ", 4).trim();

export const getAnalyticsBonusRepresentation = (
bonus: BonusActivationWithQrCode
) => ({
bonus_status: bonus.status,
created_at: format(bonus.created_at),
redeemed_at: bonus.redeemed_at ? format(bonus.redeemed_at) : "-"
});
const allowedEligibilityStatus = new Set([
EligibilityRequestProgressEnum.ERROR,
EligibilityRequestProgressEnum.TIMEOUT,
EligibilityRequestProgressEnum.BONUS_ACTIVATION_PENDING
]);

export const getAnalyticsEligibilityRepresentation = (
export const isEligibilityResponseTrackable = (
eligibility: EligibilityCheckPayload
) =>
EligibilityCheckSuccessEligible.is(eligibility)
? {
id: eligibility.id,
max_amount: eligibility.dsu_request.max_amount,
max_tax_benefit: eligibility.dsu_request.max_tax_benefit,
has_discrepancies: eligibility.dsu_request.has_discrepancies,
dsu_created_at: eligibility.dsu_request.dsu_created_at,
family_members_count: eligibility.dsu_request.family_members.length
}
: {};
) => allowedEligibilityStatus.has(eligibility.status);

const allowedActivationStatus = new Set([
BonusActivationProgressEnum.ERROR,
BonusActivationProgressEnum.TIMEOUT,
BonusActivationProgressEnum.SUCCESS
]);

export const isActivationResponseTrackable = (
eligibility: BonusVacanzeActivationPayload
) => allowedActivationStatus.has(eligibility.status);
47 changes: 15 additions & 32 deletions ts/store/middlewares/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ import {
activateBonusVacanze,
cancelBonusVacanzeRequest,
checkBonusVacanzeEligibility,
completeBonusVacanzeActivation,
loadAllBonusActivations,
loadAvailableBonuses,
loadBonusVacanzeFromId,
storeEligibilityRequestId
} from "../../features/bonusVacanze/store/actions/bonusVacanze";
import {
getAnalyticsBonusRepresentation,
getAnalyticsEligibilityRepresentation
isActivationResponseTrackable,
isEligibilityResponseTrackable
} from "../../features/bonusVacanze/utils/bonus";
import { mixpanel } from "../../mixpanel";
import { getCurrentRouteName } from "../../utils/navigation";
Expand Down Expand Up @@ -239,8 +237,6 @@ const trackAction = (mp: NonNullable<typeof mixpanel>) => (
case getType(logoutFailure):
case getType(loadServiceDetail.failure):
case getType(loadServiceMetadata.failure):
// bonus vacanze
case getType(loadBonusVacanzeFromId.failure):
return mp.track(action.type, {
reason: action.payload.error.message
});
Expand Down Expand Up @@ -371,38 +367,25 @@ const trackAction = (mp: NonNullable<typeof mixpanel>) => (
case getType(loadAvailableBonuses.success):
case getType(loadAvailableBonuses.request):
case getType(checkBonusVacanzeEligibility.request):
case getType(activateBonusVacanze.request):
case getType(cancelBonusVacanzeRequest):
case getType(completeBonusVacanzeActivation):
case getType(loadBonusVacanzeFromId.request):
case getType(storeEligibilityRequestId):
return mp.track(action.type);

// bonus vacanze
case getType(checkBonusVacanzeEligibility.success):
const dsuPayload = getAnalyticsEligibilityRepresentation(action.payload);

return mp.track(action.type, {
status: action.payload.status,
...dsuPayload
});
case getType(storeEligibilityRequestId):
return mp.track(action.type, {
id: action.payload.id
});
if (isEligibilityResponseTrackable(action.payload)) {
return mp.track(action.type, {
status: action.payload.status
});
}
break;
case getType(activateBonusVacanze.success):
const bonus = action.payload.activation
? getAnalyticsBonusRepresentation(action.payload.activation)
: {};

return mp.track(action.type, {
status: action.payload.status,
...bonus
});
case getType(loadBonusVacanzeFromId.success):
return mp.track(
action.type,
getAnalyticsBonusRepresentation(action.payload)
);
if (isActivationResponseTrackable(action.payload)) {
return mp.track(action.type, {
status: action.payload.status
});
}
break;
}
return Promise.resolve();
};
Expand Down

0 comments on commit 50d77c2

Please sign in to comment.