feat: Rewrite Front End cloud and posthog hooks using TypeScript (no-changelog) (#5491)
This commit is contained in:
@@ -7,10 +7,12 @@ import {
|
||||
WEBHOOK_NODE_TYPE,
|
||||
} from '@/constants';
|
||||
import { defineStore } from 'pinia';
|
||||
|
||||
import { useSettingsStore } from '@/stores/settings.store';
|
||||
import type { INodeTypeDescription, IRun, ITelemetryTrackProperties } from 'n8n-workflow';
|
||||
import { useWorkflowsStore } from '@/stores/workflows.store';
|
||||
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
|
||||
import { useUsersStore } from '@/stores/users.store';
|
||||
|
||||
const EVENTS = {
|
||||
ADDED_MANUAL_TRIGGER: 'User added manual trigger',
|
||||
@@ -27,6 +29,7 @@ export const useSegment = defineStore('segment', () => {
|
||||
const nodeTypesStore = useNodeTypesStore();
|
||||
const workflowsStore = useWorkflowsStore();
|
||||
const settingsStore = useSettingsStore();
|
||||
const usersStore = useUsersStore();
|
||||
|
||||
const track = (eventName: string, properties?: ITelemetryTrackProperties) => {
|
||||
if (settingsStore.telemetry.enabled) {
|
||||
@@ -34,6 +37,20 @@ export const useSegment = defineStore('segment', () => {
|
||||
}
|
||||
};
|
||||
|
||||
const page = (category: string, name: string, properties?: ITelemetryTrackProperties) => {
|
||||
if (settingsStore.telemetry.enabled) {
|
||||
window.analytics?.page(category, name, properties);
|
||||
}
|
||||
};
|
||||
|
||||
const identify = () => {
|
||||
const userId = usersStore.currentUserId;
|
||||
|
||||
if (settingsStore.telemetry.enabled && userId) {
|
||||
window.analytics?.identify(userId);
|
||||
}
|
||||
};
|
||||
|
||||
const trackAddedTrigger = (nodeTypeName: string) => {
|
||||
if (!nodeTypesStore.isTriggerNode(nodeTypeName)) {
|
||||
return;
|
||||
@@ -119,6 +136,8 @@ export const useSegment = defineStore('segment', () => {
|
||||
track,
|
||||
trackAddedTrigger,
|
||||
trackSuccessfulWorkflowExecution,
|
||||
identify,
|
||||
page,
|
||||
EVENTS,
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user