Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Outlet } from "react-router-dom";

import useHotjar from "@/hooks/common/useHotjar";

const App = () => {
useHotjar();

return (
<main>
<Outlet />
Expand Down
27 changes: 27 additions & 0 deletions src/hooks/common/useHotjar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { useEffect } from "react";

const useHotjar = () => {
useEffect(() => {
const hotjarId = import.meta.env.VITE_HOTJAR_ID;

if (import.meta.env.PROD && hotjarId) {
(function (h: any, o: any, t: any, j: any, a?: any, r?: any) {
(h.hj as any) =
h.hj ||
function () {
// eslint-disable-next-line prefer-rest-params
(h.hj.q = h.hj.q || []).push(arguments);
};
h._hjSettings = { hjid: parseInt(hotjarId, 10), hjsv: 6 };
a = o.getElementsByTagName("head")[0];
r = o.createElement("script");
r.async = 1;
r.src = t + h._hjSettings.hjid + j + h._hjSettings.hjsv;
a.appendChild(r);
})(window, document, "https://static.hotjar.com/c/hotjar-", ".js?sv=");
}
}, []);
};

export default useHotjar;