Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/clairefro/basic-ass-analytics
https://github.com/clairefro/basic-ass-analytics
Last synced: 29 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/clairefro/basic-ass-analytics
- Owner: clairefro
- License: other
- Created: 2024-09-23T14:58:36.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-09-24T20:56:24.000Z (4 months ago)
- Last Synced: 2024-12-15T23:34:30.810Z (about 1 month ago)
- Language: JavaScript
- Size: 41 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Basic Ass Analytics
Just barely enough to be useful, and barely too little to somewhat cover your ass from GDPR
![image](https://github.com/user-attachments/assets/0a75810d-c671-49bf-87cb-3e4697105c7c)
![image](https://github.com/user-attachments/assets/aa8134e3-7a07-4f6c-b51e-afb0114f3fa6)# Usage - Client snippet (React)
## Hook
```ts
import { useEffect } from "react";const useAn = () => {
useEffect(() => {
const send = async () => {
const anUrl = import.meta.env.VITE_AN_URL;if (!anUrl) return;
try {
const timestamp = new Date().toISOString();
const userAgent = navigator.userAgent;const response = await fetch(anUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
timestamp,
userAgent,
}),
});if (!response.ok) {
console.error("Error sending data:", response.statusText);
}
} catch (error) {
console.error("Error sending data:", error);
}
};send();
}, []);
};export default useAn;
```## Impl
Place at app root if only want hits on app renderIf page-wise analytics needed, modify the server to collect page path, move impl to page layout
```jsx
function App() {
useAn();return (
...
);
}export default App;
```