Skip to content

Commit 36545f4

Browse files
authored
feat: hotjar 추가 (#131)
1 parent fcbf416 commit 36545f4

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/App.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { Outlet } from "react-router-dom";
22

3+
import useHotjar from "@/hooks/common/useHotjar";
4+
35
const App = () => {
6+
useHotjar();
7+
48
return (
59
<main>
610
<Outlet />

src/hooks/common/useHotjar.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
import { useEffect } from "react";
3+
4+
const useHotjar = () => {
5+
useEffect(() => {
6+
const hotjarId = import.meta.env.VITE_HOTJAR_ID;
7+
8+
if (import.meta.env.PROD && hotjarId) {
9+
(function (h: any, o: any, t: any, j: any, a?: any, r?: any) {
10+
(h.hj as any) =
11+
h.hj ||
12+
function () {
13+
// eslint-disable-next-line prefer-rest-params
14+
(h.hj.q = h.hj.q || []).push(arguments);
15+
};
16+
h._hjSettings = { hjid: parseInt(hotjarId, 10), hjsv: 6 };
17+
a = o.getElementsByTagName("head")[0];
18+
r = o.createElement("script");
19+
r.async = 1;
20+
r.src = t + h._hjSettings.hjid + j + h._hjSettings.hjsv;
21+
a.appendChild(r);
22+
})(window, document, "https://static.hotjar.com/c/hotjar-", ".js?sv=");
23+
}
24+
}, []);
25+
};
26+
27+
export default useHotjar;

0 commit comments

Comments
 (0)