chore: maintain app distinct_id on factory reset (#4541)
This commit is contained in:
parent
144b836935
commit
350c9f7def
@ -1,4 +1,5 @@
|
||||
export type AppConfiguration = {
|
||||
data_folder: string
|
||||
quick_ask: boolean
|
||||
distinct_id?: string
|
||||
}
|
||||
|
||||
@ -26,6 +26,8 @@ import ImportModelOptionModal from '@/screens/Settings/ImportModelOptionModal'
|
||||
import ImportingModelModal from '@/screens/Settings/ImportingModelModal'
|
||||
import SelectingModelModal from '@/screens/Settings/SelectingModelModal'
|
||||
|
||||
import { getAppDistinctId, updateDistinctId } from '@/utils/settings'
|
||||
|
||||
import LoadingModal from '../LoadingModal'
|
||||
|
||||
import MainViewContainer from '../MainViewContainer'
|
||||
@ -93,8 +95,16 @@ const BaseLayout = () => {
|
||||
return properties
|
||||
},
|
||||
})
|
||||
posthog.opt_in_capturing()
|
||||
posthog.register({ app_version: VERSION })
|
||||
// Attempt to restore distinct Id from app global settings
|
||||
getAppDistinctId()
|
||||
.then((id) => {
|
||||
if (id) posthog.identify(id)
|
||||
})
|
||||
.finally(() => {
|
||||
posthog.opt_in_capturing()
|
||||
posthog.register({ app_version: VERSION })
|
||||
updateDistinctId(posthog.get_distinct_id())
|
||||
})
|
||||
} else {
|
||||
posthog.opt_out_capturing()
|
||||
}
|
||||
|
||||
@ -58,6 +58,7 @@ export default function useFactoryReset() {
|
||||
const configuration: AppConfiguration = {
|
||||
data_folder: defaultJanDataFolder,
|
||||
quick_ask: appConfiguration?.quick_ask ?? false,
|
||||
distinct_id: appConfiguration?.distinct_id,
|
||||
}
|
||||
await window.core?.api?.updateAppConfiguration(configuration)
|
||||
}
|
||||
|
||||
22
web/utils/settings.ts
Normal file
22
web/utils/settings.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { AppConfiguration } from '@janhq/core'
|
||||
|
||||
/**
|
||||
* Update app distinct Id
|
||||
* @param id
|
||||
*/
|
||||
export const updateDistinctId = async (id: string) => {
|
||||
const appConfiguration: AppConfiguration =
|
||||
await window.core?.api?.getAppConfigurations()
|
||||
appConfiguration.distinct_id = id
|
||||
await window.core?.api?.updateAppConfiguration(appConfiguration)
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve app distinct Id
|
||||
* @param id
|
||||
*/
|
||||
export const getAppDistinctId = async (): Promise<string | undefined> => {
|
||||
const appConfiguration: AppConfiguration =
|
||||
await window.core?.api?.getAppConfigurations()
|
||||
return appConfiguration.distinct_id
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user