Skip to content

Commit

Permalink
Split user properties from global props (#73)
Browse files Browse the repository at this point in the history
* Identify user by profileId instead of ext ID

* Prevent overriding critical fields in Posthog

* Use identifyUser to set global person properties

* Create custom person properties for user
  • Loading branch information
ppsreejith authored Nov 11, 2024
1 parent f68ac38 commit 89e2418
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
31 changes: 23 additions & 8 deletions web/src/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { initEventCapture, initEventListener } from '../tracking/init';
import { getExtensionID } from '../helpers/extensionId';
import { onSubscription } from '../helpers/documentSubscription';
import { getApp } from '../helpers/app';
import { getParsedIframeInfo } from '../helpers/origin';
import { getParsedIframeInfo, IframeInfoWeb } from '../helpers/origin';
import { captureEvent, GLOBAL_EVENTS, identifyUser, setGlobalProperties } from '../tracking';
import { useAppFromExternal } from './rpc';
import { Button } from '@chakra-ui/react';
Expand Down Expand Up @@ -92,7 +92,6 @@ const useMinusXMode = () => {
}

initEventCapture()
// identifyUser(getExtensionID())

const checkDiagnostics = async () => {
const tool = getParsedIframeInfo().tool
Expand Down Expand Up @@ -131,10 +130,17 @@ const useInitArgs = (cb: Function, args: any[]) => {

const persistor = persistStore(store);

interface GlobalData extends IframeInfoWeb {
IS_DEV: string
email?: string
profile_id?: string
}

function ProviderApp() {
const mode = useMinusXMode()
const tool = getParsedIframeInfo().tool
const toolVersion = getParsedIframeInfo().toolVersion
const extId = getParsedIframeInfo().r
const isGSheets = tool == 'google' && toolVersion == 'sheets'
const profileId = useSelector((state: RootState) => state.auth.profile_id)
const email = useSelector((state: RootState) => state.auth.email)
Expand All @@ -157,14 +163,23 @@ function ProviderApp() {
}
}, [session_jwt])
useInitArgs(() => {
const globalData = {
const globalData: GlobalData = {
IS_DEV: String(configs.IS_DEV),
email: email ?? '',
profile_id: profileId ?? '',
...getParsedIframeInfo()
...getParsedIframeInfo(),
email,
profile_id: profileId
}
setGlobalProperties({...globalData})
if (profileId) {
const personProperties = {
email,
profile_id: profileId,
[`tool_${tool}`]: true,
[`toolVersion_${toolVersion}`]: true,
r: extId,
}
identifyUser(profileId, personProperties)
}
identifyUser(getExtensionID(), globalData)
setGlobalProperties(globalData)
}, [profileId])
// Hack to fix planning stage
useInitArgs(() => {
Expand Down
2 changes: 1 addition & 1 deletion web/src/tracking/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ export const captureEvent = (type: string, payload?: object) => {

export const identifyUser = (unique_id: string, kv?: Record<string, string>) => {
identifyPosthogUser(unique_id, kv)
setPosthogPersonProperties({...kv})
}

export const setGlobalProperties = (kv: Record<string, string>) => {
setGlobalCustomEventProperties(kv)
setPosthogGlobalProperties(kv)
setPosthogPersonProperties(kv)
}

export const stopEventCapture = () => {
Expand Down

0 comments on commit 89e2418

Please sign in to comment.