From b7b54c2fc6e8b6f5e8c881822cc8d2d1018c9577 Mon Sep 17 00:00:00 2001 From: fabriziofff Date: Tue, 29 Dec 2020 18:21:50 +0100 Subject: [PATCH] feat(Bonus Pagamenti Digitali): [#176291649] Track ranking api on Mixpanel (#2655) * [#176291649] track ranking api on mixpanel * Update ts/features/bonus/bpd/saga/networking/ranking.ts Co-authored-by: Matteo Boschi Co-authored-by: Matteo Boschi --- ts/features/bonus/bpd/saga/networking/ranking.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ts/features/bonus/bpd/saga/networking/ranking.ts b/ts/features/bonus/bpd/saga/networking/ranking.ts index 6e787b4b736..ccf937bbfbb 100644 --- a/ts/features/bonus/bpd/saga/networking/ranking.ts +++ b/ts/features/bonus/bpd/saga/networking/ranking.ts @@ -1,6 +1,7 @@ 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"; @@ -8,6 +9,10 @@ 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 @@ -23,12 +28,16 @@ export function* bpdLoadRaking( getRanking: ReturnType["getRanking"] ): Generator>, any> { try { + void mixpanelTrack(mixpanelActionRequest); const getRankingResult: SagaCallReturnType = yield call( getRanking, {} as any ); if (getRankingResult.isRight()) { if (getRankingResult.value.status === 200) { + void mixpanelTrack(mixpanelActionSuccess, { + count: getRankingResult.value.value?.length + }); return right>( convertRankingArray(getRankingResult.value.value) ); @@ -43,6 +52,9 @@ export function* bpdLoadRaking( ); } } catch (e) { + void mixpanelTrack(mixpanelActionFailure, { + reason: getError(e).message + }); return left>(getError(e)); } }