:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(integrations): report the correct surface when linking an existing GitHub install (#93132)
posthog[bot]d1562cb02471
diff --git a/frontend/src/scenes/integrations/components/GithubIntegration.test.tsx b/frontend/src/scenes/integrations/components/GithubIntegration.test.tsxindex ad5afdf24b57..3337d44a2d7c 100644--- a/frontend/src/scenes/integrations/components/GithubIntegration.test.tsx+++ b/frontend/src/scenes/integrations/components/GithubIntegration.test.tsx@@ -5,6 +5,8 @@ import userEvent from '@testing-library/user-event'import { Provider } from 'kea'import posthog from 'posthog-js'+import type { IntegrationConnectSurface } from 'lib/integrations/utils'+import { useMocks } from '~/mocks/jest'import { initKeaTests } from '~/test/init'@@ -13,18 +15,26 @@ import { GithubIntegration } from './GithubIntegration'describe('GithubIntegration', () => {let captureSpy: jest.SpyInstancelet installRequests: Record<string, unknown>[]+ let availableInstallations: Record<string, unknown>[]beforeEach(() => {installRequests = []+ availableInstallations = []useMocks({get: {'/api/environments/:team_id/integrations': { results: [] },- '/api/projects/:team_id/integrations/github/available_installations/': { installations: [] },+ '/api/projects/:team_id/integrations/github/available_installations/': () => [+ 200,+ { installations: availableInstallations, personal_github_connected: false },+ ],'/api/users/@me/integrations/github/install_requests/': () => [200,{ results: installRequests, install_url: 'https://github.com/apps/posthog-dev/installations/new' },],},+ post: {+ '/api/projects/:team_id/integrations/github/link_existing/': { id: 1 },+ },})initKeaTests()captureSpy = jest.spyOn(posthog, 'capture').mockReturnValue(undefined as any)@@ -62,6 +72,31 @@ describe('GithubIntegration', () => {expect(connectClicks()).toEqual([])})+ it.each([+ ['settings', 'settings_link_existing'],+ ['inbox_welcome', 'inbox_welcome'],+ ])(+ 'reports linking an existing installation with the %s surface as %s',+ async (connectSurface, expectedSurface) => {+ availableInstallations = [{ installation_id: '55555', account_name: 'posthog-org', account_type: null }]++ render(+ <Provider>+ <GithubIntegration connectSurface={connectSurface as IntegrationConnectSurface} />+ </Provider>+ )++ const button = await screen.findByText(/^Connect to /)+ await userEvent.click(button)++ await waitFor(() =>+ expect(connectClicks()).toEqual([+ { integration: 'github', integration_kind: 'github', surface: expectedSurface },+ ])+ )+ }+ )+it.each([['pending', 'GitHub sent your request', 'Copy message for your org owner'],['approved', 'An organization owner approved the PostHog app for', 'Finish connecting'],diff --git a/frontend/src/scenes/integrations/components/GithubIntegration.tsx b/frontend/src/scenes/integrations/components/GithubIntegration.tsxindex cbd302d6a8c0..039474a30f67 100644--- a/frontend/src/scenes/integrations/components/GithubIntegration.tsx+++ b/frontend/src/scenes/integrations/components/GithubIntegration.tsx@@ -110,8 +110,10 @@ export function GithubIntegration({onLink={(installationId) => {// Reusing an existing install never leaves PostHog, so it's a// connect that skips GitHub entirely — worth separating from the- // clicks that redirect out.- reportConnect('settings_link_existing')+ // clicks that redirect out. Falls back to `connectSurface` like+ // every other button here, instead of a fixed literal, so the+ // surface still says where the click happened.+ reportConnect(connectSurface === 'settings' ? 'settings_link_existing' : undefined)linkExistingGithubInstallation(installationId)}}projectName={currentTeam?.name}