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 ga

AykutSaracd152ad9301f5
diff --git a/package.json b/package.json
index a63ae0f7..fd4d4479 100644
--- a/package.json
+++ b/package.json
@@ -40,7 +40,7 @@
"next": "13.4.12",
"react": "^18.2.0",
"react-dom": "^18.2.0",
- "react-ga": "^3.3.1",
+ "react-ga4": "^2.1.0",
"react-hot-toast": "^2.4.1",
"react-icons": "^4.10.1",
"react-linkify-it": "^1.0.7",
diff --git a/src/components/GoogleAnalytics/index.tsx b/src/components/GoogleAnalytics/index.tsx
deleted file mode 100644
index a627e2c7..00000000
--- a/src/components/GoogleAnalytics/index.tsx
+++ /dev/null
@@ -1,37 +0,0 @@
-import React from "react";
-import Script from "next/script";
-import ReactGA from "react-ga";
-
-const isDevelopment = process.env.NODE_ENV === "development";
-const GA_TRACKING_ID = process.env.NEXT_PUBLIC_GA_ID;
-
-ReactGA.initialize(GA_TRACKING_ID, { testMode: isDevelopment });
-
-const GoogleAnalytics: React.FC = () => {
- if (isDevelopment) return null;
-
- return (
- <>
- <Script
- strategy="afterInteractive"
- src={`https://www.googletagmanager.com/gtag/js?id=${GA_TRACKING_ID}`}
- />
- <Script
- id="gtag-init"
- strategy="afterInteractive"
- dangerouslySetInnerHTML={{
- __html: `
- window.dataLayer = window.dataLayer || [];
- function gtag(){dataLayer.push(arguments);}
- gtag('js', new Date());
- gtag('config', '${GA_TRACKING_ID}', {
- page_path: window.location.pathname,
- });
- `,
- }}
- />
- </>
- );
-};
-
-export default GoogleAnalytics;
diff --git a/src/components/SearchInput/index.tsx b/src/components/SearchInput/index.tsx
index e2b4b29b..a98320e4 100644
--- a/src/components/SearchInput/index.tsx
+++ b/src/components/SearchInput/index.tsx
@@ -1,7 +1,7 @@
import React from "react";
import { Flex, Input, Text } from "@mantine/core";
import { getHotkeyHandler } from "@mantine/hooks";
-import { event } from "react-ga";
+import ReactGA from "react-ga4";
import { AiOutlineSearch } from "react-icons/ai";
import { useFocusNode } from "src/hooks/useFocusNode";
@@ -16,7 +16,7 @@ export const SearchInput: React.FC = () => {
w={180}
value={searchValue}
onChange={e => setValue(e.currentTarget.value)}
- onFocus={() => event({ action: "focus_node_search", category: "User" })}
+ onFocus={() => ReactGA.event({ action: "focus_node_search", category: "User" })}
placeholder="Search Node"
onKeyDown={getHotkeyHandler([["Enter", skip]])}
icon={<AiOutlineSearch />}
diff --git a/src/containers/Editor/LiveEditor/Tools.tsx b/src/containers/Editor/LiveEditor/Tools.tsx
index 6352f444..ab49db93 100644
--- a/src/containers/Editor/LiveEditor/Tools.tsx
+++ b/src/containers/Editor/LiveEditor/Tools.tsx
@@ -2,7 +2,7 @@ import React from "react";
import styled from "styled-components";
import { Flex, Group, MediaQuery, Menu, Select, Text } from "@mantine/core";
import { useHotkeys } from "@mantine/hooks";
-import { event } from "react-ga";
+import ReactGA from "react-ga4";
import toast from "react-hot-toast";
import { AiOutlineFullscreen, AiOutlineMinus, AiOutlinePlus } from "react-icons/ai";
import { CgArrowsMergeAltH, CgArrowsShrinkH, CgChevronDown } from "react-icons/cg";
@@ -212,7 +212,11 @@ export const Tools: React.FC<{ isWidget?: boolean }> = ({ isWidget = false }) =>
fz={12}
onClick={() => {
toggleEditor();
- event({ action: "toggle_hide_editor", category: "User", label: "Tools" });
+ ReactGA.event({
+ action: "toggle_hide_editor",
+ category: "User",
+ label: "Tools",
+ });
}}
icon={fullscreen ? <VscLayoutSidebarLeft /> : <VscLayoutSidebarLeftOff />}
rightSection={
@@ -227,7 +231,11 @@ export const Tools: React.FC<{ isWidget?: boolean }> = ({ isWidget = false }) =>
fz={12}
onClick={() => {
toggleDirection();
- event({ action: "toggle_layout_direction", category: "User", label: "Tools" });
+ ReactGA.event({
+ action: "toggle_layout_direction",
+ category: "User",
+ label: "Tools",
+ });
}}
icon={<StyledFlowIcon rotate={rotateLayout(direction)} />}
rightSection={
@@ -242,7 +250,11 @@ export const Tools: React.FC<{ isWidget?: boolean }> = ({ isWidget = false }) =>
fz={12}
onClick={() => {
toggleFoldNodes();
- event({ action: "toggle_fold_nodes", category: "User", label: "Tools" });
+ ReactGA.event({
+ action: "toggle_fold_nodes",
+ category: "User",
+ label: "Tools",
+ });
}}
icon={foldNodes ? <CgArrowsShrinkH /> : <CgArrowsMergeAltH />}
rightSection={
@@ -257,7 +269,11 @@ export const Tools: React.FC<{ isWidget?: boolean }> = ({ isWidget = false }) =>
fz={12}
onClick={() => {
toggleExpandCollapseGraph();
- event({ action: "toggle_collapse_nodes", category: "User", label: "Tools" });
+ ReactGA.event({
+ action: "toggle_collapse_nodes",
+ category: "User",
+ label: "Tools",
+ });
}}
icon={graphCollapsed ? <VscExpandAll /> : <VscCollapseAll />}
rightSection={
diff --git a/src/containers/Modals/DownloadModal/index.tsx b/src/containers/Modals/DownloadModal/index.tsx
index 957b08e0..b5cfb344 100644
--- a/src/containers/Modals/DownloadModal/index.tsx
+++ b/src/containers/Modals/DownloadModal/index.tsx
@@ -13,7 +13,7 @@ import {
Stack,
} from "@mantine/core";
import { toBlob, toJpeg, toPng, toSvg } from "html-to-image";
-import { event } from "react-ga";
+import ReactGA from "react-ga4";
import toast from "react-hot-toast";
import { FiCopy, FiDownload } from "react-icons/fi";
@@ -96,7 +96,7 @@ export const DownloadModal: React.FC<ModalProps> = ({ opened, onClose }) => {
toast.error("Failed to copy to clipboard");
} finally {
toast.dismiss("toastClipboard");
- event({ action: "click_clipboard_image", category: "User" });
+ ReactGA.event({ action: "click_clipboard_image", category: "User" });
onClose();
}
};
@@ -117,7 +117,7 @@ export const DownloadModal: React.FC<ModalProps> = ({ opened, onClose }) => {
toast.error("Failed to download image!");
} finally {
toast.dismiss("toastDownload");
- event({ action: "click_download_image", category: "User" });
+ ReactGA.event({ action: "click_download_image", category: "User" });
onClose();
}
};
diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx
index 53d82b5e..acdfa727 100644
--- a/src/pages/_app.tsx
+++ b/src/pages/_app.tsx
@@ -5,17 +5,21 @@ import { useRouter } from "next/router";
import { StyleSheetManager, ThemeProvider } from "styled-components";
import { MantineProvider, MantineThemeOverride } from "@mantine/core";
import { SessionContextProvider, Session } from "@supabase/auth-helpers-react";
-import { pageview } from "react-ga";
+import ReactGA from "react-ga4";
import { monaSans } from "src/constants/fonts";
import GlobalStyle from "src/constants/globalStyle";
import { lightTheme } from "src/constants/theme";
import { supabase } from "src/lib/api/supabase";
import useUser from "src/store/useUser";
+const isDevelopment = process.env.NODE_ENV === "development";
+const GA_TRACKING_ID = process.env.NEXT_PUBLIC_GA_ID;
+
+ReactGA.initialize(GA_TRACKING_ID, { testMode: isDevelopment });
+
const Toaster = dynamic(() => import("react-hot-toast").then(c => c.Toaster));
const ExternalMode = dynamic(() => import("src/layout/ExternalMode"));
const ModalController = dynamic(() => import("src/layout/ModalController"));
-const GoogleAnalytics = dynamic(() => import("src/components/GoogleAnalytics"));
const mantineTheme: MantineThemeOverride = {
colorScheme: "light",
@@ -40,8 +44,8 @@ function JsonCrack({
}, [setSession]);
React.useEffect(() => {
- const handleRouteChange = (url: string) => {
- pageview(url);
+ const handleRouteChange = (page: string) => {
+ ReactGA.send({ hitType: "pageview", page });
};
router.events.on("routeChangeComplete", handleRouteChange);
@@ -53,7 +57,6 @@ function JsonCrack({
return (
<SessionContextProvider supabaseClient={supabase}>
- <GoogleAnalytics />
<StyleSheetManager>
<ThemeProvider theme={lightTheme}>
<GlobalStyle />
diff --git a/src/store/useFile.ts b/src/store/useFile.ts
index 8321a103..46b38116 100644
--- a/src/store/useFile.ts
+++ b/src/store/useFile.ts
@@ -1,7 +1,7 @@
import debounce from "lodash.debounce";
import _get from "lodash.get";
import _set from "lodash.set";
-import { event } from "react-ga";
+import ReactGA from "react-ga4";
import { toast } from "react-hot-toast";
import { create } from "zustand";
import { defaultJson } from "src/constants/data";
@@ -112,7 +112,7 @@ const useFile = create<FileStates & JsonActions>()((set, get) => ({
get().setContents({ contents: jsonContent });
- event({ action: "change_data_format", category: "User" });
+ ReactGA.event({ action: "change_data_format", category: "User" });
} 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 c74f6763..083196c2 100644
--- a/src/store/useModal.ts
+++ b/src/store/useModal.ts
@@ -1,4 +1,4 @@
-import { modalview } from "react-ga";
+import ReactGA from "react-ga4";
import { create } from "zustand";
import { Modal } from "src/containers/Modals";
import useUser from "./useUser";
@@ -41,7 +41,7 @@ const useModal = create<ModalState & ModalActions>()(set => ({
return set({ premium: true });
}
- if (visible) modalview(modal);
+ if (visible) ReactGA.event({ category: "Modal View", action: `modal_view_${modal}` });
set({ [modal]: visible });
},
}));
diff --git a/src/store/useUser.ts b/src/store/useUser.ts
index 542b998c..de3d2ff4 100644
--- a/src/store/useUser.ts
+++ b/src/store/useUser.ts
@@ -1,4 +1,5 @@
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";
@@ -34,9 +35,11 @@ const useUser = create<UserStates & UserActions>()(set => ({
organization: data.organization,
premiumCancelled: !!data.cancelled,
});
+ ReactGA.set({ tier: data.premium ? "premium" : "free" });
}
set({ user: session.user, isAuthenticated: true });
+ ReactGA.set({ userId: session.user.id });
});
},
logout: async () => {
diff --git a/yarn.lock b/yarn.lock
index 4b17f455..66cf3ef4 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -4933,10 +4933,10 @@ react-fast-compare@^3.2.0:
resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-3.2.2.tgz#929a97a532304ce9fee4bcae44234f1ce2c21d49"
integrity sha512-nsO+KSNgo1SbJqJEYRE9ERzo7YtYbou/OqjSQKxV7jcKox7+usiUVZOAC+XnDOABXggQTno0Y1CpVnuWEc1boQ==
-react-ga@^3.3.1:
- version "3.3.1"
- resolved "https://registry.yarnpkg.com/react-ga/-/react-ga-3.3.1.tgz#d8e1f4e05ec55ed6ff944dcb14b99011dfaf9504"
- integrity sha512-4Vc0W5EvXAXUN/wWyxvsAKDLLgtJ3oLmhYYssx+YzphJpejtOst6cbIHCIyF50Fdxuf5DDKqRYny24yJ2y7GFQ==
+react-ga4@^2.1.0:
+ version "2.1.0"
+ resolved "https://registry.yarnpkg.com/react-ga4/-/react-ga4-2.1.0.tgz#56601f59d95c08466ebd6edfbf8dede55c4678f9"
+ integrity sha512-ZKS7PGNFqqMd3PJ6+C2Jtz/o1iU9ggiy8Y8nUeksgVuvNISbmrQtJiZNvC/TjDsqD0QlU5Wkgs7i+w9+OjHhhQ==
react-hot-toast@^2.4.1:
version "2.4.1"