Skip to content

Commit 52ddbeb

Browse files
committed
chore: add tracking for analytics
1 parent 9174950 commit 52ddbeb

File tree

3 files changed

+324
-308
lines changed

3 files changed

+324
-308
lines changed

components/useTracking.tsx

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { useEffect } from "react";
2+
3+
const CLARITY_ID = "q6bz69wquw";
4+
5+
export const useTracking = () => {
6+
useEffect(() => {
7+
const script = document.createElement("script");
8+
script.type = "text/javascript";
9+
script.text = `
10+
(function(c,l,a,r,i,t,y){
11+
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
12+
t=l.createElement(r);t.async=1;
13+
t.src="https://www.clarity.ms/tag/"+i;
14+
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
15+
})(window, document, "clarity", "script", "${CLARITY_ID}");
16+
`;
17+
document.head.appendChild(script);
18+
return () => {
19+
document.head.removeChild(script);
20+
};
21+
}, []);
22+
};

layout.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { useSidebarToggle } from "./components/useSidebarToggle";
2+
import { useTracking } from "./components/useTracking";
23

34
export default function Root({ children }: { children: React.ReactNode }) {
5+
useTracking();
46
useSidebarToggle();
57
return <div className="page-wrapper">{children}</div>;
68
}

0 commit comments

Comments
 (0)