diff --git a/.env b/.env deleted file mode 100644 index b2b63dc..0000000 --- a/.env +++ /dev/null @@ -1 +0,0 @@ -WDS_SOCKET_PORT=0 diff --git a/.env.example b/.env.example index b2b63dc..23274e0 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,3 @@ WDS_SOCKET_PORT=0 +REACT_APP_WDS_SOCKET_PORT=$WDS_SOCKET_PORT +GOAT_COUNTER_ID=example diff --git a/.gitignore b/.gitignore index 4d29575..8b182cf 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,5 @@ npm-debug.log* yarn-debug.log* yarn-error.log* + +.env diff --git a/src/components/common/goatCounter.tsx b/src/components/common/goatCounter.tsx new file mode 100644 index 0000000..79497fb --- /dev/null +++ b/src/components/common/goatCounter.tsx @@ -0,0 +1,31 @@ +import React, { useEffect } from "react"; + +const GoatCounter: React.FC = () => { + useEffect(() => { + const handleLoad = () => { + const script = document.createElement("script"); + + script.src = "//gc.zgo.at/count.js"; + script.async = true; + if (process.env.GOAT_COUNTER_ID) { + script.dataset.goatcounter = `https://${process.env.REACT_APP_GOAT_COUNTER_ID}.goatcounter.com/count`; + } else { + console.error("GOAT_COUNTER_ID is not defined"); + } + + document.body.appendChild(script); + }; + + // Attach the event listener for window load + window.addEventListener("load", handleLoad); + + // Cleanup: remove event listener + return () => { + window.removeEventListener("load", handleLoad); + }; + }, []); + + return null; // No UI for this component +}; + +export default GoatCounter; diff --git a/src/components/main.tsx b/src/components/main.tsx index 5d79638..87799bb 100644 --- a/src/components/main.tsx +++ b/src/components/main.tsx @@ -6,6 +6,7 @@ import { TableSection, Title, } from "components"; +import GoatCounter from "./common/goatCounter"; interface MainProps {} @@ -21,6 +22,7 @@ export const Main: React.FC = (props) => { + ); };