Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Add theme tracking to GitHubStarButton component

Bill Yang646a0963fa1c
diff --git a/docs/src/components/GitHubStarButton.tsx b/docs/src/components/GitHubStarButton.tsx
index efe4c2e4f..0a5f4e1e4 100644
--- a/docs/src/components/GitHubStarButton.tsx
+++ b/docs/src/components/GitHubStarButton.tsx
@@ -3,10 +3,23 @@
import { Star } from "lucide-react";
import { trackAdEvent } from "../lib/trackAdEvent";
import { useGithubStarCount } from "../lib/useGithubStarCount";
+import { useTheme } from "next-themes";
+import { useEffect } from "react";
export function GitHubStarButton() {
const { starCount, isLoading } = useGithubStarCount();
+ const { systemTheme, resolvedTheme } = useTheme();
+
+ useEffect(() => {
+ if (systemTheme && resolvedTheme) {
+ window.rybbit.event("theme", {
+ resolvedTheme,
+ systemTheme,
+ });
+ }
+ }, [resolvedTheme, resolvedTheme]);
+
return (
<div className="mb-6 md:mb-8" onClick={() => trackAdEvent("github")}>
<a
diff --git a/docs/src/components/rybbit.d.ts b/docs/src/components/rybbit.d.ts
new file mode 100644
index 000000000..a434c3039
--- /dev/null
+++ b/docs/src/components/rybbit.d.ts
@@ -0,0 +1,39 @@
+interface Rybbit {
+ /**
+ * Tracks a page view
+ */
+ pageview: () => void;
+ /**
+ * Tracks a custom event
+ * @param name Name of the event
+ * @param properties Optional properties for the event
+ */
+ event: (name: string, properties?: Record<string, any>) => void;
+ /**
+ * Sets a custom user ID for tracking logged-in users
+ * @param userId The user ID to set (will be stored in localStorage)
+ */
+ identify: (userId: string) => void;
+ /**
+ * Clears the stored user ID
+ */
+ clearUserId: () => void;
+ /**
+ * Gets the currently set user ID
+ * @returns The current user ID or null if not set
+ */
+ getUserId: () => string | null;
+ /**
+ * Manually tracks outbound link clicks
+ * @param url The URL of the outbound link
+ * @param text Optional text content of the link
+ * @param target Optional target attribute of the link
+ */
+ trackOutbound: (url: string, text?: string, target?: string) => void;
+}
+declare global {
+ interface Window {
+ rybbit: Rybbit;
+ }
+}
+export {};