refactor: dont inject analytics script

This commit is contained in:
2024-01-09 10:30:45 +00:00
parent 44983068e4
commit 45245153ab
5 changed files with 54 additions and 39 deletions

View File

@ -1,6 +1,6 @@
import "./Layout.css";
import { useCallback } from "react";
import { useCallback, useEffect } from "react";
import { Outlet, useLocation } from "react-router-dom";
import CloseButton from "@/Components/Button/CloseButton";
@ -15,7 +15,7 @@ import { useLoginRelays } from "@/Hooks/useLoginRelays";
import { useTheme } from "@/Hooks/useTheme";
import Footer from "@/Pages/Layout/Footer";
import { Header } from "@/Pages/Layout/Header";
import { isFormElement } from "@/Utils";
import { isFormElement, trackEvent } from "@/Utils";
import { LoginStore } from "@/Utils/Login";
import NavSidebar from "./NavSidebar";
@ -23,7 +23,11 @@ import RightColumn from "./RightColumn";
export default function Index() {
const location = useLocation();
const { id, stalker } = useLogin(s => ({ id: s.id, stalker: s.stalker ?? false }));
const { id, stalker, telemetry } = useLogin(s => ({
id: s.id,
stalker: s.stalker ?? false,
telemetry: s.appData.item.preferences.telemetry,
}));
useTheme();
useLoginRelays();
@ -34,13 +38,19 @@ export default function Index() {
const shouldHideFooter = location.pathname.startsWith("/messages/");
const shouldHideHeader = hideHeaderPaths.some(path => location.pathname.startsWith(path));
const handleKeyboardShortcut = useCallback(event => {
const handleKeyboardShortcut = useCallback((event: Event) => {
if (event.target && !isFormElement(event.target as HTMLElement)) {
event.preventDefault();
window.scrollTo({ top: 0, behavior: "instant" });
}
}, []);
useEffect(() => {
if (CONFIG.features.analytics && (telemetry ?? true)) {
trackEvent("pageview");
}
}, [location]);
useKeyboardShortcut(".", handleKeyboardShortcut);
const isStalker = !!stalker;