Skip to content

Commit

Permalink
chore: update analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasfrancisco committed Jan 22, 2025
1 parent c745f15 commit ebbfb25
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 44 deletions.
18 changes: 11 additions & 7 deletions apps/blog/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Fira_Sans, Fira_Mono } from 'next/font/google';
import './globals.css';
import { Footer } from '@/components/footer';
import { Toaster } from '@/components/ui/sonner';
import { AnalyticsProvider, PageTracker } from '@ds-project/services/analytics';

const fontSans = Fira_Sans({
variable: '--font-sans',
Expand All @@ -28,13 +29,16 @@ export default function RootLayout({
}>) {
return (
<html lang="en">
<body
className={`${fontSans.variable} ${fontMono.variable} antialiased font-[family-name:var(--font-sans)]`}
>
<main className="mx-auto max-w-2xl px-4 py-16">{children}</main>
<Footer />
<Toaster />
</body>
<AnalyticsProvider>
<body
className={`${fontSans.variable} ${fontMono.variable} antialiased font-[family-name:var(--font-sans)]`}
>
<main className="mx-auto max-w-2xl px-4 py-16">{children}</main>
<Footer />
<Toaster />
<PageTracker />
</body>
</AnalyticsProvider>
</html>
);
}
17 changes: 0 additions & 17 deletions apps/engine/src/app/_components/analytics-page-tracker.tsx

This file was deleted.

15 changes: 2 additions & 13 deletions apps/engine/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,12 @@ import { Inter } from 'next/font/google';
import { cn } from '@/lib/css';
import { Toaster } from '@ds-project/components';
import { Favicon } from '@/components';
import dynamic from 'next/dynamic';
import { getMetadata } from '@/lib/metadata';
import { TooltipProvider } from '@ds-project/components';
import { AnalyticsProvider } from '@ds-project/services/analytics';
import { AnalyticsProvider, PageTracker } from '@ds-project/services/analytics';

const inter = Inter({ subsets: ['latin'] });

const AnalyticsPageView = dynamic(
() =>
import('@ds-project/services/analytics').then(
(module) => module.AnalyticsPageView
),
{
ssr: false,
}
);

export const metadata = getMetadata();

export default function RootLayout({
Expand All @@ -41,7 +30,7 @@ export default function RootLayout({
inter.className
)}
>
<AnalyticsPageView />
<PageTracker />
{children}
<Toaster />
</body>
Expand Down
8 changes: 4 additions & 4 deletions packages/services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
"author": "",
"type": "module",
"exports": {
"./github": {
"types": "./dist/github/index.d.ts",
"default": "./src/github/index.ts"
},
"./analytics": {
"types": "./dist/analytics/index.d.ts",
"default": "./src/analytics/index.ts"
},
"./analytics/rewrites.mjs": {
"types": "./dist/analytics/rewrites/index.d.ts",
"default": "./src/analytics/rewrites.mjs"
},
"./github": {
"types": "./dist/github/index.d.ts",
"default": "./src/github/index.ts"
}
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/services/src/analytics/env/client-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const clientEnv = createEnv({
.enum(['development', 'preview', 'production'])
.optional(),
NEXT_PUBLIC_POSTHOG_KEY: z.string().min(1),
NEXT_PUBLIC_ARE_ANALYTICS_ENABLED: z.boolean().optional(),
NEXT_PUBLIC_ARE_ANALYTICS_ENABLED: z.boolean(),
},
runtimeEnv: {
NEXT_PUBLIC_VERCEL_ENV: process.env.NEXT_PUBLIC_VERCEL_ENV,
Expand Down
2 changes: 1 addition & 1 deletion packages/services/src/analytics/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './track-page-view';
export * from './provider';
export * from './page-tracker/page-tracker';
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { usePathname, useSearchParams } from 'next/navigation';
import { useEffect } from 'react';
import { usePostHog } from 'posthog-js/react';

export function AnalyticsPageView(): null {
export function TrackPageView(): null {
const pathname = usePathname();
const searchParams = useSearchParams();
const posthog = usePostHog();
Expand Down
1 change: 1 addition & 0 deletions packages/services/src/analytics/page-tracker/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './page-tracker';
14 changes: 14 additions & 0 deletions packages/services/src/analytics/page-tracker/page-tracker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use client';

import dynamic from 'next/dynamic';

const TrackPageView = dynamic(
() => import('./_track-page-view').then((module) => module.TrackPageView),
{
ssr: false,
}
);

export const PageTracker = () => {
return <TrackPageView />;
};

0 comments on commit ebbfb25

Please sign in to comment.