Skip to content

Commit

Permalink
Merge pull request #75 from 100-hours-a-week/feature/lucy
Browse files Browse the repository at this point in the history
Fix : useEffect top level에서 사용 불가 오류 수정
  • Loading branch information
lucy726j authored Aug 24, 2024
2 parents f7f12dd + c9a49db commit b7f75c0
Showing 1 changed file with 43 additions and 42 deletions.
85 changes: 43 additions & 42 deletions src/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,54 +14,55 @@ import LoginPage from "./Pages/404/loginPage";
import ReactGA from "react-ga";
import { useEffect } from "react";

// 구글 애널리틱스 설정
const gaTrackingId = process.env.REACT_APP_GA_TRACKING_ID;
const clarityTrackingId = process.env.REACT_APP_CLARITY_TRACKING_ID;
const Router = () => {
const { user } = useAuth();

if (gaTrackingId) {
ReactGA.initialize(gaTrackingId, { debug: true }); // react-ga 초기화 및 debug 사용
} else {
console.error("Google Analytics tracking ID is not defined");
}
// 구글 애널리틱스 설정
const gaTrackingId = process.env.REACT_APP_GA_TRACKING_ID;
const clarityTrackingId = process.env.REACT_APP_CLARITY_TRACKING_ID;

const usePageTracking = () => {
const location = useLocation();
if (gaTrackingId) {
ReactGA.initialize(gaTrackingId, { debug: true }); // react-ga 초기화 및 debug 사용
} else {
console.error("Google Analytics tracking ID is not defined");
}

useEffect(() => {
if (gaTrackingId) {
ReactGA.pageview(location.pathname + location.search);
}
}, [location]);
};
const usePageTracking = () => {
const location = useLocation();

// MicroSoft Clarity 설정
// 타입 에러 때문에,,, c,a,i any로 변경
useEffect(() => {
(function (
c: any,
l: Document,
a: any,
r: keyof HTMLElementTagNameMap,
i: any
) {
c[a] =
c[a] ||
function () {
(c[a].q = c[a].q || []).push(arguments);
};
useEffect(() => {
if (gaTrackingId) {
ReactGA.pageview(location.pathname + location.search);
}
}, [location]);
};

const t: HTMLScriptElement = l.createElement(r) as HTMLScriptElement;
t.async = true;
t.src = "https://www.clarity.ms/tag/" + i;
// MicroSoft Clarity 설정
// 타입 에러 때문에,,, c,a,i any로 변경
useEffect(() => {
(function (
c: any,
l: Document,
a: any,
r: keyof HTMLElementTagNameMap,
i: any
) {
c[a] =
c[a] ||
function () {
(c[a].q = c[a].q || []).push(arguments);
};

const y = l.getElementsByTagName(r)[0] as HTMLElement; // Explicitly cast to HTMLElement
if (y && y.parentNode) {
y.parentNode.insertBefore(t, y);
}
})(window, document, "clarity", "script", clarityTrackingId);
}, []);
const Router = () => {
const { user } = useAuth();
const t: HTMLScriptElement = l.createElement(r) as HTMLScriptElement;
t.async = true;
t.src = "https://www.clarity.ms/tag/" + i;

const y = l.getElementsByTagName(r)[0] as HTMLElement; // Explicitly cast to HTMLElement
if (y && y.parentNode) {
y.parentNode.insertBefore(t, y);
}
})(window, document, "clarity", "script", clarityTrackingId);
}, []);
usePageTracking();

return (
Expand Down

0 comments on commit b7f75c0

Please sign in to comment.