Skip to content

Commit 3cb5e38

Browse files
committed
Merge branch 'canary' into feat/storybook-upgrade
2 parents c138ae1 + e3aa9cd commit 3cb5e38

33 files changed

+1526
-1908
lines changed

apps/docs/.env.example

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ NEXT_PUBLIC_PREVIEW=true/false
1616

1717
## Featurebase
1818
NEXT_PUBLIC_FB_FEEDBACK_ORG=
19-
NEXT_PUBLIC_FB_FEEDBACK_URL=
19+
NEXT_PUBLIC_FB_FEEDBACK_URL=
20+
21+
# PostHog
22+
NEXT_PUBLIC_POSTHOG_KEY=your-posthog-key
23+
NEXT_PUBLIC_POSTHOG_HOST=your-posthog-host

apps/docs/app/providers.tsx

+30-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
"use client";
22

3+
import type {ReactNode} from "react";
4+
35
import * as React from "react";
46
import {NextUIProvider} from "@nextui-org/react";
57
import {ThemeProvider as NextThemesProvider} from "next-themes";
68
import {ThemeProviderProps} from "next-themes/dist/types";
79
import {useRouter} from "next/navigation";
10+
import {useEffect} from "react";
11+
import posthog from "posthog-js";
12+
import {PostHogProvider} from "posthog-js/react";
13+
14+
import {__PROD__} from "@/utils";
815

916
export interface ProvidersProps {
1017
children: React.ReactNode;
@@ -14,9 +21,29 @@ export interface ProvidersProps {
1421
export function Providers({children, themeProps}: ProvidersProps) {
1522
const router = useRouter();
1623

24+
const ProviderWrapper = ({children}: {children: ReactNode}) => {
25+
useEffect(() => {
26+
if (typeof window !== "undefined") {
27+
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
28+
api_host: "/ingest",
29+
person_profiles: "identified_only",
30+
ui_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
31+
});
32+
}
33+
}, []);
34+
35+
if (__PROD__) {
36+
return <PostHogProvider client={posthog}>{children}</PostHogProvider>;
37+
}
38+
39+
return children;
40+
};
41+
1742
return (
18-
<NextUIProvider navigate={router.push}>
19-
<NextThemesProvider {...themeProps}>{children}</NextThemesProvider>
20-
</NextUIProvider>
43+
<ProviderWrapper>
44+
<NextUIProvider navigate={router.push}>
45+
<NextThemesProvider {...themeProps}>{children}</NextThemesProvider>
46+
</NextUIProvider>
47+
</ProviderWrapper>
2148
);
2249
}

apps/docs/components/blog-post.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ import Balancer from "react-wrap-balancer";
66
import {format, parseISO} from "date-fns";
77
import NextLink from "next/link";
88
import {AnimatePresence, motion} from "framer-motion";
9+
import {usePostHog} from "posthog-js/react";
910

1011
import {useIsMounted} from "@/hooks/use-is-mounted";
11-
import {trackEvent} from "@/utils/va";
1212

