🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
add settings options
Bill Yang12b087894269
diff --git a/client/src/components/SiteSettings/SiteSettings.tsx b/client/src/components/SiteSettings/SiteSettings.tsxindex 32f8bf196..0d5659eb5 100644--- a/client/src/components/SiteSettings/SiteSettings.tsx+++ b/client/src/components/SiteSettings/SiteSettings.tsx@@ -29,6 +29,8 @@ import {DialogTrigger,} from "@/components/ui/dialog";import { Input } from "@/components/ui/input";+import { Label } from "@/components/ui/label";+import { Switch } from "@/components/ui/switch";import {changeSiteDomain,@@ -65,9 +67,24 @@ export function SiteSettingsInner({const [isDeleting, setIsDeleting] = useState(false);const [dialogOpen, setDialogOpen] = useState(false);+ // Script configuration options+ const [debounceValue, setDebounceValue] = useState(500);+ const [autoTrack, setAutoTrack] = useState(true);++ // Generate tracking script dynamically based on optionsconst trackingScript = `<scriptsrc="${BACKEND_URL}/script.js"- site-id="${siteMetadata.siteId}"+ data-site-id="${siteMetadata.siteId}"${+ debounceValue !== 500+ ? `+ data-debounce="${debounceValue}"`+ : ""+ }${+ !autoTrack+ ? `+ data-auto-track="false"`+ : ""+ }defer/>`;@@ -119,27 +136,92 @@ export function SiteSettingsInner({<Settings className="h-4 w-4" /></Button></DialogTrigger>- <DialogContent className="sm:max-w-[425px]">+ <DialogContent className="sm:max-w-[500px]"><DialogHeader><DialogTitle>Site Settings</DialogTitle><DialogDescription>Manage settings for {siteMetadata.domain}</DialogDescription></DialogHeader>- <div className="space-y-6 py-4">- <div className="space-y-2">- <h4 className="text-sm font-medium">Tracking Script</h4>- <p className="text-xs text-neutral-500">- Add this script to the <code><head></code> of your website- </p>+ <div className="space-y-6 py-4 max-h-[70vh] overflow-y-auto">+ <div className="space-y-3">+ <div>+ <h4 className="text-sm font-semibold text-foreground">+ Tracking Script+ </h4>+ <p className="text-xs text-muted-foreground">+ Add this script to the <code><head></code> of your website+ </p>+ </div><CodeSnippet language="HTML" code={trackingScript} />+ {/* Script Options Section */}+ <div className="space-y-3 pl-4">+ <h4 className="text-sm font-semibold text-foreground">+ Script Options+ </h4>+ <div className="space-y-2">+ <div className="flex flex-col gap-1.5">+ <Label+ htmlFor="debounce"+ className="text-sm font-medium text-foreground"+ >+ Debounce Duration (ms)+ </Label>+ <div className="flex items-center gap-2">+ <Input+ id="debounce"+ type="number"+ min="0"+ max="5000"+ value={debounceValue}+ onChange={(e) =>+ setDebounceValue(parseInt(e.target.value) || 0)+ }+ className="max-w-[120px]"+ />+ <span className="text-xs text-muted-foreground">+ Default: 500ms+ </span>+ </div>+ </div>+ <p className="text-xs text-muted-foreground">+ Time to wait before tracking a pageview after URL changes+ </p>+ </div>+ <div className="space-y-2">+ <div className="flex items-center justify-between">+ <div>+ <Label+ htmlFor="autoTrack"+ className="text-sm font-medium text-foreground block"+ >+ Automatically track URL changes+ </Label>+ <p className="text-xs text-muted-foreground mt-1">+ For SPAs: track page views when URL changes (using History+ API)+ </p>+ </div>+ <Switch+ id="autoTrack"+ checked={autoTrack}+ onCheckedChange={setAutoTrack}+ />+ </div>+ </div>+ </div></div>- <div className="space-y-2">- <h4 className="text-sm font-medium">Change Domain</h4>- <p className="text-xs text-neutral-500">- Update the domain for this site- </p>+ {/* Domain Settings Section */}+ <div className="space-y-3 pt-3">+ <div>+ <h4 className="text-sm font-semibold text-foreground">+ Change Domain+ </h4>+ <p className="text-xs text-muted-foreground">+ Update the domain for this site+ </p>+ </div><div className="flex space-x-2"><Inputvalue={newDomain}@@ -156,12 +238,15 @@ export function SiteSettingsInner({</div></div>- <div className="space-y-2">- <h4 className="text-sm font-medium text-red-500">Danger Zone</h4>+ {/* Danger Zone Section */}+ <div className="space-y-3 pt-3">+ <h4 className="text-sm font-semibold text-destructive">+ Danger Zone+ </h4><AlertDialog><AlertDialogTrigger asChild><Button variant="destructive" className="w-full">- <AlertTriangle className="h-4 w-4" />+ <AlertTriangle className="h-4 w-4 mr-2" />Delete Site</Button></AlertDialogTrigger>diff --git a/server/public/script.js b/server/public/script.jsindex f805783ca..3c976e3fd 100644--- a/server/public/script.js+++ b/server/public/script.js@@ -19,7 +19,7 @@return;}- // Get debounce duration from data attribute or default to 300ms+ // Get debounce duration from data attribute or default to 500msconst debounceDuration = scriptTag.getAttribute("data-debounce")? Math.max(0, parseInt(scriptTag.getAttribute("data-debounce"))): 500;