mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Added reusable isPosthogLoaded function (#19722)
no issue - We were checking if Posthog was loaded in a few separate places using the same logic — this PR consolidates that logic into a simple utility function so we can ensure consistency and change this logic more easily if we need to in the future
This commit is contained in:
parent
fbeecd58e6
commit
f49b5ab78d
1 changed files with 6 additions and 2 deletions
|
@ -1,5 +1,9 @@
|
|||
// Wrapper function for Plausible event
|
||||
|
||||
function isPosthogLoaded() {
|
||||
return window.posthog?.__loaded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hashes a user's email address so we can use it as a distinct_id in PostHog without storing the email address itself
|
||||
*
|
||||
|
@ -44,7 +48,7 @@ export function trackEvent(eventName, props = {}) {
|
|||
*/
|
||||
export async function identifyUser(user) {
|
||||
// Return early if window.posthog doesn't exist
|
||||
if (!window.posthog?.__loaded) {
|
||||
if (!isPosthogLoaded()) {
|
||||
return;
|
||||
}
|
||||
// User the user exists and has an email address, identify them in PostHog
|
||||
|
@ -79,7 +83,7 @@ export async function identifyUser(user) {
|
|||
* @returns {void}
|
||||
*/
|
||||
export function resetUser() {
|
||||
if (window.posthog?.__loaded) {
|
||||
if (isPosthogLoaded()) {
|
||||
window.posthog.reset();
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue