Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Bonus Pagamenti Digitali): [#175883179] track satispay actions #2582

Merged
merged 7 commits into from
Dec 14, 2020
45 changes: 45 additions & 0 deletions ts/features/wallet/satispay/analytics/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { getType } from "typesafe-actions";
import { mixpanel } from "../../../../mixpanel";
import { Action } from "../../../../store/actions/types";
import { isTimeoutError } from "../../../../utils/errors";
import {
addSatispayToWallet,
searchUserSatispay,
walletAddSatispayBack,
walletAddSatispayCancel,
walletAddSatispayCompleted,
walletAddSatispayStart
} from "../../onboarding/satispay/store/actions";

const trackAction = (mp: NonNullable<typeof mixpanel>) => (
action: Action
): Promise<any> => {
switch (action.type) {
case getType(searchUserSatispay.request):
case getType(walletAddSatispayStart):
case getType(walletAddSatispayCompleted):
case getType(walletAddSatispayCancel):
case getType(walletAddSatispayBack):
case getType(addSatispayToWallet.request):
case getType(addSatispayToWallet.success):
return mp.track(action.type);

case getType(searchUserSatispay.success):
return mp.track(action.type, {
count: action.payload !== undefined ? 1 : 0
});

case getType(searchUserSatispay.failure):
return mp.track(action.type, {
reason: isTimeoutError(action.payload)
? action.payload.kind
: action.payload.value.message
});

case getType(addSatispayToWallet.failure):
return mp.track(action.type, { reason: action.payload.message });
}
return Promise.resolve();
};

export default trackAction;
2 changes: 2 additions & 0 deletions ts/store/middlewares/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ import {
} from "../actions/wallet/wallets";

import trackBpdAction from "../../features/bonus/bpd/analytics/index";
import trackSatispayAction from "../../features/wallet/satispay/analytics/index";

// eslint-disable-next-line complexity
const trackAction = (mp: NonNullable<typeof mixpanel>) => (
Expand Down Expand Up @@ -431,6 +432,7 @@ export const actionTracking = (_: MiddlewareAPI) => (next: Dispatch) => (
// API token
trackAction(mixpanel)(action).then(constNull, constNull);
trackBpdAction(mixpanel)(action).then(constNull, constNull);
trackSatispayAction(mixpanel)(action).then(constNull, constNull);
}
return next(action);
};
Expand Down