-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #824 from CareTogether/posthog
PostHog.Identify(), unmask some UI components, and mask all events by default
- Loading branch information
Showing
13 changed files
with
125 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/caretogether-pwa/src/Authentication/AuthenticationWrapper.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/caretogether-pwa/src/Utilities/Instrumentation/postHogOptions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { PostHogConfig } from 'posthog-js'; | ||
|
||
export const postHogOptions: Partial<PostHogConfig> = { | ||
session_recording: { | ||
// `maskTextFn` only applies to selected elements, so make sure to set to "*" if you want this to work globally. | ||
maskTextSelector: '*', | ||
maskTextFn: (text, element) => { | ||
// To unmask text in a specific element, add the class `ph-unmask` to that element or the closest possible parent. | ||
// Sometimes adding the class to the element itself is difficult due to how the 3rd party component was implemented, | ||
// so you may need to add it to a parent. | ||
// Adding it to an element too high up in the DOM tree may unmask more text than you want and cause performance issues, | ||
// as the browser will have to work more to find an element with that class in the elements tree. | ||
if (element?.closest('.ph-unmask') !== null) { | ||
return text; | ||
} | ||
|
||
return '*'.repeat(text.length); | ||
}, | ||
}, | ||
mask_all_text: true, | ||
}; |
37 changes: 37 additions & 0 deletions
37
src/caretogether-pwa/src/Utilities/Instrumentation/usePostHogGroups.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useEffect } from 'react'; | ||
import { useLoadable } from '../../Hooks/useLoadable'; | ||
import posthog from 'posthog-js'; | ||
import { | ||
locationConfigurationQuery, | ||
organizationConfigurationQuery, | ||
} from '../../Model/ConfigurationModel'; | ||
import { useParams } from 'react-router-dom'; | ||
|
||
export const usePostHogGroups = () => { | ||
const { organizationId, locationId } = useParams<{ | ||
organizationId: string; | ||
locationId: string; | ||
}>(); | ||
|
||
const organizationConfiguration = useLoadable(organizationConfigurationQuery); | ||
const locationConfiguration = useLoadable(locationConfigurationQuery); | ||
|
||
useEffect(() => { | ||
if (organizationId) { | ||
posthog.group('organization', organizationId, { | ||
name: organizationConfiguration?.organizationName, | ||
}); | ||
} | ||
|
||
if (organizationId && locationId) { | ||
posthog.group('location', locationId, { | ||
name: locationConfiguration?.name, | ||
}); | ||
} | ||
}, [ | ||
organizationId, | ||
locationId, | ||
organizationConfiguration?.organizationName, | ||
locationConfiguration?.name, | ||
]); | ||
}; |
18 changes: 18 additions & 0 deletions
18
src/caretogether-pwa/src/Utilities/Instrumentation/usePostHogIdentify.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useEffect } from 'react'; | ||
import { accountInfoState } from '../../Authentication/Auth'; | ||
import { useLoadable } from '../../Hooks/useLoadable'; | ||
import posthog from 'posthog-js'; | ||
|
||
export const usePostHogIdentify = () => { | ||
const accountInfo = useLoadable(accountInfoState); | ||
|
||
// Passing the properties to the deps array avoids calling the effect twice. | ||
useEffect(() => { | ||
if (accountInfo?.userId) { | ||
posthog.identify(accountInfo.userId, { | ||
email: accountInfo.email, | ||
name: accountInfo.name, | ||
}); | ||
} | ||
}, [accountInfo?.userId, accountInfo?.email, accountInfo?.name]); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters