Skip to content

Commit 084c5da

Browse files
authored
Merge pull request #17 from alexmarqs/chore/add-posthog
feat: add .env.example for PostHog configuration and remove unused an…
2 parents 7e159b0 + 055de0d commit 084c5da

File tree

4 files changed

+7
-37
lines changed

4 files changed

+7
-37
lines changed
File renamed without changes.

packages/analytics/src/client/hooks.tsx

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { useTrackAnalytics } from "./hooks";
21
import { PostHogProvider } from "./providers";
32

4-
export { PostHogProvider as AnalyticsProvider, useTrackAnalytics };
3+
export { PostHogProvider as AnalyticsProvider };

packages/analytics/src/client/providers.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
"use client";
22

33
import { usePathname, useSearchParams } from "next/navigation";
4+
import { usePostHog } from "posthog-js/react";
45
import { Suspense, useEffect } from "react";
56

67
import posthog from "posthog-js";
78
import { PostHogProvider as PHProvider } from "posthog-js/react";
8-
import { useTrackAnalytics } from ".";
99
import { isProd } from "./utils";
1010

1111
export function PostHogProvider({ children }: { children: React.ReactNode }) {
1212
useEffect(() => {
1313
if (!isProd) {
14-
console.log("Mock analytics init");
14+
console.log("Analytics disabled in non-production environment");
1515
return;
1616
}
1717

@@ -34,19 +34,18 @@ export function PostHogProvider({ children }: { children: React.ReactNode }) {
3434
function PostHogPageView() {
3535
const pathname = usePathname();
3636
const searchParams = useSearchParams();
37-
const { track } = useTrackAnalytics();
37+
const posthog = usePostHog();
3838

39-
// Track pageviews
4039
useEffect(() => {
41-
if (pathname) {
40+
if (pathname && posthog) {
4241
let url = window.origin + pathname;
4342
if (searchParams.toString()) {
4443
url = url + "?" + searchParams.toString();
4544
}
4645

47-
track({ event: "$pageview", $current_url: url });
46+
posthog.capture("$pageview", { $current_url: url });
4847
}
49-
}, [pathname, searchParams, track]);
48+
}, [pathname, searchParams, posthog]);
5049

5150
return null;
5251
}

0 commit comments

Comments
 (0)