Skip to content

✨ Innovative and open-source visualization application that transforms various data formats, such as JSON, YAML, XML and CSV into interactive graphs.

update events

AykutSaracea3011b0dbfa
diff --git a/src/components/SearchInput/index.tsx b/src/components/SearchInput/index.tsx
index 6b76c25e..b41c0832 100644
--- a/src/components/SearchInput/index.tsx
+++ b/src/components/SearchInput/index.tsx
@@ -1,7 +1,6 @@
import React from "react";
import { Flex, Text, TextInput } from "@mantine/core";
import { getHotkeyHandler } from "@mantine/hooks";
-import ReactGA from "react-ga4";
import { AiOutlineSearch } from "react-icons/ai";
import { useFocusNode } from "src/hooks/useFocusNode";
@@ -16,7 +15,6 @@ export const SearchInput: React.FC = () => {
w={180}
value={searchValue}
onChange={e => setValue(e.currentTarget.value)}
- onFocus={() => ReactGA.event({ action: "focus_node_search", category: "User" })}
placeholder="Search Node"
onKeyDown={getHotkeyHandler([["Enter", skip]])}
leftSection={<AiOutlineSearch />}
diff --git a/src/containers/Modals/DownloadModal/index.tsx b/src/containers/Modals/DownloadModal/index.tsx
index 571fdaa7..3276e21a 100644
--- a/src/containers/Modals/DownloadModal/index.tsx
+++ b/src/containers/Modals/DownloadModal/index.tsx
@@ -11,9 +11,9 @@ import {
ColorInput,
} from "@mantine/core";
import { toBlob, toJpeg, toPng, toSvg } from "html-to-image";
-import ReactGA from "react-ga4";
import toast from "react-hot-toast";
import { FiCopy, FiDownload } from "react-icons/fi";
+import { gaEvent } from "src/lib/utils/gaEvent";
enum Extensions {
SVG = "svg",
@@ -90,11 +90,11 @@ export const DownloadModal: React.FC<ModalProps> = ({ opened, onClose }) => {
]);
toast.success("Copied to clipboard");
+ gaEvent("click", "clipboard image");
} catch (error) {
toast.error("Failed to copy to clipboard");
} finally {
toast.dismiss("toastClipboard");
- ReactGA.event({ action: "click_clipboard_image", category: "User" });
onClose();
}
};
@@ -111,11 +111,11 @@ export const DownloadModal: React.FC<ModalProps> = ({ opened, onClose }) => {
});
downloadURI(dataURI, `${fileDetails.filename}.${extension}`);
+ gaEvent("download", "download graph image", extension);
} catch (error) {
toast.error("Failed to download image!");
} finally {
toast.dismiss("toastDownload");
- ReactGA.event({ action: "click_download_image", category: "User" });
onClose();
}
};
diff --git a/src/containers/Modals/NodeModal/index.tsx b/src/containers/Modals/NodeModal/index.tsx
index 92e9878d..c1cba767 100644
--- a/src/containers/Modals/NodeModal/index.tsx
+++ b/src/containers/Modals/NodeModal/index.tsx
@@ -3,6 +3,7 @@ import { Modal, Stack, Text, ScrollArea, ModalProps, Button } from "@mantine/cor
import { CodeHighlight } from "@mantine/code-highlight";
import Editor from "@monaco-editor/react";
import { VscLock } from "react-icons/vsc";
+import { gaEvent } from "src/lib/utils/gaEvent";
import { isIframe } from "src/lib/utils/widget";
import useConfig from "src/store/useConfig";
import useFile from "src/store/useFile";
@@ -36,6 +37,7 @@ export const NodeModal: React.FC<ModalProps> = ({ opened, onClose }) => {
if (!isPremium) return;
editContents(path!, value, () => {
setEditMode(false);
+ gaEvent("input", "node contents update");
onModalClose();
});
};
diff --git a/src/containers/Toolbar/FileMenu.tsx b/src/containers/Toolbar/FileMenu.tsx
index 550bfe65..73c3c0e6 100644
--- a/src/containers/Toolbar/FileMenu.tsx
+++ b/src/containers/Toolbar/FileMenu.tsx
@@ -1,6 +1,7 @@
import React from "react";
import { Flex, Menu } from "@mantine/core";
import { CgChevronDown } from "react-icons/cg";
+import { gaEvent } from "src/lib/utils/gaEvent";
import useFile from "src/store/useFile";
import useModal from "src/store/useModal";
import * as Styles from "./styles";
@@ -17,6 +18,8 @@ export const FileMenu = () => {
a.href = window.URL.createObjectURL(file);
a.download = `jsoncrack.${getFormat()}`;
a.click();
+
+ gaEvent("download", "file download");
};
return (
diff --git a/src/containers/Toolbar/ToolsMenu.tsx b/src/containers/Toolbar/ToolsMenu.tsx
index 2e8cb784..2bc0e406 100644
--- a/src/containers/Toolbar/ToolsMenu.tsx
+++ b/src/containers/Toolbar/ToolsMenu.tsx
@@ -3,6 +3,7 @@ import { Menu, Flex } from "@mantine/core";
import { CgChevronDown } from "react-icons/cg";
import { SiJsonwebtokens } from "react-icons/si";
import { VscSearchFuzzy, VscJson, VscGroupByRefType } from "react-icons/vsc";
+import { gaEvent } from "src/lib/utils/gaEvent";
import useModal from "src/store/useModal";
import * as Styles from "./styles";
@@ -12,7 +13,7 @@ export const ToolsMenu = () => {
return (
<Menu shadow="md" withArrow>
<Menu.Target>
- <Styles.StyledToolElement>
+ <Styles.StyledToolElement onClick={() => gaEvent("click", "tools menu")}>
<Flex align="center" gap={3}>
Tools <CgChevronDown />
</Flex>
diff --git a/src/containers/Toolbar/ViewMenu.tsx b/src/containers/Toolbar/ViewMenu.tsx
index 04667cc6..366a207f 100644
--- a/src/containers/Toolbar/ViewMenu.tsx
+++ b/src/containers/Toolbar/ViewMenu.tsx
@@ -1,12 +1,12 @@
import React from "react";
import { Menu, Flex, Text, SegmentedControl } from "@mantine/core";
import { useHotkeys } from "@mantine/hooks";
-import ReactGA from "react-ga4";
import toast from "react-hot-toast";
import { CgChevronDown } from "react-icons/cg";
import { VscExpandAll, VscCollapseAll, VscTarget } from "react-icons/vsc";
import { ViewMode } from "src/enums/viewMode.enum";
import useToggleHide from "src/hooks/useToggleHide";
+import { gaEvent } from "src/lib/utils/gaEvent";
import { getNextDirection } from "src/lib/utils/graph/getNextDirection";
import useConfig from "src/store/useConfig";
import useGraph from "src/store/useGraph";
@@ -65,7 +65,7 @@ export const ViewMenu = () => {
return (
<Menu shadow="md" closeOnItemClick={false} withArrow>
<Menu.Target>
- <Styles.StyledToolElement>
+ <Styles.StyledToolElement onClick={() => gaEvent("click", "view menu")}>
<Flex align="center" gap={3}>
View <CgChevronDown />
</Flex>
@@ -88,14 +88,7 @@ export const ViewMenu = () => {
<Menu.Item
mt="xs"
fz={12}
- onClick={() => {
- toggleDirection();
- ReactGA.event({
- action: "toggle_layout_direction",
- category: "User",
- label: "Tools",
- });
- }}
+ onClick={toggleDirection}
leftSection={<Styles.StyledFlowIcon rotate={rotateLayout(direction || "RIGHT")} />}
rightSection={
<Text ml="md" fz={10} c="dimmed">
@@ -107,14 +100,7 @@ export const ViewMenu = () => {
</Menu.Item>
<Menu.Item
fz={12}
- onClick={() => {
- toggleExpandCollapseGraph();
- ReactGA.event({
- action: "toggle_collapse_nodes",
- category: "User",
- label: "Tools",
- });
- }}
+ onClick={toggleExpandCollapseGraph}
leftSection={graphCollapsed ? <VscExpandAll /> : <VscCollapseAll />}
rightSection={
<Text ml="md" fz={10} c="dimmed">
diff --git a/src/containers/Toolbar/ZoomMenu.tsx b/src/containers/Toolbar/ZoomMenu.tsx
index dda6d6b6..1f09c9fc 100644
--- a/src/containers/Toolbar/ZoomMenu.tsx
+++ b/src/containers/Toolbar/ZoomMenu.tsx
@@ -2,6 +2,7 @@ import React from "react";
import { Menu, Flex, Input, Text } from "@mantine/core";
import { getHotkeyHandler, useHotkeys } from "@mantine/hooks";
import { CgChevronDown } from "react-icons/cg";
+import { gaEvent } from "src/lib/utils/gaEvent";
import useGraph from "src/store/useGraph";
import * as Styles from "./styles";
@@ -26,7 +27,7 @@ export const ZoomMenu = () => {
return (
<Menu shadow="md" trigger="click" closeOnItemClick={false} withArrow>
<Menu.Target>
- <Styles.StyledToolElement>
+ <Styles.StyledToolElement onClick={() => gaEvent("click", "zoom menu")}>
<Flex gap={4} align="center">
{Math.round(zoomFactor * 100)}%
<CgChevronDown />
diff --git a/src/hooks/useFocusNode.ts b/src/hooks/useFocusNode.ts
index 24b92e3e..98289dd7 100644
--- a/src/hooks/useFocusNode.ts
+++ b/src/hooks/useFocusNode.ts
@@ -1,5 +1,6 @@
import React from "react";
import { useDebouncedValue } from "@mantine/hooks";
+import { gaEvent } from "src/lib/utils/gaEvent";
import { searchQuery, cleanupHighlight, highlightMatchedNodes } from "src/lib/utils/graph/search";
import useGraph from "src/store/useGraph";
@@ -37,6 +38,8 @@ export const useFocusNode = () => {
setSelectedNode(0);
setNodeCount(0);
}
+
+ gaEvent("input", "search node in graph");
}, [selectedNode, debouncedValue, value, viewPort]);
return [value, setValue, skip, nodeCount, selectedNode] as const;
diff --git a/src/lib/utils/gaEvent.ts b/src/lib/utils/gaEvent.ts
new file mode 100644
index 00000000..b9909f46
--- /dev/null
+++ b/src/lib/utils/gaEvent.ts
@@ -0,0 +1,9 @@
+import ReactGA4 from "react-ga4";
+
+export const gaEvent = (category: string, action: string, label?: string) => {
+ ReactGA4.event({
+ category,
+ action,
+ label,
+ });
+};
diff --git a/src/store/useFile.ts b/src/store/useFile.ts
index 93b37f67..602d422b 100644
--- a/src/store/useFile.ts
+++ b/src/store/useFile.ts
@@ -1,11 +1,11 @@
import debounce from "lodash.debounce";
import _get from "lodash.get";
import _set from "lodash.set";
-import ReactGA from "react-ga4";
import { toast } from "react-hot-toast";
import { create } from "zustand";
import { defaultJson } from "src/constants/data";
import { FileFormat } from "src/enums/file.enum";
+import { gaEvent } from "src/lib/utils/gaEvent";
import { contentToJson, jsonToContent } from "src/lib/utils/json/jsonAdapter";
import { isIframe } from "src/lib/utils/widget";
import { documentSvc } from "src/services/document.service";
@@ -111,8 +111,7 @@ const useFile = create<FileStates & JsonActions>()((set, get) => ({
const jsonContent = await jsonToContent(JSON.stringify(contentJson, null, 2), format);
get().setContents({ contents: jsonContent });
-
- ReactGA.event({ action: "change_data_format", category: "User" });
+ gaEvent("input", "file format change");
} catch (error) {
get().clear();
console.warn("The content was unable to be converted, so it was cleared instead.");
diff --git a/src/store/useModal.ts b/src/store/useModal.ts
index 305ecd1a..ab4d2d65 100644
--- a/src/store/useModal.ts
+++ b/src/store/useModal.ts
@@ -1,6 +1,6 @@
-import ReactGA from "react-ga4";
import { create } from "zustand";
import { Modal } from "src/containers/Modals";
+import { gaEvent } from "src/lib/utils/gaEvent";
import useUser from "./useUser";
type ModalState = {
@@ -43,7 +43,7 @@ const useModal = create<ModalState & ModalActions>()(set => ({
return set({ premium: true });
}
- if (visible) ReactGA.event({ category: "Modal View", action: `modal_view_${modal}` });
+ if (visible) gaEvent("modal", `open ${modal}`);
set({ [modal]: visible });
},
}));
diff --git a/src/store/useUser.ts b/src/store/useUser.ts
index 4d1df30d..86f49e6f 100644
--- a/src/store/useUser.ts
+++ b/src/store/useUser.ts
@@ -1,8 +1,8 @@
import { Session, User } from "@supabase/supabase-js";
-import ReactGA from "react-ga4";
import toast from "react-hot-toast";
import { create } from "zustand";
import { supabase } from "src/lib/api/supabase";
+import { gaEvent } from "src/lib/utils/gaEvent";
interface UserActions {
logout: () => void;
@@ -38,12 +38,10 @@ const useUser = create<UserStates & UserActions>()(set => ({
premiumCancelled: !!data.cancelled,
orgAdmin: data.orgAdmin,
});
-
- ReactGA.set({ tier: data.premium ? "premium" : "free" });
}
+ gaEvent("engagement", "login");
set({ user: session.user, isAuthenticated: true });
- ReactGA.set({ userId: session.user.id });
});
},
logout: async () => {