Added first round of analytics and event tracking BOD-190

This commit is contained in:
Patrick Fic
2020-07-17 08:27:28 -07:00
parent 3f0394760a
commit a54a85b96c
73 changed files with 433 additions and 208 deletions

View File

@@ -2,23 +2,35 @@ import axios from "axios";
import phone from "phone";
import { all, call, put, select, takeLatest } from "redux-saga/effects";
import { client } from "../../App/App.container";
import { logImEXEvent } from "../../firebase/firebase.utils";
import {
CONVERSATION_ID_BY_PHONE,
CREATE_CONVERSATION,
} from "../../graphql/conversations.queries";
import { INSERT_CONVERSATION_TAG } from "../../graphql/job-conversations.queries";
import { selectBodyshop } from "../user/user.selectors";
import {
sendMessageFailure,
sendMessageSuccess,
setSelectedConversation,
} from "./messaging.actions";
import MessagingActionTypes from "./messaging.types";
import { selectBodyshop } from "../user/user.selectors";
export function* onToggleChatVisible() {
yield takeLatest(MessagingActionTypes.TOGGLE_CHAT_VISIBLE, toggleChatLogging);
}
export function* toggleChatLogging() {
try {
yield logImEXEvent("messaging_toggle_popup");
} catch (error) {
console.log("Error in sendMessage saga.", error);
}
}
export function* onOpenChatByPhone() {
yield takeLatest(MessagingActionTypes.OPEN_CHAT_BY_PHONE, openChatByPhone);
}
export function* openChatByPhone({ payload }) {
logImEXEvent("messaging_open_by_phone");
const { phone_num, jobid } = payload;
const bodyshop = yield select(selectBodyshop);
try {
@@ -69,6 +81,8 @@ export function* onSendMessage() {
}
export function* sendMessage({ payload }) {
try {
yield logImEXEvent("messaging_send_message");
const response = yield call(axios.post, "/sms/send", payload);
if (response.status === 200) {
yield put(sendMessageSuccess(payload));
@@ -82,5 +96,9 @@ export function* sendMessage({ payload }) {
}
export function* messagingSagas() {
yield all([call(onSendMessage), call(onOpenChatByPhone)]);
yield all([
call(onSendMessage),
call(onOpenChatByPhone),
call(onToggleChatVisible),
]);
}

View File

@@ -1,4 +1,5 @@
import ModalsActionTypes from "./modals.types";
import { logImEXEvent } from "../../firebase/firebase.utils";
const baseModal = {
visible: false,
@@ -24,6 +25,7 @@ const INITIAL_STATE = {
const modalsReducer = (state = INITIAL_STATE, action) => {
switch (action.type) {
case ModalsActionTypes.TOGGLE_MODAL_VISIBLE:
logImEXEvent("redux_toggle_modal_visible", { modal: action.payload });
return {
...state,
[action.payload]: {
@@ -32,6 +34,8 @@ const modalsReducer = (state = INITIAL_STATE, action) => {
},
};
case ModalsActionTypes.SET_MODAL_CONTEXT:
logImEXEvent("redux_set_modal_context", { modal: action.payload.modal });
return {
...state,
[action.payload.modal]: {

View File

@@ -3,30 +3,25 @@ import { all, call, put, select, takeLatest } from "redux-saga/effects";
import { selectBodyshop } from "../user/user.selectors";
import { techLoginFailure, techLoginSuccess } from "./tech.actions";
import TechActionTypes from "./tech.types";
import { logImEXEvent } from "../../firebase/firebase.utils";
export function* onSignInStart() {
yield takeLatest(TechActionTypes.TECH_LOGIN_START, signInStart);
}
export function* signInStart({ payload: { employeeid, pin } }) {
try {
logImEXEvent("redux_tech_sign_in");
const bodyshop = yield select(selectBodyshop);
const response = yield call(axios.post, "/tech/login", {
shopid: bodyshop.id,
employeeid: employeeid,
pin: pin,
});
console.log("response", response);
const { valid, technician, error } = response.data;
console.log(
"function*signInStart -> valid, technician, erro",
valid,
technician,
error
);
if (valid) {
console.log("Valid in else");
yield put(techLoginSuccess(technician));
} else {
yield put(techLoginFailure(error));

View File

@@ -1,24 +1,24 @@
import { all, call, put, takeLatest, delay, select } from "redux-saga/effects";
import LogRocket from "logrocket";
import { firestore } from "../../firebase/firebase.utils";
import Fingerprint2 from "fingerprintjs2";
import LogRocket from "logrocket";
import { all, call, delay, put, select, takeLatest } from "redux-saga/effects";
import {
auth,
firestore,
getCurrentUser,
logImEXEvent,
updateCurrentUser,
} from "../../firebase/firebase.utils";
import {
checkInstanceId,
setInstanceConflict,
setInstanceId,
setLocalFingerprint,
signInFailure,
signInSuccess,
signOutFailure,
signOutSuccess,
unauthorizedUser,
updateUserDetailsSuccess,
setInstanceId,
checkInstanceId,
setLocalFingerprint,
setInstanceConflict,
} from "./user.actions";
import UserActionTypes from "./user.types";
@@ -27,6 +27,8 @@ export function* onEmailSignInStart() {
}
export function* signInWithEmail({ payload: { email, password } }) {
try {
logImEXEvent("redux_sign_in_attempt", { user: email });
const { user } = yield auth.signInWithEmailAndPassword(email, password);
yield put(
@@ -40,6 +42,7 @@ export function* signInWithEmail({ payload: { email, password } }) {
);
} catch (error) {
yield put(signInFailure(error));
logImEXEvent("redux_sign_in_failure", { user: email, error });
}
}
@@ -48,6 +51,8 @@ export function* onCheckUserSession() {
}
export function* isUserAuthenticated() {
try {
logImEXEvent("redux_auth_check");
const user = yield getCurrentUser();
if (!user) {
yield put(unauthorizedUser());
@@ -73,6 +78,8 @@ export function* onSignOutStart() {
}
export function* signOutStart() {
try {
logImEXEvent("redux_sign_out");
yield auth.signOut();
yield put(signOutSuccess());
localStorage.removeItem("token");
@@ -135,6 +142,7 @@ export function* checkInstanceIdSaga({ payload: uid }) {
yield put(checkInstanceId(uid));
} else {
console.log("ERROR: Fingerprints do not match. Conflict detected.");
logImEXEvent("instance_confict");
yield put(setInstanceConflict());
}
} catch (error) {
@@ -150,6 +158,7 @@ export function* onSignInSuccess() {
export function* signInSuccessSaga({ payload }) {
LogRocket.identify(payload.email);
yield put(setInstanceId(payload.uid));
yield logImEXEvent("redux_sign_in_success");
}
export function* userSagas() {