mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 12:57:29 -08:00
⚡ Add userId
to BE PH identify
call
This commit is contained in:
parent
c5ae9c4199
commit
895aaa45e5
|
@ -380,6 +380,7 @@ export interface IInternalHooksClass {
|
||||||
onServerStarted(
|
onServerStarted(
|
||||||
diagnosticInfo: IDiagnosticInfo,
|
diagnosticInfo: IDiagnosticInfo,
|
||||||
firstWorkflowCreatedAt?: Date,
|
firstWorkflowCreatedAt?: Date,
|
||||||
|
userId?: string,
|
||||||
): Promise<unknown[]>;
|
): Promise<unknown[]>;
|
||||||
onPersonalizationSurveySubmitted(userId: string, answers: Record<string, string>): Promise<void>;
|
onPersonalizationSurveySubmitted(userId: string, answers: Record<string, string>): Promise<void>;
|
||||||
onWorkflowCreated(userId: string, workflow: IWorkflowBase, publicApi: boolean): Promise<void>;
|
onWorkflowCreated(userId: string, workflow: IWorkflowBase, publicApi: boolean): Promise<void>;
|
||||||
|
|
|
@ -32,6 +32,7 @@ export class InternalHooksClass implements IInternalHooksClass {
|
||||||
async onServerStarted(
|
async onServerStarted(
|
||||||
diagnosticInfo: IDiagnosticInfo,
|
diagnosticInfo: IDiagnosticInfo,
|
||||||
earliestWorkflowCreatedAt?: Date,
|
earliestWorkflowCreatedAt?: Date,
|
||||||
|
userId?: string,
|
||||||
): Promise<unknown[]> {
|
): Promise<unknown[]> {
|
||||||
const info = {
|
const info = {
|
||||||
version_cli: diagnosticInfo.versionCli,
|
version_cli: diagnosticInfo.versionCli,
|
||||||
|
@ -45,9 +46,11 @@ export class InternalHooksClass implements IInternalHooksClass {
|
||||||
n8n_binary_data_mode: diagnosticInfo.binaryDataMode,
|
n8n_binary_data_mode: diagnosticInfo.binaryDataMode,
|
||||||
n8n_multi_user_allowed: diagnosticInfo.n8n_multi_user_allowed,
|
n8n_multi_user_allowed: diagnosticInfo.n8n_multi_user_allowed,
|
||||||
smtp_set_up: diagnosticInfo.smtp_set_up,
|
smtp_set_up: diagnosticInfo.smtp_set_up,
|
||||||
|
user_id: userId,
|
||||||
};
|
};
|
||||||
|
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
|
this.telemetry.identify(info),
|
||||||
this.telemetry.track('Instance started', {
|
this.telemetry.track('Instance started', {
|
||||||
...info,
|
...info,
|
||||||
earliest_workflow_created: earliestWorkflowCreatedAt,
|
earliest_workflow_created: earliestWorkflowCreatedAt,
|
||||||
|
|
|
@ -1986,14 +1986,21 @@ export async function start(): Promise<void> {
|
||||||
smtp_set_up: config.getEnv('userManagement.emails.mode') === 'smtp',
|
smtp_set_up: config.getEnv('userManagement.emails.mode') === 'smtp',
|
||||||
};
|
};
|
||||||
|
|
||||||
void Db.collections
|
const earliestWorkflow = await Db.collections.Workflow.findOne({
|
||||||
.Workflow!.findOne({
|
select: ['createdAt', 'id'],
|
||||||
select: ['createdAt'],
|
order: { createdAt: 'ASC' },
|
||||||
order: { createdAt: 'ASC' },
|
});
|
||||||
})
|
|
||||||
.then(async (workflow) =>
|
const sharing = await Db.collections.SharedWorkflow.findOne({
|
||||||
InternalHooksManager.getInstance().onServerStarted(diagnosticInfo, workflow?.createdAt),
|
where: { workflow: { id: earliestWorkflow?.id } },
|
||||||
);
|
relations: ['workflow'],
|
||||||
|
});
|
||||||
|
|
||||||
|
void InternalHooksManager.getInstance().onServerStarted(
|
||||||
|
diagnosticInfo,
|
||||||
|
earliestWorkflow?.createdAt,
|
||||||
|
sharing?.userId,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on('error', (error: Error & { code: string }) => {
|
server.on('error', (error: Error & { code: string }) => {
|
||||||
|
|
|
@ -138,6 +138,38 @@ export class Telemetry {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async identify(traits?: {
|
||||||
|
[key: string]: string | number | boolean | object | undefined | null;
|
||||||
|
}): Promise<void> {
|
||||||
|
return new Promise<void>((resolve) => {
|
||||||
|
if (this.postHog && traits?.user_id) {
|
||||||
|
this.postHog.identify({
|
||||||
|
distinctId: [this.instanceId, traits.user_id].join('#'),
|
||||||
|
properties: {
|
||||||
|
...traits,
|
||||||
|
instanceId: this.instanceId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.rudderStack) {
|
||||||
|
this.rudderStack.identify(
|
||||||
|
{
|
||||||
|
userId: this.instanceId,
|
||||||
|
anonymousId: '000000000000',
|
||||||
|
traits: {
|
||||||
|
...traits,
|
||||||
|
instanceId: this.instanceId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
resolve,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async track(
|
async track(
|
||||||
eventName: string,
|
eventName: string,
|
||||||
properties: ITelemetryTrackProperties = {},
|
properties: ITelemetryTrackProperties = {},
|
||||||
|
|
Loading…
Reference in a new issue