diff --git a/apps/core/lib/core/pubsub/consumers/posthog.ex b/apps/core/lib/core/pubsub/consumers/posthog.ex deleted file mode 100644 index ff0b72c17..000000000 --- a/apps/core/lib/core/pubsub/consumers/posthog.ex +++ /dev/null @@ -1,16 +0,0 @@ -defmodule Core.PubSub.Consumers.Posthog do - @moduledoc """ - Sends tracking events to our posthog - """ - use Piazza.PubSub.Consumer, - broadcaster: Core.PubSub.Broadcaster, - max_demand: 10 - - alias Core.PubSub.Hoggable - - def handle_event(event) do - with {event, id, attributes} <- Hoggable.hog(event) do - Posthog.capture(event, Map.put(attributes, :distinct_id, id)) - end - end -end diff --git a/apps/core/mix.exs b/apps/core/mix.exs index 5a0055474..2a6f7098e 100644 --- a/apps/core/mix.exs +++ b/apps/core/mix.exs @@ -85,7 +85,6 @@ defmodule Core.MixProject do {:ex_aws, "~> 2.4.0"}, {:ex_aws_s3, "~> 2.3.3"}, {:ex_aws_sts, "~> 2.3.0"}, - {:posthog, "~> 0.1"}, {:configparser_ex, "~> 4.0"}, {:sweet_xml, "~> 0.7.3"}, {:arc_ecto, "~> 0.11.3"}, diff --git a/apps/core/test/pubsub/posthog/repositories_test.exs b/apps/core/test/pubsub/posthog/repositories_test.exs deleted file mode 100644 index 139e35fb3..000000000 --- a/apps/core/test/pubsub/posthog/repositories_test.exs +++ /dev/null @@ -1,34 +0,0 @@ -defmodule Core.PubSub.Posthog.RepositoriesTest do - use Core.SchemaCase, async: true - use Mimic - alias Core.PubSub.Consumers - alias Core.PubSub - - describe "InstallationCreated" do - test "it will send a installation.created event" do - inst = insert(:installation) - expect(Posthog, :capture, fn "installation.created", attrs -> {:ok, attrs} end) - - event = %PubSub.InstallationCreated{item: inst} - {:ok, attrs} = Consumers.Posthog.handle_event(event) - - assert attrs.applicationID == inst.repository_id - assert attrs.distinct_id == inst.user_id - assert attrs.applicationName == inst.repository.name - end - end - - describe "InstallationDeleted" do - test "it will send a installation.deleted event" do - inst = insert(:installation) - expect(Posthog, :capture, fn "installation.deleted", attrs -> {:ok, attrs} end) - - event = %PubSub.InstallationDeleted{item: inst} - {:ok, attrs} = Consumers.Posthog.handle_event(event) - - assert attrs.applicationID == inst.repository_id - assert attrs.distinct_id == inst.user_id - assert attrs.applicationName == inst.repository.name - end - end -end diff --git a/apps/core/test/pubsub/posthog/users_test.exs b/apps/core/test/pubsub/posthog/users_test.exs deleted file mode 100644 index ea9ae9414..000000000 --- a/apps/core/test/pubsub/posthog/users_test.exs +++ /dev/null @@ -1,18 +0,0 @@ -defmodule Core.PubSub.Posthog.UsersTest do - use Core.SchemaCase, async: true - use Mimic - alias Core.PubSub.Consumers - alias Core.PubSub - - describe "UserCreated" do - test "it will log user.created" do - user = insert(:user) - expect(Posthog, :capture, fn "user.created", attrs -> {:ok, attrs} end) - - event = %PubSub.UserCreated{item: user} - {:ok, attrs} = Consumers.Posthog.handle_event(event) - - assert attrs.distinct_id == user.id - end - end -end diff --git a/apps/core/test/test_helper.exs b/apps/core/test/test_helper.exs index 094e85608..433893338 100644 --- a/apps/core/test/test_helper.exs +++ b/apps/core/test/test_helper.exs @@ -33,6 +33,5 @@ Mimic.copy(Core.Services.Shell.Pods) Mimic.copy(Vault) Mimic.copy(System) Mimic.copy(Core.Clients.Vault) -Mimic.copy(Posthog) {:ok, _} = Application.ensure_all_started(:ex_machina) diff --git a/config/config.exs b/config/config.exs index a841b5043..7bfdadf51 100644 --- a/config/config.exs +++ b/config/config.exs @@ -177,10 +177,6 @@ config :junit_formatter, print_report_file: true, automatic_create_dir?: true -config :posthog, - api_url: "https://posthog.plural.sh", - api_key: "phc_r0v4jbKz8Rr27mfqgO15AN5BMuuvnU8hCFedd6zpSDy" - config :core, :oidc_providers, github_actions: [ discovery_document_uri: "https://token.actions.githubusercontent.com/.well-known/openid-configuration", diff --git a/config/prod.exs b/config/prod.exs index f65166f75..d386de3f1 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -29,7 +29,6 @@ config :core, :consumers, [ Core.PubSub.Consumers.Audits, Core.PubSub.Consumers.Cache, Core.PubSub.Consumers.Usage, - Core.PubSub.Consumers.Posthog ] config :email, :consumers, [ diff --git a/www/package.json b/www/package.json index f0d7fc93c..0c1c40b40 100644 --- a/www/package.json +++ b/www/package.json @@ -72,7 +72,6 @@ "moment": "2.29.4", "phoenix": "1.7.3", "pluralsh-absinthe-socket-apollo-link": "0.2.0", - "posthog-js": "1.66.1", "process": "0.11.10", "prop-types": "15.8.1", "query-string": "8.1.0", diff --git a/www/src/App.tsx b/www/src/App.tsx index 77fe44d4c..d31a4075a 100644 --- a/www/src/App.tsx +++ b/www/src/App.tsx @@ -1,5 +1,5 @@ import 'react-toggle/style.css' -import { Suspense, lazy, useEffect } from 'react' +import { Suspense, lazy } from 'react' import { Route, Routes } from 'react-router-dom' import { ApolloProvider } from '@apollo/client' import { IntercomProvider } from 'react-use-intercom' @@ -19,14 +19,12 @@ import styled, { ThemeProvider as StyledThemeProvider } from 'styled-components' import { mergeDeep } from '@apollo/client/utilities' import mpRecipe from 'honorable-recipe-mp' import { GrowthBook, GrowthBookProvider } from '@growthbook/growthbook-react' -import posthog from 'posthog-js' import { client } from './helpers/client' import { INTERCOM_APP_ID } from './constants' import { DEFAULT_THEME } from './theme' import { HistoryRouter, browserHistory } from './router' import { growthbook } from './helpers/growthbook' -import Cookiebot from './utils/cookiebot' import { OverlayContextProvider } from './components/layout/Overlay' import NavContextProvider from './contexts/NavigationContext' import { CursorPositionProvider } from './components/utils/CursorPosition' @@ -79,28 +77,6 @@ const SSOCallback = lazy(() => })) ) -function PosthogOptInOut() { - useEffect(() => { - if (Cookiebot?.consent?.statistics) { - posthog.opt_in_capturing() - } else { - posthog.opt_out_capturing() - } - const onPrefChange = () => { - if (Cookiebot?.consent?.statistics) { - posthog.opt_in_capturing() - } else { - posthog.opt_out_capturing() - } - } - - window.addEventListener('CookiebotOnAccept', onPrefChange) - window.addEventListener('CookiebotOnDecline', onPrefChange) - }, []) - - return null -} - const RootBoxSC = styled.div(({ theme }) => ({ display: 'flex', flexdirection: 'column', @@ -191,7 +167,6 @@ function App() { return ( - diff --git a/www/src/components/Plural.tsx b/www/src/components/Plural.tsx index 94765d455..0857ee7c2 100644 --- a/www/src/components/Plural.tsx +++ b/www/src/components/Plural.tsx @@ -1,11 +1,9 @@ -import { Suspense, lazy, useContext, useEffect, useState } from 'react' +import { Suspense, lazy, useEffect, useState } from 'react' import { Navigate, Outlet, Route, Routes, useMatch } from 'react-router-dom' import { Toast } from '@pluralsh/design-system' import { growthbook } from '../helpers/growthbook' import { useHistory } from '../router' -import CurrentUserContext from '../contexts/CurrentUserContext' -import PosthogIdentify from '../utils/posthog' import { WrapStripe } from './WrapStripe' import { LegacyExpirationNotice } from './login/LegacyExpiration' @@ -296,23 +294,6 @@ function TestBanner() { return null } -function PosthogIdentifier() { - const me = useContext(CurrentUserContext) - - PosthogIdentify(me) - - useEffect(() => { - const onPrefChange = () => { - PosthogIdentify(me) - } - - window.addEventListener('CookiebotOnAccept', onPrefChange) - window.addEventListener('CookiebotOnDecline', onPrefChange) - }, [me]) - - return null -} - export function PluralInner() { return ( @@ -321,7 +302,6 @@ export function PluralInner() { - diff --git a/www/src/components/oidc/OAuthConsent.tsx b/www/src/components/oidc/OAuthConsent.tsx index 3ec7dc1d0..525e20254 100644 --- a/www/src/components/oidc/OAuthConsent.tsx +++ b/www/src/components/oidc/OAuthConsent.tsx @@ -2,7 +2,7 @@ import { useLocation, useNavigate } from 'react-router-dom' import { useMutation, useQuery } from '@apollo/client' import queryString from 'query-string' import { ArrowRightLeftIcon, Button, IconFrame } from '@pluralsh/design-system' -import { useCallback, useEffect } from 'react' +import { useCallback } from 'react' import { A, Flex, Span } from 'honorable' import StartCase from 'lodash/startCase' import { useTheme } from 'styled-components' @@ -13,8 +13,6 @@ import { PLURAL_MARK, PLURAL_MARK_WHITE } from '../constants' import { useMeQuery } from '../../generated/graphql' import { clearLocalStorage } from '../../helpers/localStorage' -import { PosthogEvent, posthogCapture } from '../../utils/posthog' - import LoadingIndicator from '../utils/LoadingIndicator' import { GET_OIDC_CONSENT, OAUTH_CONSENT } from './queries' @@ -61,16 +59,6 @@ export function OAuthConsent() { navigate('/login') }, [navigate]) - useEffect(() => { - if (repository) { - posthogCapture(PosthogEvent.OIDCLogin, { - applicationID: repository.id, - applicationName: repository.name, - installationID: repository.installation?.id, - }) - } - }, [repository]) - if (!data || userLoading) return if (!userData?.me?.email) { diff --git a/www/src/components/shell/onboarding/sections/shell/CreateShell.tsx b/www/src/components/shell/onboarding/sections/shell/CreateShell.tsx index ea4f01587..8dab0fb9e 100644 --- a/www/src/components/shell/onboarding/sections/shell/CreateShell.tsx +++ b/www/src/components/shell/onboarding/sections/shell/CreateShell.tsx @@ -36,7 +36,6 @@ import { WorkspaceProps, } from '../../context/types' import { toCloudProviderAttributes } from '../../../utils/provider' -import { PosthogEvent, posthogCapture } from '../../../../../utils/posthog' import { useSectionError, useSectionState } from '../../context/hooks' @@ -192,19 +191,6 @@ function CreateShell() { setSectionState(CreateCloudShellSectionState.Finished) }, [shell, setupShellCompleted, error, setSectionState]) - // Capture errors and send to posthog - useEffect( - () => - error && - posthogCapture(PosthogEvent.Onboarding, { - type: cloud.type, - provider: cloud.provider, - clusterName: workspace.clusterName, - error, - }), - [cloud.provider, cloud.type, error, workspace.clusterName] - ) - useEffect(() => setSectionError(!!error), [error, setSectionError]) return ( diff --git a/www/src/components/shell/onboarding/sections/workspace/CreateDemo.tsx b/www/src/components/shell/onboarding/sections/workspace/CreateDemo.tsx index 8823d1585..e2265fa17 100644 --- a/www/src/components/shell/onboarding/sections/workspace/CreateDemo.tsx +++ b/www/src/components/shell/onboarding/sections/workspace/CreateDemo.tsx @@ -26,15 +26,13 @@ import { } from '../../../../../generated/graphql' import { OnboardingContext } from '../../context/onboarding' import { generateString } from '../../../../../utils/string' -import { PosthogEvent, posthogCapture } from '../../../../../utils/posthog' import { DemoStatus } from './DemoStatus' function CreateDemo({ onBack, onNext }): JSX.Element { const setSectionState = useSectionState() const setSectionError = useSectionError() - const { cloud, workspace, setSCM, setCloud, setWorkspace } = - useContext(OnboardingContext) + const { setSCM, setCloud, setWorkspace } = useContext(OnboardingContext) const [demoCreated, setDemoCreated] = useState(false) const [shouldCreate, setShouldCreate] = useState(true) @@ -95,19 +93,6 @@ function CreateDemo({ onBack, onNext }): JSX.Element { setDemoCreated(true) }, [demoCreated, demoProject, isProjectReady, setCloud, setSCM, setWorkspace]) - // Capture errors and send to posthog - useEffect( - () => - error && - posthogCapture(PosthogEvent.Onboarding, { - type: cloud.type, - provider: cloud.provider, - clusterName: workspace.clusterName, - error, - }), - [cloud.provider, cloud.type, error, workspace.clusterName] - ) - useEffect(() => setSectionError(!!error), [error, setSectionError]) useEffect(() => { diff --git a/www/src/components/shell/terminal/sidebar/installer/Installer.tsx b/www/src/components/shell/terminal/sidebar/installer/Installer.tsx index f253578a3..1119dde5a 100644 --- a/www/src/components/shell/terminal/sidebar/installer/Installer.tsx +++ b/www/src/components/shell/terminal/sidebar/installer/Installer.tsx @@ -19,7 +19,6 @@ import { } from 'react' import { useSearchParams } from 'react-router-dom' -import { PosthogEvent, posthogCapture } from '../../../../../utils/posthog' import LoadingIndicator from '../../../../utils/LoadingIndicator' import { ImpersonationContext } from '../../../context/impersonation' import useOnboarded from '../../../hooks/useOnboarded' @@ -52,9 +51,6 @@ function Installer({ onInstallSuccess }) { const [steps, setSteps] = useState>([]) const [error, setError] = useState() const [defaultSteps, setDefaultSteps] = useState>([]) - const [selectedApplications, setSelectedApplications] = useState< - Array - >([]) const [domains, setDomains] = useState>({}) const { @@ -111,10 +107,6 @@ function Installer({ onInstallSuccess }) { mutation() refetch() refetchInstalledApps() - posthogCapture(PosthogEvent.Installer, { - provider, - applications: selectedApplications, - }) onInstallSuccess() }) .catch((err) => setError(err)) @@ -139,9 +131,6 @@ function Installer({ onInstallSuccess }) { setSteps(steps) } - setSelectedApplications( - selectedApplications.map((app) => app.label ?? 'unknown') - ) setStepsLoading(true) build().finally(() => setStepsLoading(false)) }, @@ -159,18 +148,6 @@ function Installer({ onInstallSuccess }) { [applications, preselectedApps, provider] ) - // Capture errors and send to posthog - useEffect( - () => - error && - posthogCapture(PosthogEvent.Installer, { - error, - applications: selectedApplications, - provider, - }), - [error, selectedApplications, provider] - ) - if (!applications || defaultSteps.length === 0) { return ( - provider?: Provider -} - -interface PosthogOIDCLoginEvent { - applicationName?: string - applicationID?: string - installationID?: string -} - -type PosthogEventData = { - [PosthogEvent.Onboarding]: PosthogOnboardingEvent - [PosthogEvent.Installer]: PosthogInstallerEvent - [PosthogEvent.OIDCLogin]: PosthogOIDCLoginEvent -} - -export function posthogCapture( - event: T, - data: PosthogEventData[T] -): void { - posthog.capture(event, data) -} diff --git a/www/yarn.lock b/www/yarn.lock index 4155d5915..421373f55 100644 --- a/www/yarn.lock +++ b/www/yarn.lock @@ -10165,13 +10165,6 @@ __metadata: languageName: node linkType: hard -"fflate@npm:^0.4.1": - version: 0.4.8 - resolution: "fflate@npm:0.4.8" - checksum: 29d8cbe44d5e7f53e7f5a160ac7f9cc025480c7b3bfd85c5f898cbe20dfa2dad4732daa534982664bf30b35896a90af44ea33ede5d94c5ffd1b8b0c0a0a56ca2 - languageName: node - linkType: hard - "fflate@npm:^0.8.1": version: 0.8.1 resolution: "fflate@npm:0.8.1" @@ -14379,15 +14372,6 @@ __metadata: languageName: node linkType: hard -"posthog-js@npm:1.66.1": - version: 1.66.1 - resolution: "posthog-js@npm:1.66.1" - dependencies: - fflate: ^0.4.1 - checksum: 55c2696bd26b0d73aef45d7a08cad82a1ce7b20f79dc65cff434b3fb45f8a5fe65a0d6ad265250ff27404ae236f91181230577fc8eb56f91e8a20912cf4737c0 - languageName: node - linkType: hard - "prelude-ls@npm:^1.2.1": version: 1.2.1 resolution: "prelude-ls@npm:1.2.1" @@ -19003,7 +18987,6 @@ __metadata: npm-run-all: 4.1.5 phoenix: 1.7.3 pluralsh-absinthe-socket-apollo-link: 0.2.0 - posthog-js: 1.66.1 prettier: 2.8.8 process: 0.11.10 prop-types: 15.8.1