File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11// @ts -check
22import { defineConfig } from "astro/config" ;
33import starlight from "@astrojs/starlight" ;
4+ import { analytics } from "./src/integrations/analytics" ;
45
56// https://astro.build/config
67export default defineConfig ( {
@@ -36,6 +37,7 @@ export default defineConfig({
3637 "./src/styles/custom.css" ,
3738 ] ,
3839 } ) ,
40+ analytics ( ) ,
3941 ] ,
4042 site : "https://keshav.is-a.dev" ,
4143 base : "FreqKnow" ,
Original file line number Diff line number Diff line change 1+ import type { AstroIntegration } from "astro" ;
2+
3+ export function analytics ( ) : AstroIntegration {
4+ return {
5+ name : "analytics" ,
6+ hooks : {
7+ "astro:config:setup" : ( { injectScript } ) => {
8+ injectScript (
9+ "page" ,
10+ `
11+ const API_URL = "https://freq-know-analytics.dhimankeshav201.workers.dev/track/";
12+
13+ export function trackPageEntry() {
14+ // Don't track in development
15+ if (window.location.hostname === "localhost") return;
16+
17+ const referrer = document.referrer;
18+ const currentDomain = window.location.hostname;
19+
20+ // Check if referrer is from a different domain (or no referrer = direct visit)
21+ const isExternalEntry =
22+ !referrer || (referrer && new URL(referrer).hostname !== currentDomain);
23+
24+ if (isExternalEntry) {
25+ fetch(API_URL, {
26+ method: "GET",
27+ }).catch(() => {}); // Silent fail
28+ }
29+ }
30+ ` ,
31+ ) ;
32+ } ,
33+ } ,
34+ } ;
35+ }
You can’t perform that action at this time.
0 commit comments