feat: Remove PostHog event calls (#6915)

This commit is contained in:
Ricardo Espinoza
2023-08-17 11:39:32 -04:00
committed by GitHub
parent 41c3cc89ca
commit 270946a93b
13 changed files with 86 additions and 53 deletions

View File

@@ -4,7 +4,7 @@ import { defineStore } from 'pinia';
import { useUsersStore } from '@/stores/users.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useSettingsStore } from '@/stores/settings.store';
import type { FeatureFlags } from 'n8n-workflow';
import type { FeatureFlags, IDataObject } from 'n8n-workflow';
import { EXPERIMENTS_TO_TRACK, LOCAL_STORAGE_EXPERIMENT_OVERRIDES } from '@/constants';
import { useTelemetryStore } from './telemetry.store';
import { debounce } from 'lodash-es';
@@ -161,10 +161,29 @@ export const usePostHog = defineStore('posthog', () => {
trackedDemoExp.value[name] = variant;
};
const capture = (event: string, properties: IDataObject) => {
if (typeof window.posthog?.capture === 'function') {
window.posthog.capture(event, properties);
}
};
const setMetadata = (metadata: IDataObject, target: 'user' | 'events') => {
if (typeof window.posthog?.people?.set !== 'function') return;
if (typeof window.posthog?.register !== 'function') return;
if (target === 'user') {
window.posthog?.people?.set(metadata);
} else if (target === 'events') {
window.posthog?.register(metadata);
}
};
return {
init,
isVariantEnabled,
getVariant,
reset,
capture,
setMetadata,
};
});

View File

@@ -200,6 +200,7 @@ export const useUsersStore = defineStore(STORES.USERS, {
this.addUsers([user]);
this.currentUserId = user.id;
settingsStore.stopShowingSetupPage();
usePostHog().init(user.featureFlags);
}
},
async validateSignupToken(params: {
@@ -221,9 +222,8 @@ export const useUsersStore = defineStore(STORES.USERS, {
if (user) {
this.addUsers([user]);
this.currentUserId = user.id;
usePostHog().init(user.featureFlags);
}
usePostHog().init(user.featureFlags);
},
async sendForgotPasswordEmail(params: { email: string }): Promise<void> {
const rootStore = useRootStore();