|
| 1 | +import axios from "axios"; |
| 2 | +import { errorHandler } from "../utils/errorHandler"; |
| 3 | +import { setRequestStatus } from "../utils/setRequestStatus"; |
| 4 | +import { |
| 5 | + GET_BROWSER_ANALYTICS, |
| 6 | + GET_COUNTRY_ANALYTICS, |
| 7 | + GET_DEVICE_ANALYTICS, |
| 8 | + GET_MOSTVIEWED_ANALYTICS, |
| 9 | + GET_PROPOSALVIEW_ANALYTICS |
| 10 | +} from "../actions/types"; |
| 11 | +import moment from "moment"; |
| 12 | + |
| 13 | +// GET BROWSER ANALYTICS |
| 14 | +export const getBrowserAnalytics = ( |
| 15 | + startingDate, |
| 16 | + endingDate, |
| 17 | + proposalId |
| 18 | +) => async (dispatch) => { |
| 19 | + try { |
| 20 | + let data = { |
| 21 | + startDate: moment(startingDate).format("YYYY-MM-DD"), |
| 22 | + endDate: moment(endingDate).format("YYYY-MM-DD"), |
| 23 | + proposalId: proposalId, |
| 24 | + }; |
| 25 | + const res = await axios.post("/analytics/browser", data); |
| 26 | + dispatch(setRequestStatus(false)); |
| 27 | + if (res.status === 200) { |
| 28 | + dispatch(setRequestStatus(true)); |
| 29 | + dispatch({ |
| 30 | + type: GET_BROWSER_ANALYTICS, |
| 31 | + payload: res.data.analytics || res.data.msg, |
| 32 | + }); |
| 33 | + } |
| 34 | + } catch (error) { |
| 35 | + dispatch(errorHandler(error)); |
| 36 | + } |
| 37 | +}; |
| 38 | + |
| 39 | +// GET MOSTVIEWED ANALYTICS |
| 40 | +export const getMostViewedAnalytics = (startingDate, endingDate) => async ( |
| 41 | + dispatch |
| 42 | +) => { |
| 43 | + try { |
| 44 | + let data = { |
| 45 | + startDate: moment(startingDate).format("YYYY-MM-DD"), |
| 46 | + endDate: moment(endingDate).format("YYYY-MM-DD"), |
| 47 | + }; |
| 48 | + const res = await axios.post("/analytics/mostviewed", data); |
| 49 | + dispatch(setRequestStatus(false)); |
| 50 | + if (res.status === 200) { |
| 51 | + dispatch(setRequestStatus(true)); |
| 52 | + dispatch({ |
| 53 | + type: GET_MOSTVIEWED_ANALYTICS, |
| 54 | + payload: res.data.analytics || res.data.msg, |
| 55 | + }); |
| 56 | + } |
| 57 | + } catch (error) { |
| 58 | + dispatch(errorHandler(error)); |
| 59 | + } |
| 60 | +}; |
| 61 | + |
| 62 | +// GET PROPOSAL VIEW ANALYTICS |
| 63 | +export const getProposalviewAnalytics = ( |
| 64 | + startingDate, |
| 65 | + endingDate, |
| 66 | + proposalId |
| 67 | + ) => async (dispatch) => { |
| 68 | + try { |
| 69 | + let data = { |
| 70 | + startDate: moment(startingDate).format("YYYY-MM-DD"), |
| 71 | + endDate: moment(endingDate).format("YYYY-MM-DD"), |
| 72 | + proposalId: proposalId, |
| 73 | + }; |
| 74 | + const res = await axios.post("/analytics/views", data); |
| 75 | + dispatch(setRequestStatus(false)); |
| 76 | + if (res.status === 200) { |
| 77 | + dispatch(setRequestStatus(true)); |
| 78 | + console.log(res.data.analytics) |
| 79 | + dispatch({ |
| 80 | + type: GET_PROPOSALVIEW_ANALYTICS, |
| 81 | + payload: res.data.analytics || res.data.msg, |
| 82 | + }); |
| 83 | + } |
| 84 | + } catch (error) { |
| 85 | + dispatch(errorHandler(error)); |
| 86 | + } |
| 87 | + }; |
| 88 | + |
| 89 | +// GET COUNTRIES ANALYTICS |
| 90 | +export const getCountryAnalytics = ( |
| 91 | + startingDate, |
| 92 | + endingDate, |
| 93 | + proposalId |
| 94 | +) => async (dispatch) => { |
| 95 | + try { |
| 96 | + let data = { |
| 97 | + startDate: moment(startingDate).format("YYYY-MM-DD"), |
| 98 | + endDate: moment(endingDate).format("YYYY-MM-DD"), |
| 99 | + proposalId: proposalId, |
| 100 | + }; |
| 101 | + const res = await axios.post("/analytics/countries", data); |
| 102 | + dispatch(setRequestStatus(false)); |
| 103 | + if (res.status === 200) { |
| 104 | + dispatch(setRequestStatus(true)); |
| 105 | + dispatch({ |
| 106 | + type: GET_COUNTRY_ANALYTICS, |
| 107 | + payload: res.data.analytics || res.data.msg, |
| 108 | + }); |
| 109 | + } |
| 110 | + } catch (error) { |
| 111 | + dispatch(errorHandler(error)); |
| 112 | + } |
| 113 | +}; |
| 114 | + |
| 115 | +// GET DEVICE ANALYTICS |
| 116 | +export const getDeviceAnalytics = ( |
| 117 | + startingDate, |
| 118 | + endingDate, |
| 119 | + proposalId |
| 120 | +) => async (dispatch) => { |
| 121 | + try { |
| 122 | + let data = { |
| 123 | + startDate: moment(startingDate).format("YYYY-MM-DD"), |
| 124 | + endDate: moment(endingDate).format("YYYY-MM-DD"), |
| 125 | + proposalId: proposalId, |
| 126 | + }; |
| 127 | + const res = await axios.post("/analytics/device", data); |
| 128 | + dispatch(setRequestStatus(false)); |
| 129 | + if (res.status === 200) { |
| 130 | + dispatch(setRequestStatus(true)); |
| 131 | + dispatch({ |
| 132 | + type: GET_DEVICE_ANALYTICS, |
| 133 | + payload: res.data.analytics || res.data.msg, |
| 134 | + }); |
| 135 | + } |
| 136 | + } catch (error) { |
| 137 | + dispatch(errorHandler(error)); |
| 138 | + } |
| 139 | +}; |
0 commit comments