Skip to content

Commit fb4a343

Browse files
Merge branch 'main' into brendan/bitbucket-server-sso
2 parents e1ecf25 + 5a00847 commit fb4a343

File tree

8 files changed

+643
-230
lines changed

8 files changed

+643
-230
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Added PostHog events for chat UI interactions (details card expand/collapse, copy answer, table of contents toggle) and repo tracking in `wa_chat_message_sent`. [#922](https://github.com/sourcebot-dev/sourcebot/pull/922)
1212
- Added Bitbucket Cloud OAuth identity provider support (`provider: "bitbucket-cloud"`) for SSO and account-linked permission syncing. [#924](https://github.com/sourcebot-dev/sourcebot/pull/924)
1313
- Added permission syncing support for Bitbucket Cloud. [#925](https://github.com/sourcebot-dev/sourcebot/pull/925)
14+
- Added `wa_user_created` PostHog event fired on successful user sign-up. [#933](https://github.com/sourcebot-dev/sourcebot/pull/933)
15+
- Added `wa_askgh_login_wall_prompted` PostHog event fired when an unauthenticated user attempts to ask a question on Ask GitHub. [#933](https://github.com/sourcebot-dev/sourcebot/pull/933)
1416
- Added Bitbucket Server (Data Center) OAuth 2.0 SSO identity provider support (`provider: "bitbucket-server"`). [#934](https://github.com/sourcebot-dev/sourcebot/pull/934)
1517

1618
### Changed

packages/web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"@opentelemetry/api-logs": "^0.203.0",
6464
"@opentelemetry/instrumentation": "^0.203.0",
6565
"@opentelemetry/sdk-logs": "^0.203.0",
66+
"@posthog/ai": "^7.8.10",
6667
"@radix-ui/react-accordion": "^1.2.11",
6768
"@radix-ui/react-alert-dialog": "^1.1.5",
6869
"@radix-ui/react-avatar": "^1.1.2",

packages/web/src/app/[domain]/askgh/[owner]/[repo]/components/landingPage.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type { IdentityProviderMetadata } from "@/lib/identityProviders";
1414
import { Descendant, Transforms } from "slate";
1515
import { useSlate } from "slate-react";
1616
import { useCallback, useEffect, useMemo, useState, useRef } from "react";
17+
import { captureEvent } from "@/hooks/useCaptureEvent";
1718

1819
const PENDING_MESSAGE_KEY = "askgh_pending_message";
1920

@@ -55,6 +56,7 @@ export const LandingPage = ({
5556
// Intercept submit to check auth status
5657
const handleSubmit = useCallback((children: Descendant[]) => {
5758
if (!isAuthenticated) {
59+
captureEvent('wa_askgh_login_wall_prompted', {});
5860
// Store message in sessionStorage to survive OAuth redirect
5961
sessionStorage.setItem(PENDING_MESSAGE_KEY, JSON.stringify(children));
6062
setIsLoginModalOpen(true);

packages/web/src/features/chat/actions.ts

Lines changed: 239 additions & 216 deletions
Large diffs are not rendered by default.

packages/web/src/lib/authUtils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export const onCreateUser = async ({ user }: { user: AuthJsUser }) => {
107107
type: "org"
108108
}
109109
});
110-
} else if (!defaultOrg.memberApprovalRequired) {
110+
} else if (!defaultOrg.memberApprovalRequired) {
111111
const hasAvailability = await orgHasAvailability(defaultOrg.domain);
112112
if (!hasAvailability) {
113113
logger.warn(`onCreateUser: org ${SINGLE_TENANT_ORG_ID} has reached max capacity. User ${user.id} was not added to the org.`);
@@ -123,6 +123,10 @@ export const onCreateUser = async ({ user }: { user: AuthJsUser }) => {
123123
});
124124
}
125125

126+
// Dynamic import to avoid circular dependency:
127+
// authUtils -> posthog -> auth -> authUtils
128+
const { captureEvent } = await import("@/lib/posthog");
129+
await captureEvent('wa_user_created', { userId: user.id });
126130
};
127131

128132

packages/web/src/lib/posthog.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const getPostHogCookie = (cookieStore: Pick<RequestCookies, 'get'>): PostHogCook
5252
/**
5353
* Attempts to retrieve the distinct id of the current user.
5454
*/
55-
const tryGetDistinctId = async () => {
55+
export const tryGetPostHogDistinctId = async () => {
5656
// First, attempt to retrieve the distinct id from the cookie.
5757
const cookieStore = await cookies();
5858
const cookie = getPostHogCookie(cookieStore);
@@ -77,22 +77,27 @@ const tryGetDistinctId = async () => {
7777
return apiKey?.createdById;
7878
}
7979

80+
export const createPostHogClient = async () => {
81+
const posthog = new PostHog(env.POSTHOG_PAPIK, {
82+
host: 'https://us.i.posthog.com',
83+
flushAt: 1,
84+
flushInterval: 0
85+
});
86+
87+
return posthog;
88+
}
89+
8090
export async function captureEvent<E extends PosthogEvent>(event: E, properties: PosthogEventMap[E]) {
8191
if (env.SOURCEBOT_TELEMETRY_DISABLED === 'true') {
8292
return;
8393
}
8494

85-
const distinctId = await tryGetDistinctId();
95+
const distinctId = await tryGetPostHogDistinctId();
96+
const posthog = await createPostHogClient();
8697

8798
const headersList = await headers();
8899
const host = headersList.get("host") ?? undefined;
89100

90-
const posthog = new PostHog(env.POSTHOG_PAPIK, {
91-
host: 'https://us.i.posthog.com',
92-
flushAt: 1,
93-
flushInterval: 0
94-
})
95-
96101
posthog.capture({
97102
event,
98103
properties: {

packages/web/src/lib/posthogEvents.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ export type PosthogEventMap = {
227227
chatId: string,
228228
isExpanded: boolean,
229229
},
230+
wa_user_created: {
231+
userId: string,
232+
},
233+
//////////////////////////////////////////////////////////////////
234+
wa_askgh_login_wall_prompted: {},
230235
//////////////////////////////////////////////////////////////////
231236
wa_demo_docs_link_pressed: {},
232237
wa_demo_search_example_card_pressed: {

0 commit comments

Comments
 (0)