Spaces:
Running
Running
Download app/src/pet/analytics.js from FormaLau/DuckAgochi: direct link, hf CLI and curl.
- Browser
- Download file 1.93 kB
-
https://huggingface.co/spaces/FormaLau/DuckAgochi/resolve/main/app/src/pet/analytics.js
- Command line
-
hf download hf://spaces/FormaLau/DuckAgochi/app/src/pet/analytics.js
-
curl -L -o analytics.js https://huggingface.co/spaces/FormaLau/DuckAgochi/resolve/main/app/src/pet/analytics.js
1.93 kB
| // Anonymous audience measurement with Umami Cloud: no cookies, no personal data, no | |
| // cross-site tracking. Visitors are counted by Umami's daily-rotating hash; play time is a | |
| // "play-minute" event sent for each minute the page is visible. Nothing loads until | |
| // UMAMI_WEBSITE_ID is set, and nothing is sent when the visitor opted out or the browser | |
| // asks not to be tracked (Do Not Track / Global Privacy Control). | |
| export const UMAMI_WEBSITE_ID = '2e0a1b61-a8a3-436a-bf47-74f72de0823a'; // Website ID from cloud.umami.is → Settings → Websites | |
| const SCRIPT = 'https://cloud.umami.is/script.js'; | |
| const KEY = 'duckagochi.analytics'; | |
| const browserSaysNo = () => navigator.doNotTrack === '1' || navigator.globalPrivacyControl === true; | |
| export function analyticsOptedOut() { | |
| try { return localStorage.getItem(KEY) === 'off'; } catch { return false; } | |
| } | |
| export function analyticsAvailable() { | |
| return !!UMAMI_WEBSITE_ID && !browserSaysNo(); | |
| } | |
| export function setAnalyticsOptOut(off) { | |
| try { off ? localStorage.setItem(KEY, 'off') : localStorage.removeItem(KEY); } catch {} | |
| if (!off) startAnalytics(); | |
| } | |
| let started = false; | |
| export function startAnalytics() { | |
| if (started || !analyticsAvailable() || analyticsOptedOut()) return; | |
| started = true; | |
| const script = document.createElement('script'); | |
| script.defer = true; script.src = SCRIPT; | |
| script.dataset.websiteId = UMAMI_WEBSITE_ID; | |
| script.dataset.doNotTrack = 'true'; | |
| document.head.append(script); | |
| const send = (name, data) => { if (!analyticsOptedOut()) window.umami?.track(name, data); }; | |
| let minutes = 0, visibleSeconds = 0; | |
| setInterval(() => { | |
| if (document.visibilityState !== 'visible') return; | |
| visibleSeconds += 15; | |
| if (visibleSeconds >= 60) { visibleSeconds = 0; minutes++; send('play-minute', { minute: minutes }); } | |
| }, 15000); | |
| window.addEventListener('pagehide', () => { if (minutes) send('session-end', { minutes }); }); | |
| } | |