Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

feat(open-knowledge): PostHog analytics for subscribe events (#2359)

sarah0cb0d4100361
diff --git a/packages/app/src/components/HelpPopover.tsx b/packages/app/src/components/HelpPopover.tsx
index 1379c6c2b..bafad630d 100644
--- a/packages/app/src/components/HelpPopover.tsx
+++ b/packages/app/src/components/HelpPopover.tsx
@@ -190,6 +190,7 @@ export const HelpPopover: FC = () => {
plus a gap rather than overlapping the menu. */}
<PopoverContent side="left" align="center" sideOffset={20} className="w-80">
<SubscribeForm
+ source="resources_menu"
autoFocus
onDismiss={() => setSubscribeOpen(false)}
onSuccess={() => subscribeCardStore.markSubscribed()}
diff --git a/packages/app/src/components/SubscribeCard.tsx b/packages/app/src/components/SubscribeCard.tsx
index 64c0f5940..8cdba2619 100644
--- a/packages/app/src/components/SubscribeCard.tsx
+++ b/packages/app/src/components/SubscribeCard.tsx
@@ -59,6 +59,7 @@ export function SubscribeCard({
>
<div className="px-3 py-2.5">
<SubscribeForm
+ source="post_update_card"
compactSubmit
description={<Trans>Product updates in your inbox.</Trans>}
onSuccess={() => {
diff --git a/packages/app/src/components/SubscribeForm.dom.test.tsx b/packages/app/src/components/SubscribeForm.dom.test.tsx
index 3d1901ab3..41725321a 100644
--- a/packages/app/src/components/SubscribeForm.dom.test.tsx
+++ b/packages/app/src/components/SubscribeForm.dom.test.tsx
@@ -17,7 +17,7 @@ mock.module('@/lib/subscribe', () => ({ submitSubscribe }));
async function renderForm(onSuccess?: () => void) {
const { SubscribeForm } = await import('./SubscribeForm');
- render(<SubscribeForm onSuccess={onSuccess} />);
+ render(<SubscribeForm source="resources_menu" onSuccess={onSuccess} />);
}
describe('SubscribeForm', () => {
@@ -44,7 +44,9 @@ describe('SubscribeForm', () => {
await userEvent.type(screen.getByTestId('subscribe-email'), '[email protected]');
await userEvent.click(screen.getByTestId('subscribe-submit'));
- await waitFor(() => expect(submitSubscribe).toHaveBeenCalledWith('[email protected]'));
+ await waitFor(() =>
+ expect(submitSubscribe).toHaveBeenCalledWith('[email protected]', 'resources_menu'),
+ );
expect(onSuccess).toHaveBeenCalledTimes(1);
expect(await screen.findByText(/Watch your inbox/i)).not.toBeNull();
expect(screen.queryByTestId('subscribe-email')).toBeNull();
diff --git a/packages/app/src/components/SubscribeForm.tsx b/packages/app/src/components/SubscribeForm.tsx
index 87db31a71..be2ad7e38 100644
--- a/packages/app/src/components/SubscribeForm.tsx
+++ b/packages/app/src/components/SubscribeForm.tsx
@@ -7,7 +7,7 @@ import { Controller, useForm } from 'react-hook-form';
import { z } from 'zod';
import { Button } from '@/components/ui/button';
import { InputGroup, InputGroupAddon, InputGroupInput } from '@/components/ui/input-group';
-import { submitSubscribe } from '@/lib/subscribe';
+import { type SubscribeSource, submitSubscribe } from '@/lib/subscribe';
import { cn } from '@/lib/utils';
interface SubscribeValues {
@@ -15,6 +15,7 @@ interface SubscribeValues {
}
export interface SubscribeFormProps {
+ source: SubscribeSource;
title?: ReactNode;
description?: ReactNode;
onSuccess?: () => void;
@@ -25,6 +26,7 @@ export interface SubscribeFormProps {
}
export function SubscribeForm({
+ source,
title,
description,
onSuccess,
@@ -55,7 +57,7 @@ export function SubscribeForm({
async function onSubmit(values: SubscribeValues) {
form.clearErrors('root');
- const result = await submitSubscribe(values.email);
+ const result = await submitSubscribe(values.email, source);
if (result.ok) {
setSubscribed(true);
onSuccess?.();
diff --git a/packages/app/src/lib/subscribe.ts b/packages/app/src/lib/subscribe.ts
index f11731aec..eb07acb62 100644
--- a/packages/app/src/lib/subscribe.ts
+++ b/packages/app/src/lib/subscribe.ts
@@ -1,15 +1,20 @@
const SUBSCRIBE_ENDPOINT = 'https://openknowledge.ai/api/subscribe';
+export type SubscribeSource = 'resources_menu' | 'post_update_card';
+
export type SubscribeResult =
| { ok: true }
| { ok: false; reason: 'invalid' | 'unavailable' | 'error' };
-export async function submitSubscribe(email: string): Promise<SubscribeResult> {
+export async function submitSubscribe(
+ email: string,
+ source: SubscribeSource,
+): Promise<SubscribeResult> {
try {
const response = await fetch(SUBSCRIBE_ENDPOINT, {
method: 'POST',
headers: { 'content-type': 'application/json' },
- body: JSON.stringify({ email }),
+ body: JSON.stringify({ email, source }),
signal: AbortSignal.timeout(15_000),
});
if (response.ok) {