The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix: use shared useGoogleAnalyticsProps
phamhieuf26d4a823282
diff --git a/studio/components/interfaces/SQLEditor/SQLTemplates/SQLTemplates.tsx b/studio/components/interfaces/SQLEditor/SQLTemplates/SQLTemplates.tsxindex 43548b7ec7d..d1ea1631330 100644--- a/studio/components/interfaces/SQLEditor/SQLTemplates/SQLTemplates.tsx+++ b/studio/components/interfaces/SQLEditor/SQLTemplates/SQLTemplates.tsx@@ -8,7 +8,7 @@ import { useProfileQuery } from 'data/profile/profile-query'import { SQL_TEMPLATES } from 'components/interfaces/SQLEditor/SQLEditor.constants'import SQLCard from './SQLCard'import { createSqlSnippetSkeleton } from '../SQLEditor.utils'-import { useParams } from 'common'+import { useGoogleAnalyticsProps, useParams } from 'common'import { useRouter } from 'next/router'import { SqlSnippet } from 'data/content/sql-snippets-query'import { useSqlEditorStateSnapshot } from 'state/sql-editor'@@ -21,6 +21,7 @@ const SQLTemplates = observer(() => {const { data: profile } = useProfileQuery()const [sql, quickStart] = partition(SQL_TEMPLATES, { type: 'template' })+ const googleAnalyticsProps = useGoogleAnalyticsProps()const snap = useSqlEditorStateSnapshot()const canCreateSQLSnippet = checkPermissions(PermissionAction.CREATE, 'user_content', {resource: { type: 'sql', owner_id: profile?.id },@@ -77,7 +78,7 @@ const SQLTemplates = observer(() => {action: 'script_clicked',label: x.title,},- ui.googleAnalyticsProps+ googleAnalyticsProps)}}/>@@ -111,7 +112,7 @@ const SQLTemplates = observer(() => {action: 'quickstart_clicked',label: x.title,},- ui.googleAnalyticsProps+ googleAnalyticsProps)}}/>diff --git a/studio/components/interfaces/SQLEditor/UtilityPanel/ResultsDropdown.tsx b/studio/components/interfaces/SQLEditor/UtilityPanel/ResultsDropdown.tsxindex 2ba8e6a3324..0f9ac2fe627 100644--- a/studio/components/interfaces/SQLEditor/UtilityPanel/ResultsDropdown.tsx+++ b/studio/components/interfaces/SQLEditor/UtilityPanel/ResultsDropdown.tsx@@ -9,6 +9,7 @@ import { CSVLink } from 'react-csv'import { useSqlEditorStateSnapshot } from 'state/sql-editor'// @ts-ignoreimport MarkdownTable from 'markdown-table'+import { useGoogleAnalyticsProps } from 'common'export type ResultsDropdownProps = {id: string@@ -17,6 +18,7 @@ export type ResultsDropdownProps = {const ResultsDropdown = ({ id }: ResultsDropdownProps) => {const { project } = useProjectContext()const snap = useSqlEditorStateSnapshot()+ const googleAnalyticsProps = useGoogleAnalyticsProps()const result = snap.results?.[id]?.[0] ?? undefinedconst { ui } = useStore()const csvRef = useRef<CSVLink & HTMLAnchorElement & { link: HTMLAnchorElement }>(null)@@ -30,7 +32,7 @@ const ResultsDropdown = ({ id }: ResultsDropdownProps) => {csvRef.current?.link.click()Telemetry.sendEvent({ category: 'sql_editor', action: 'sql_download_csv', label: '' },- ui.googleAnalyticsProps+ googleAnalyticsProps)}@@ -53,7 +55,7 @@ const ResultsDropdown = ({ id }: ResultsDropdownProps) => {ui.setNotification({ category: 'success', message: 'Copied results to clipboard' })Telemetry.sendEvent({ category: 'sql_editor', action: 'sql_copy_as_markdown', label: '' },- ui.googleAnalyticsProps+ googleAnalyticsProps)})}diff --git a/studio/components/ui/PageTelemetry.tsx b/studio/components/ui/PageTelemetry.tsxindex 412336e28d0..b6f2591b0b4 100644--- a/studio/components/ui/PageTelemetry.tsx+++ b/studio/components/ui/PageTelemetry.tsx@@ -1,4 +1,4 @@-import { useStore } from 'hooks'+import { useGoogleAnalyticsProps } from 'common'import { post } from 'lib/common/fetch'import { API_URL, IS_PLATFORM } from 'lib/constants'import { observer } from 'mobx-react-lite'@@ -25,7 +25,7 @@ function sanitizePageViewRoute(_route?: string) {const PageTelemetry: FC = ({ children }) => {const router = useRouter()- const { ui } = useStore()+ const googleAnalyticsProps = useGoogleAnalyticsProps()useEffect(() => {function handleRouteChange(url: string) {@@ -71,8 +71,8 @@ const PageTelemetry: FC = ({ children }) => {title: document.title,route,ga: {- screen_resolution: ui.googleAnalyticsProps?.screenResolution,- language: ui.googleAnalyticsProps?.language,+ screen_resolution: googleAnalyticsProps?.screenResolution,+ language: googleAnalyticsProps?.language,},})}diff --git a/studio/lib/auth.tsx b/studio/lib/auth.tsxindex c7b962a2010..f02f3688130 100644--- a/studio/lib/auth.tsx+++ b/studio/lib/auth.tsx@@ -1,18 +1,20 @@import {AuthContext as AuthContextInternal,AuthProvider as AuthProviderInternal,- AuthProviderProps,gotrueClient,+ useGoogleAnalyticsProps,} from 'common'import { useProfileQuery } from 'data/profile/profile-query'import { useStore } from 'hooks'import { PropsWithChildren, useEffect } from 'react'import { GOTRUE_ERRORS, IS_PLATFORM } from './constants'+import Telemetry from 'lib/telemetry'export const AuthContext = AuthContextInternalexport const AuthProvider = ({ children }: PropsWithChildren<{}>) => {const { ui, app } = useStore()+ const googleAnalyticsProps = useGoogleAnalyticsProps()// Check for unverified GitHub users after a GitHub sign inuseEffect(() => {@@ -34,7 +36,7 @@ export const AuthProvider = ({ children }: PropsWithChildren<{}>) => {// Track telemetry for the current useruseProfileQuery({onSuccess(profile) {- ui.setProfile(profile)+ Telemetry.sendIdentify(profile, googleAnalyticsProps)// [Joshen] Temp fix: For new users, the GET profile call also creates a default org// But because the dashboard's logged in state is using gotrue as the source of truthdiff --git a/studio/stores/UiStore.ts b/studio/stores/UiStore.tsindex 1b91898ae31..0e7b35339f9 100644--- a/studio/stores/UiStore.ts+++ b/studio/stores/UiStore.ts@@ -1,8 +1,7 @@import { uuidv4 } from 'lib/helpers'import { action, makeAutoObservable } from 'mobx'-import { Project, Notification, User, Organization, ProjectBase, Permission } from 'types'+import { Project, Notification, Organization, ProjectBase, Permission } from 'types'import { IRootStore } from './RootStore'-import Telemetry, { GoogleAnalyticsProps } from 'lib/telemetry'export interface IUiStore {language: 'en-US'@@ -12,12 +11,10 @@ export interface IUiStore {selectedOrganization?: Organizationnotification?: Notificationpermissions?: Permission[]- googleAnalyticsProps?: GoogleAnalyticsPropsload: () => voidsetProjectRef: (ref?: string) => voidsetOrganizationSlug: (slug?: string) => voidsetNotification: (notification: Notification) => string- setProfile: (value: User) => voidsetPermissions: (permissions?: Permission[]) => void}export default class UiStore implements IUiStore {@@ -83,14 +80,6 @@ export default class UiStore implements IUiStore {return undefined}- get googleAnalyticsProps() {- return {- screenResolution:- typeof window !== 'undefined' ? `${window.innerWidth}x${window.innerHeight}` : undefined,- language: this.language,- }- }-load() {if (typeof window === 'undefined') return}@@ -109,10 +98,6 @@ export default class UiStore implements IUiStore {return id}- setProfile(value: User) {- Telemetry.sendIdentify(value, this.googleAnalyticsProps)- }-setPermissions(permissions?: any) {this.permissions = permissions}