Skip to content
Snippets Groups Projects
Commit 19b58b0b authored by Allen Gilliland's avatar Allen Gilliland
Browse files

Merge pull request #2511 from metabase/saved-questions-analytics

Instrumentation for saved questions + labels
parents ea5eba06 f6e1fdb5
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,8 @@ import { AngularResourceProxy, createAction, createThunkAction } from "metabase/
import { reset } from 'redux-form';
import { normalize, Schema, arrayOf } from 'normalizr';
import MetabaseAnalytics from "metabase/lib/analytics";
const label = new Schema('labels');
const LabelApi = new AngularResourceProxy("Label", ["list", "create", "update", "delete"]);
......@@ -26,8 +28,10 @@ export const saveLabel = createThunkAction(SAVE_LABEL, (values) => {
try {
let response;
if (values.id == null) {
MetabaseAnalytics.trackEvent("Labels", "Create");
response = await LabelApi.create(values);
} else {
MetabaseAnalytics.trackEvent("Labels", "Update");
response = await LabelApi.update(values);
}
if (response.id != null) {
......@@ -50,6 +54,7 @@ export const saveLabel = createThunkAction(SAVE_LABEL, (values) => {
export const deleteLabel = createThunkAction(DELETE_LABEL, (id) => {
return async (dispatch, getState) => {
try {
MetabaseAnalytics.trackEvent("Labels", "Delete");
await LabelApi.delete({ id });
return id;
} catch (e) {
......
......@@ -6,6 +6,7 @@ import i from "icepick";
import _ from "underscore";
import { inflect } from "metabase/lib/formatting";
import MetabaseAnalytics from "metabase/lib/analytics";
import { getVisibleEntities, getSelectedEntities } from "./selectors";
import { addUndo } from "./undo";
......@@ -71,6 +72,7 @@ export const setFavorited = createThunkAction(SET_FAVORITED, (cardId, favorited)
} else {
await CardApi.unfavorite({ cardId });
}
MetabaseAnalytics.trackEvent("Questions", favorited ? "Favorite" : "Unfavorite");
return { id: cardId, favorite: favorited };
}
});
......@@ -96,6 +98,7 @@ export const setArchived = createThunkAction(SET_ARCHIVED, (cardId, archived, un
archived ? "archived" : "unarchived",
selected.map(item => setArchived(item.id, !archived))
)));
MetabaseAnalytics.trackEvent("Questions", archived ? "Bulk Archive" : "Bulk Unarchive", selected.length);
}
} else {
let card = {
......@@ -108,6 +111,7 @@ export const setArchived = createThunkAction(SET_ARCHIVED, (cardId, archived, un
archived ? "archived" : "unarchived",
[setArchived(cardId, !archived)]
)));
MetabaseAnalytics.trackEvent("Questions", archived ? "Archive" : "Unarchive");
}
return response;
}
......@@ -126,6 +130,7 @@ export const setLabeled = createThunkAction(SET_LABELED, (cardId, labelId, label
labeled ? "labeled" : "unlabeled",
selected.map(item => setLabeled(item.id, labelId, !labeled))
)));
MetabaseAnalytics.trackEvent("Questions", labeled ? "Bulk Apply Label" : "Bulk Remove Label", selected.length);
}
} else {
const state = getState();
......@@ -142,6 +147,7 @@ export const setLabeled = createThunkAction(SET_LABELED, (cardId, labelId, label
labeled ? "labeled" : "unlabeled",
[setLabeled(cardId, labelId, !labeled)]
)));
MetabaseAnalytics.trackEvent("Questions", labeled ? "Apply Label" : "Remove Label");
}
return { id: cardId, labels: newLabels, _changedLabelSlug: labelSlug, _changedLabeled: labeled };
}
......@@ -154,12 +160,14 @@ export const setItemSelected = createAction(SET_ITEM_SELECTED);
export const setAllSelected = createThunkAction(SET_ALL_SELECTED, (selected) => {
return async (dispatch, getState) => {
const visibleEntities = getVisibleEntities(getState());
let selectedIds = {}
if (selected) {
for (let entity of getVisibleEntities(getState())) {
for (let entity of visibleEntities) {
selectedIds[entity.id] = true;
}
}
MetabaseAnalytics.trackEvent("Questions", selected ? "Select All" : "Unselect All", visibleEntities.length);
return selectedIds;
}
});
......
import { createAction, createThunkAction } from "metabase/lib/redux";
import MetabaseAnalytics from "metabase/lib/analytics";
import _ from "underscore";
const ADD_UNDO = 'metabase/questions/ADD_UNDO';
......@@ -12,21 +14,27 @@ let nextUndoId = 0;
export const addUndo = createThunkAction(ADD_UNDO, (undo) => {
return (dispatch, getState) => {
let id = nextUndoId++;
setTimeout(() => dispatch(dismissUndo(id)), 5000);
setTimeout(() => dispatch(dismissUndo(id, false)), 5000);
return { ...undo, id, _domId: id };
};
});
export const dismissUndo = createAction(DISMISS_UNDO);
export const dismissUndo = createAction(DISMISS_UNDO, (undoId, track = true) => {
if (track) {
MetabaseAnalytics.trackEvent("Undo", "Dismiss Undo");
}
return undoId;
});
export const performUndo = createThunkAction(PERFORM_UNDO, (undoId) => {
return (dispatch, getState) => {
MetabaseAnalytics.trackEvent("Undo", "Perform Undo");
let undo = _.findWhere(getState().undo, { id: undoId });
if (undo) {
undo.actions.map(action =>
dispatch(action)
);
dispatch(dismissUndo(undoId));
dispatch(dismissUndo(undoId, false));
}
};
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment