Skip to content

Commit

Permalink
Add posthog (#2013)
Browse files Browse the repository at this point in the history
* posthog added to project

* added posthog
  • Loading branch information
tg339 authored Feb 2, 2025
1 parent b81d307 commit 071f57c
Show file tree
Hide file tree
Showing 8 changed files with 264 additions and 157 deletions.
1 change: 1 addition & 0 deletions apps/framework-docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ yarn-error.log*
# Sentry Auth Token
.sentryclirc

.env*.local
17 changes: 17 additions & 0 deletions apps/framework-docs/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,23 @@ const nextConfig = {
// 'Disable the Sentry SDK Debug Logger to Save Bundle Size':
// - disableLogger
},
async rewrites() {
return [
{
source: "/ingest/static/:path*",
destination: "https://us-assets.i.posthog.com/static/:path*",
},
{
source: "/ingest/:path*",
destination: "https://us.i.posthog.com/:path*",
},
{
source: "/ingest/decide",
destination: "https://us.i.posthog.com/decide",
},
];
},
skipTrailingSlashRedirect: true,
};

const sentryWebpackPluginOptions = {
Expand Down
1 change: 1 addition & 0 deletions apps/framework-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"next": "^14.2.15",
"nextra": "^2.13.2",
"nextra-theme-docs": "^2.13.2",
"posthog-js": "^1.214.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-server-dom-webpack": "^0.0.1",
Expand Down
2 changes: 1 addition & 1 deletion apps/framework-docs/src/components/callout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function Callout({ type, title, children }: CalloutProps) {
return (
<Card
className={cn(
"callout border b-[1px] rounded-3xl my-5 flex items-start w-full p-4 space-x-2",
"callout border b-[1px] my-5 flex items-start w-full p-4 space-x-2",
variantProps.color,
variantProps.border,
)}
Expand Down
4 changes: 2 additions & 2 deletions apps/framework-docs/src/components/cta-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export function CTACard({
variant = "default",
}: CTACardProps) {
return (
<Card className={cn("rounded-3xl h-full flex flex-col", className)}>
<Card className={cn("h-full flex flex-col", className)}>
<CardHeader>
<div className="flex gap-2">
<div className="flex gap-2 items-center">
<Icon className="h-[20px] w-[20px] text-purple-400" />
<SmallText className="text-primary text-purple-400 my-0">
{cardName}
Expand Down
7 changes: 6 additions & 1 deletion apps/framework-docs/src/components/two-columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from "@514labs/design-system-components/typography";

import { cn } from "@514labs/design-system-components/utils";
import { Card } from "@514labs/design-system-components/components";

interface ColumnProps {
heading: string;
Expand All @@ -35,5 +36,9 @@ export function Column({ heading, body, list, className }: ColumnProps) {
}

export function Columns({ children }: { children: React.ReactNode }) {
return <Grid className="mt-4 md:gap-x-0 border rounded-3xl">{children}</Grid>;
return (
<Card className="mt-4 md:gap-x-0">
<Grid>{children}</Grid>
</Card>
);
}
51 changes: 48 additions & 3 deletions apps/framework-docs/src/pages/_app.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,55 @@
import "@514labs/design-system-base/globals.css";
import RootLayout from "../components/layouts";
import { useEffect } from 'react'
import { useRouter } from 'next/router'
import Router from 'next/router'
import posthog from 'posthog-js'
import { PostHogProvider } from 'posthog-js/react'


export default function App({ Component, pageProps }) {
const router = useRouter();

useEffect(() => {
// Wait until Next.js router is ready to ensure query params are populated.
if (!router.isReady) return;

// Extract cross-site tracking params from Next.js router query.
// These are added by TrackLink as 'ph_distinct_id' and 'ph_session_id'.
const { ph_distinct_id, ph_session_id } = router.query;
let bootstrapData = {};

if (ph_distinct_id || ph_session_id) {
bootstrapData = {
...(ph_distinct_id && { distinct_id: ph_distinct_id }),
...(ph_session_id && { session_id: ph_session_id }),
};
}

posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, {
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST || 'https://us.i.posthog.com',
ui_host: 'https://us.posthog.com',
bootstrap: bootstrapData, // Bootstrap with IDs from the URL if provided.
// Enable debug mode in development
loaded: (posthogInstance) => {
if (process.env.NODE_ENV === 'development') posthogInstance.debug()
}
})

const handleRouteChange = () => posthog?.capture('$pageview')

Router.events.on('routeChangeComplete', handleRouteChange);

return () => {
Router.events.off('routeChangeComplete', handleRouteChange);
}
}, [router.isReady])

return (
<RootLayout>
<Component {...pageProps} />
</RootLayout>
<PostHogProvider client={posthog}>
<RootLayout>
<Component {...pageProps} />
</RootLayout>
</PostHogProvider>
);
}
Loading

0 comments on commit 071f57c

Please sign in to comment.