Skip to content

Commit

Permalink
feat: add visitor counter
Browse files Browse the repository at this point in the history
  • Loading branch information
ijash committed Dec 27, 2024
1 parent 5bddd53 commit 2af2865
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
1 change: 0 additions & 1 deletion .env

This file was deleted.

2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
WDS_SOCKET_PORT=0
REACT_APP_WDS_SOCKET_PORT=$WDS_SOCKET_PORT
GOAT_COUNTER_ID=example
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

.env
31 changes: 31 additions & 0 deletions src/components/common/goatCounter.tsx
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 2 additions & 0 deletions src/components/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
TableSection,
Title,
} from "components";
import GoatCounter from "./common/goatCounter";

interface MainProps {}

Expand All @@ -21,6 +22,7 @@ export const Main: React.FC<MainProps> = (props) => {
</div>
<FooterText />
</FilterContextProvider>
<GoatCounter />
</main>
);
};

0 comments on commit 2af2865

Please sign in to comment.