mirror of
https://github.com/trycua/computer.git
synced 2026-01-04 12:30:08 -06:00
cookie policy + external links
This commit is contained in:
@@ -3,6 +3,9 @@ import { RootProvider } from 'fumadocs-ui/provider';
|
||||
import { Inter } from 'next/font/google';
|
||||
import type { ReactNode } from 'react';
|
||||
import { PHProvider, PostHogPageView } from '@/providers/posthog-provider';
|
||||
import { AnalyticsTracker } from '@/components/analytics-tracker';
|
||||
import { CookieConsent } from '@/components/cookie-consent';
|
||||
import { Footer } from '@/components/footer';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
const inter = Inter({
|
||||
@@ -20,9 +23,12 @@ export default function Layout({ children }: { children: ReactNode }) {
|
||||
<Suspense fallback={null}>
|
||||
<PostHogPageView />
|
||||
</Suspense>
|
||||
<AnalyticsTracker />
|
||||
<RootProvider search={{ options: { api: '/docs/api/search' } }}>
|
||||
{children}
|
||||
</RootProvider>
|
||||
<Footer />
|
||||
<CookieConsent />
|
||||
</PHProvider>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
71
docs/src/components/analytics-tracker.tsx
Normal file
71
docs/src/components/analytics-tracker.tsx
Normal file
@@ -0,0 +1,71 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
import posthog from 'posthog-js';
|
||||
|
||||
export function AnalyticsTracker() {
|
||||
useEffect(() => {
|
||||
const handleClick = (e: MouseEvent) => {
|
||||
const target = e.target as HTMLElement;
|
||||
const link = target.closest('a');
|
||||
|
||||
if (!link) return;
|
||||
|
||||
const href = link.href;
|
||||
const text = link.textContent || link.getAttribute('aria-label') || '';
|
||||
|
||||
if (href.includes('github.com/trycua')) {
|
||||
posthog.capture('github_link_clicked', {
|
||||
url: href,
|
||||
link_text: text,
|
||||
page: window.location.pathname,
|
||||
});
|
||||
}
|
||||
|
||||
if (href.includes('discord.com/invite') || href.includes('discord.gg')) {
|
||||
posthog.capture('discord_link_clicked', {
|
||||
url: href,
|
||||
link_text: text,
|
||||
page: window.location.pathname,
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
(href.includes('trycua.com') && !href.includes('trycua.com/docs')) ||
|
||||
href.includes('cua.ai')
|
||||
) {
|
||||
posthog.capture('main_website_clicked', {
|
||||
url: href,
|
||||
link_text: text,
|
||||
page: window.location.pathname,
|
||||
});
|
||||
}
|
||||
|
||||
if (link.hostname && link.hostname !== window.location.hostname) {
|
||||
if (
|
||||
href.includes('github.com/trycua') ||
|
||||
href.includes('discord.com') ||
|
||||
href.includes('trycua.com') ||
|
||||
href.includes('cua.ai')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
posthog.capture('external_link_clicked', {
|
||||
url: href,
|
||||
link_text: text,
|
||||
page: window.location.pathname,
|
||||
domain: link.hostname,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener('click', handleClick);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('click', handleClick);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
}
|
||||
44
docs/src/components/cookie-consent.tsx
Normal file
44
docs/src/components/cookie-consent.tsx
Normal file
@@ -0,0 +1,44 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import posthog from 'posthog-js';
|
||||
|
||||
export function CookieConsent() {
|
||||
const [isVisible, setIsVisible] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
// Check if user has already accepted cookies
|
||||
const hasAccepted = localStorage.getItem('cookie-consent');
|
||||
if (!hasAccepted) {
|
||||
setIsVisible(true);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handleAccept = () => {
|
||||
localStorage.setItem('cookie-consent', 'accepted');
|
||||
setIsVisible(false);
|
||||
|
||||
// Track cookie acceptance
|
||||
posthog.capture('cookie_consent_accepted', {
|
||||
page: window.location.pathname,
|
||||
});
|
||||
};
|
||||
|
||||
if (!isVisible) return null;
|
||||
|
||||
return (
|
||||
<div className="fixed bottom-0 left-0 right-0 z-50 bg-fd-background border-t border-fd-border shadow-lg">
|
||||
<div className="container mx-auto px-4 py-2 flex flex-col sm:flex-row items-center justify-between gap-3">
|
||||
<p className="text-xs text-fd-muted-foreground">
|
||||
This site uses cookies for website functionality, analytics, and personalized content.
|
||||
</p>
|
||||
<button
|
||||
onClick={handleAccept}
|
||||
className="px-4 py-1 text-xs bg-fd-primary text-fd-primary-foreground rounded hover:opacity-90 transition-opacity whitespace-nowrap"
|
||||
>
|
||||
Okay
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
16
docs/src/components/footer.tsx
Normal file
16
docs/src/components/footer.tsx
Normal file
@@ -0,0 +1,16 @@
|
||||
export function Footer() {
|
||||
return (
|
||||
<footer className="mt-auto border-t border-fd-border py-4">
|
||||
<div className="container mx-auto px-4 flex justify-end">
|
||||
<a
|
||||
href="https://www.cua.ai/cookie-policy"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-sm text-fd-muted-foreground hover:text-fd-foreground transition-colors"
|
||||
>
|
||||
Cookie Policy
|
||||
</a>
|
||||
</div>
|
||||
</footer>
|
||||
);
|
||||
}
|
||||
@@ -3,6 +3,12 @@ import * as TabsComponents from 'fumadocs-ui/components/tabs';
|
||||
import type { MDXComponents } from 'mdx/types';
|
||||
import { Mermaid } from './components/mermaid';
|
||||
import IOU from './components/iou';
|
||||
import {
|
||||
EditableCodeBlock,
|
||||
EditableValue,
|
||||
EditableForm,
|
||||
EditableInput,
|
||||
} from './components/editable-code-block';
|
||||
|
||||
// use this function to get MDX components, you will need it for rendering MDX
|
||||
export function getMDXComponents(components?: MDXComponents): MDXComponents {
|
||||
@@ -10,6 +16,10 @@ export function getMDXComponents(components?: MDXComponents): MDXComponents {
|
||||
...defaultMdxComponents,
|
||||
Mermaid,
|
||||
IOU,
|
||||
EditableCodeBlock,
|
||||
EditableValue,
|
||||
EditableForm,
|
||||
EditableInput,
|
||||
...TabsComponents,
|
||||
...components,
|
||||
};
|
||||
|
||||
@@ -30,7 +30,6 @@ export function PostHogPageView(): null {
|
||||
url = url + `?${searchParams.toString()}`;
|
||||
}
|
||||
|
||||
console.log('[PostHog] Capturing pageview:', url);
|
||||
posthog.capture('$pageview', {
|
||||
$current_url: url,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user