1313
const BlogPostCard = (post: BlogPost) => {
1414
const isMounted = useIsMounted();
1515

16+
const posthog = usePostHog();
17+
1618
const handlePress = () => {
17-
trackEvent("BlogPostCard - Selection", {
19+
posthog.capture("BlogPostCard - Selection", {
1820
name: post.title,
1921
action: "click",
2022
category: "blog",

apps/docs/components/cmdk.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {isAppleDevice, isWebKit} from "@react-aria/utils";
1515
import {create} from "zustand";
1616
import {isEmpty, intersectionBy} from "@nextui-org/shared-utils";
1717
import {writeStorage, useLocalStorage} from "@rehooks/local-storage";
18+
import {usePostHog} from "posthog-js/react";
1819

1920
import {
2021
DocumentCodeBoldIcon,
@@ -25,7 +26,6 @@ import {
2526

2627
import searchData from "@/config/search-meta.json";
2728
import {useUpdateEffect} from "@/hooks/use-update-effect";
28-
import {trackEvent} from "@/utils/va";
2929

3030
const hideOnPaths = ["examples"];
3131

@@ -139,6 +139,8 @@ export const Cmdk: FC<{}> = () => {
139139

140140
const {isOpen, onClose, onOpen} = useCmdkStore();
141141

142+
const posthog = usePostHog();
143+
142144
const [recentSearches] = useLocalStorage<SearchResultItem[]>(RECENT_SEARCHES_KEY);
143145

144146
const addToRecentSearches = (item: SearchResultItem) => {
@@ -196,7 +198,7 @@ export const Cmdk: FC<{}> = () => {
196198

197199
const matches = intersectionBy(...matchesForEachWord, "objectID").slice(0, MAX_RESULTS);
198200

199-
trackEvent("Cmdk - Search", {
201+
posthog.capture("Cmdk - Search", {
200202
name: "cmdk - search",
201203
action: "search",
202204
category: "cmdk",
@@ -219,7 +221,7 @@ export const Cmdk: FC<{}> = () => {
219221
e.preventDefault();
220222
isOpen ? onClose() : onOpen();
221223

222-
trackEvent("Cmdk - Open/Close", {
224+
posthog.capture("Cmdk - Open/Close", {
223225
name: "cmdk - open/close",
224226
action: "keydown",
225227
category: "cmdk",
@@ -241,7 +243,7 @@ export const Cmdk: FC<{}> = () => {
241243
router.push(item.url);
242244
addToRecentSearches(item);
243245

244-
trackEvent("Cmdk - ItemSelect", {
246+
posthog.capture("Cmdk - ItemSelect", {
245247
name: item.content,
246248
action: "click",
247249
category: "cmdk",

apps/docs/components/demos/custom-button.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import {useRef} from "react";
44
import {Button} from "@nextui-org/react";
5-
6-
import {trackEvent} from "@/utils/va";
5+
import {usePostHog} from "posthog-js/react";
76

87
export const CustomButton = () => {
98
const buttonRef = useRef<HTMLButtonElement | null>(null);
9+
const posthog = usePostHog();
1010

1111
const handleConfetti = async () => {
1212
const {clientWidth, clientHeight} = document.documentElement;
@@ -29,7 +29,7 @@ export const CustomButton = () => {
2929
},
3030
});
3131

32-
trackEvent("LandingPage - Confetti Button", {
32+
posthog.capture("LandingPage - Confetti Button", {
3333
action: "press",
3434
category: "landing-page",
3535
});

apps/docs/components/docs/components/component-links.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {Button, ButtonProps, Code, Link, Tooltip} from "@nextui-org/react";
22
import {ReactNode} from "react";
33
import Balancer from "react-wrap-balancer";
4+
import {usePostHog} from "posthog-js/react";
45

56
import {GithubIcon, NpmIcon, AdobeIcon, StorybookIcon, NextJsIcon} from "@/components/icons";
67
import {COMPONENT_PATH, COMPONENT_THEME_PATH} from "@/libs/github/constants";
7-
import {trackEvent} from "@/utils/va";
88

99
export interface ComponentLinksProps {
1010
component: string;
@@ -26,10 +26,12 @@ const ButtonLink = ({
2626
href: string;
2727
tooltip?: string | ReactNode;
2828
}) => {
29+
const posthog = usePostHog();
30+
2931
const handlePress = () => {
3032
if (!href) return;
3133

32-
trackEvent("ComponentLinks - Click", {
34+
posthog.capture("ComponentLinks - Click", {
3335
category: "docs",
3436
action: "click",
3537
data: href || "",

apps/docs/components/docs/pager.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import * as React from "react";
44
import {Link} from "@nextui-org/react";
5+
import {usePostHog} from "posthog-js/react";
56
import {useRouter} from "next/navigation";
67
import {ChevronIcon} from "@nextui-org/shared-icons";
78

89
import manifest from "@/config/routes.json";
910
import {removeFromLast} from "@/utils";
1011
import {Route} from "@/libs/docs/page";
1112
import {useDocsRoute} from "@/hooks/use-docs-route";
12-
import {trackEvent} from "@/utils/va";
1313

1414
export interface FooterNavProps {
1515
currentRoute?: Route;
@@ -20,8 +20,10 @@ export const DocsPager: React.FC<FooterNavProps> = ({currentRoute}) => {
2020

2121
const {prevRoute, nextRoute} = useDocsRoute(manifest.routes, currentRoute);
2222

23+
const posthog = usePostHog();
24+
2325
const handlePress = (path: string) => {
24-
trackEvent("DocsPager - Click", {
26+
posthog.capture("DocsPager - Click", {
2527
category: "docs",
2628
action: "click",
2729
data: path || "",

apps/docs/components/docs/sidebar.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22

33
import {FC, useEffect, useState} from "react";
4+
import {usePostHog} from "posthog-js/react";
45
import {ChevronIcon} from "@nextui-org/shared-icons";
56
import {CollectionBase, Expandable, MultipleSelection, Node, ItemProps} from "@react-types/shared";
67
import {BaseItem} from "@nextui-org/aria-utils";
@@ -27,7 +28,6 @@ import {getRoutePaths} from "./utils";
2728

2829
import {Route} from "@/libs/docs/page";
2930
import {TreeKeyboardDelegate} from "@/utils/tree-keyboard-delegate";
30-
import {trackEvent} from "@/utils/va";
3131
import {FbFeedbackButton} from "@/components/featurebase/fb-feedback-button";
3232
import {FbChangelogButton} from "@/components/featurebase/fb-changelog-button";
3333
import {FbRoadmapLink} from "@/components/featurebase/fb-roadmap-link";
@@ -66,6 +66,7 @@ function TreeItem<T>(props: TreeItemProps<T>) {
6666

6767
const router = useRouter();
6868
const pathname = usePathname();
69+
const posthog = usePostHog();
6970

7071
const paths = item.props.path
7172
? getRoutePaths(item.props.path, item.props?.tag)
@@ -109,7 +110,7 @@ function TreeItem<T>(props: TreeItemProps<T>) {
109110
} else {
110111
router.push(paths.pathname);
111112

112-
trackEvent("SidebarDocs", {
113+
posthog.capture("SidebarDocs", {
113114
category: "docs",
114115
action: "click",
115116
data: paths.pathname || "",

apps/docs/components/featurebase/fb-changelog-button.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
"use client";
22

33
import {useEffect} from "react";
4-
5-
import {trackEvent} from "@/utils/va";
4+
import {usePostHog} from "posthog-js/react";
65

76
type Props = {
87
className?: string;
98
};
109

1110
// ref: https://developers.featurebase.app/install/changelog-widget/install
1211
export const FbChangelogButton = ({className}: Props) => {
12+
const posthog = usePostHog();
13+
1314
useEffect(() => {
1415
const win = window as any;
1516

@@ -31,7 +32,7 @@ export const FbChangelogButton = ({className}: Props) => {
3132
const fbButtonOnClick = () => {
3233
(window as any).Featurebase("manually_open_changelog_popup");
3334

34-
trackEvent("Featurebase - Changelog", {
35+
posthog.capture("Featurebase - Changelog", {
3536
name: "featurebase-changelog",
3637
action: "press",
3738
category: "featurebase",

apps/docs/components/featurebase/fb-feedback-button.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
"use client";
22

33
import {useEffect} from "react";
4-
5-
import {trackEvent} from "@/utils/va";
4+
import {usePostHog} from "posthog-js/react";
65

76
type Props = {
87
className?: string;
98
};
109

1110
// ref: https://developers.featurebase.app/install/feedback-widget/setup
1211
export const FbFeedbackButton = ({className}: Props) => {
12+
const posthog = usePostHog();
13+
1314
useEffect(() => {
1415
const win = window as any;
1516

@@ -27,7 +28,7 @@ export const FbFeedbackButton = ({className}: Props) => {
2728
}, []);
2829

2930
const fbButtonOnClick = () => {
30-
trackEvent("Featurebase - Feedback", {
31+
posthog.capture("Featurebase - Feedback", {
3132
name: "featurebase-feedback",
3233
action: "press",
3334
category: "featurebase",

apps/docs/components/featurebase/fb-roadmap-link.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
"use client";
22

33
import NextLink from "next/link";
4+
import {usePostHog} from "posthog-js/react";
45
import arrowRightUpIcon from "@iconify/icons-solar/arrow-right-up-linear";
56
import {Icon} from "@iconify/react/dist/offline";
67
import {clsx} from "@nextui-org/shared-utils";
78

8-
import {trackEvent} from "@/utils/va";
9-
109
type Props = {
1110
className?: string;
1211
innerClassName?: string;
1312
};
1413

1514
export const FbRoadmapLink = ({className, innerClassName}: Props) => {
15+
const posthog = usePostHog();
16+
1617
const fbLinkOnClick = () => {
17-
trackEvent("Featurebase - Roadmap", {
18+
posthog.capture("Featurebase - Roadmap", {
1819
name: "featurebase-roadmap",
1920
action: "press",
2021
category: "featurebase",

apps/docs/components/figma-button.tsx

+23-20
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
"use client";
22

33
import {Button, Link} from "@nextui-org/react";
4+
import {usePostHog} from "posthog-js/react";
45

5-
import {trackEvent} from "@/utils/va";
6+
export const FigmaButton = () => {
7+
const posthog = usePostHog();
68

7-
export const FigmaButton = () => (
8-
<Button
9-
isExternal
10-
showAnchorIcon
11-
as={Link}
12-
className="max-w-fit text-current"
13-
color="default"
14-
href="https://www.figma.com/community/file/1267584376234254760"
15-
variant="bordered"
16-
onPress={() => {
17-
trackEvent("FigmaPage - Open Figma Link", {
18-
action: "click",
19-
category: "figma",
20-
});
21-
}}
22-
>
23-
Open in Figma
24-
</Button>
25-
);
9+
return (
10+
<Button
11+
isExternal
12+
showAnchorIcon
13+
as={Link}
14+
className="max-w-fit text-current"
15+
color="default"
16+
href="https://www.figma.com/community/file/1267584376234254760"
17+
variant="bordered"
18+
onPress={() => {
19+
posthog.capture("FigmaPage - Open Figma Link", {
20+
action: "click",
21+
category: "figma",
22+
});
23+
}}
24+
>
25+
Open in Figma
26+
</Button>
27+
);
28+
};

0 commit comments

Comments
 (0)