Skip to content

Commit

Permalink
feat(Bonus Pagamenti Digitali): [#176291649] Track ranking api on Mix…
Browse files Browse the repository at this point in the history
…panel (#2655)

* [#176291649] track ranking api on mixpanel

* Update ts/features/bonus/bpd/saga/networking/ranking.ts

Co-authored-by: Matteo Boschi <[email protected]>

Co-authored-by: Matteo Boschi <[email protected]>
  • Loading branch information
fabriziofff and Undermaken authored Dec 29, 2020
1 parent 2d4a382 commit b7b54c2
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ts/features/bonus/bpd/saga/networking/ranking.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { Either, left, right } from "fp-ts/lib/Either";
import { call, Effect } from "redux-saga/effects";
import { readableReport } from "italia-ts-commons/lib/reporters";
import { mixpanelTrack } from "../../../../../mixpanel";
import { BpdRankingReady } from "../../store/reducers/details/periods";
import { BackendBpdClient } from "../../api/backendBpdClient";
import { SagaCallReturnType } from "../../../../../types/utils";
import { AwardPeriodId } from "../../store/actions/periods";
import { getError } from "../../../../../utils/errors";
import { CitizenRankingResourceArray } from "../../../../../../definitions/bpd/citizen/CitizenRankingResourceArray";

const mixpanelActionRequest = "BPD_RANKING_REQUEST";
const mixpanelActionSuccess = "BPD_RANKING_SUCCESS";
const mixpanelActionFailure = "BPD_RANKING_FAILURE";

// convert the network payload ranking into the relative app domain model
const convertRankingArray = (
rankings: CitizenRankingResourceArray
Expand All @@ -23,12 +28,16 @@ export function* bpdLoadRaking(
getRanking: ReturnType<typeof BackendBpdClient>["getRanking"]
): Generator<Effect, Either<Error, ReadonlyArray<BpdRankingReady>>, any> {
try {
void mixpanelTrack(mixpanelActionRequest);
const getRankingResult: SagaCallReturnType<typeof getRanking> = yield call(
getRanking,
{} as any
);
if (getRankingResult.isRight()) {
if (getRankingResult.value.status === 200) {
void mixpanelTrack(mixpanelActionSuccess, {
count: getRankingResult.value.value?.length
});
return right<Error, ReadonlyArray<BpdRankingReady>>(
convertRankingArray(getRankingResult.value.value)
);
Expand All @@ -43,6 +52,9 @@ export function* bpdLoadRaking(
);
}
} catch (e) {
void mixpanelTrack(mixpanelActionFailure, {
reason: getError(e).message
});
return left<Error, ReadonlyArray<BpdRankingReady>>(getError(e));
}
}

0 comments on commit b7b54c2

Please sign in to comment.