Skip to content

Commit

Permalink
chore: side by side analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
tihuan committed Jun 20, 2024
1 parent d0d9643 commit 96fc002
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 9 deletions.
7 changes: 7 additions & 0 deletions client/src/actions/embedding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import type { AppDispatch, GetState, RootState } from "../reducers";
import { _setEmbeddingSubset } from "../util/stateManager/viewStackHelpers";
import { Field } from "../common/types/schema";
import * as globals from "../globals";
import { track } from "../analytics";
import { EVENTS } from "../analytics/events";

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS.
async function _switchEmbedding(
Expand Down Expand Up @@ -109,6 +111,11 @@ export const swapLayoutChoicesAction: ActionCreator<
const mainLayoutChoice = layoutChoice.current;
const sideLayoutChoice = panelEmbedding.layoutChoice.current;

track(EVENTS.EXPLORER_SBS_SWAPPED, {
main_embedding: mainLayoutChoice,
window_embedding: sideLayoutChoice,
});

await dispatch(layoutChoiceAction(mainLayoutChoice, true));
await dispatch(layoutChoiceAction(sideLayoutChoice, false));
};
4 changes: 4 additions & 0 deletions client/src/analytics/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export enum EVENTS {
EXPLORER_RE_CENTER_EMBEDDING = "EXPLORER_RE_CENTER_EMBEDDING",
EXPLORER_ZOOMED = "EXPLORER_ZOOMED",
EXPLORER_PANNED = "EXPLORER_PANNED",
EXPLORER_SBS_SELECTED = "EXPLORER_SBS_SELECTED",
EXPLORER_SBS_SWAPPED = "EXPLORER_SBS_SWAPPED",
EXPLORER_SBS_SIDE_WINDOW_EMBEDDING_CLICKED = "EXPLORER_SBS_SIDE_WINDOW_EMBEDDING_CLICKED",
EXPLORER_SBS_SIDE_WINDOW_EMBEDDING_SELECTED = "EXPLORER_SBS_SIDE_WINDOW_EMBEDDING_SELECTED",

WMG_CLICK_NAV = "WMG_CLICK_NAV",
COLLECTIONS_CLICK_NAV = "COLLECTIONS_CLICK_NAV",
Expand Down
23 changes: 19 additions & 4 deletions client/src/components/embedding/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,24 @@ const Embedding = (props: Props) => {
const isSpatial = getFeatureFlag(FEATURES.SPATIAL);

const handleLayoutChoiceClick = (): void => {
track(EVENTS.EXPLORER_EMBEDDING_CLICKED);
track(
isSidePanel
? EVENTS.EXPLORER_SBS_SIDE_WINDOW_EMBEDDING_CLICKED
: EVENTS.EXPLORER_EMBEDDING_CLICKED
);
};

const handleLayoutChoiceChange = async (
e: FormEvent<HTMLInputElement>
): Promise<void> => {
track(EVENTS.EXPLORER_EMBEDDING_SELECTED, {
embedding: e.currentTarget.value,
});
track(
isSidePanel
? EVENTS.EXPLORER_SBS_SIDE_WINDOW_EMBEDDING_SELECTED
: EVENTS.EXPLORER_EMBEDDING_SELECTED,
{
embedding: e.currentTarget.value,
}
);

await dispatch(
actions.layoutChoiceAction(e.currentTarget.value, isSidePanel)
Expand All @@ -85,6 +94,12 @@ const Embedding = (props: Props) => {
dispatch({
type: "toggle panel embedding",
});

if (!sideIsOpen) {
track(EVENTS.EXPLORER_SBS_SELECTED, {
embedding: layoutChoice.current,
});
}
};

return (
Expand Down
27 changes: 22 additions & 5 deletions client/src/components/graph/graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ const mapStateToProps = (state: RootState, ownProps: OwnProps): StateProps => ({
mountCapture: state.controls.mountCapture,
imageUnderlay: state.controls.imageUnderlay,
config: state.config,
isSidePanelOpen: state.panelEmbedding.open,
sidePanelLayoutChoice: state.panelEmbedding.layoutChoice,
});

class Graph extends React.Component<GraphProps, GraphState> {
Expand Down Expand Up @@ -550,8 +552,15 @@ class Graph extends React.Component<GraphProps, GraphState> {
}

async handleImageDownload(regl: GraphState["regl"]) {
const { dispatch, screenCap, mountCapture, layoutChoice, colors } =
this.props;
const {
dispatch,
screenCap,
mountCapture,
layoutChoice,
colors,
isSidePanelOpen,
sidePanelLayoutChoice,
} = this.props;

if (!this.reglCanvas || !screenCap || !regl || this.isDownloadingImage) {
return;
Expand Down Expand Up @@ -638,9 +647,17 @@ class Graph extends React.Component<GraphProps, GraphState> {
if (categoricalLegendImageURI) {
downloadImage(categoricalLegendImageURI);
}
track(EVENTS.EXPLORER_DOWNLOAD_COMPLETE, {
embedding: layoutChoice.current,
});

track(
EVENTS.EXPLORER_DOWNLOAD_COMPLETE,
isSidePanelOpen
? {
embedding: layoutChoice.current,
side_by_side: sidePanelLayoutChoice?.current,
}
: { embedding: layoutChoice.current }
);

dispatch({ type: "graph: screencap end" });
}

Expand Down
2 changes: 2 additions & 0 deletions client/src/components/graph/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export interface StateProps {
mountCapture: RootState["controls"]["mountCapture"];
imageUnderlay: RootState["controls"]["imageUnderlay"];
config: RootState["config"];
isSidePanelOpen: RootState["panelEmbedding"]["open"];
sidePanelLayoutChoice: RootState["panelEmbedding"]["layoutChoice"];
}

export interface OwnProps {
Expand Down

0 comments on commit 96fc002

Please sign in to comment.