feat(analytics): add clickhouse (#11174)
This commit is contained in:
@ -1,13 +1,12 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { OnDatabaseBatchEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-batch-event.decorator';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
import { AnalyticsService } from 'src/engine/core-modules/analytics/analytics.service';
|
||||
import { AnalyticsService } from 'src/engine/core-modules/analytics/services/analytics.service';
|
||||
import { ObjectRecordCreateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-create.event';
|
||||
import { TelemetryService } from 'src/engine/core-modules/telemetry/telemetry.service';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import { USER_SIGNUP_EVENT_NAME } from 'src/engine/api/graphql/workspace-query-runner/constants/user-signup-event-name.constants';
|
||||
import { OnCustomBatchEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-custom-batch-event.decorator';
|
||||
import { USER_SIGNUP_EVENT } from 'src/engine/core-modules/analytics/utils/events/track/user/user-signup';
|
||||
import { USER_SIGNUP_EVENT_NAME } from 'src/engine/api/graphql/workspace-query-runner/constants/user-signup-event-name.constants';
|
||||
|
||||
@Injectable()
|
||||
export class TelemetryListener {
|
||||
@ -16,36 +15,18 @@ export class TelemetryListener {
|
||||
private readonly telemetryService: TelemetryService,
|
||||
) {}
|
||||
|
||||
@OnDatabaseBatchEvent('*', DatabaseEventAction.CREATED)
|
||||
async handleAllCreate(payload: WorkspaceEventBatch<ObjectRecordCreateEvent>) {
|
||||
await Promise.all(
|
||||
payload.events.map((eventPayload) =>
|
||||
this.analyticsService.create(
|
||||
{
|
||||
action: payload.name,
|
||||
payload: {},
|
||||
},
|
||||
eventPayload.userId,
|
||||
payload.workspaceId,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@OnCustomBatchEvent(USER_SIGNUP_EVENT_NAME)
|
||||
async handleUserSignup(
|
||||
payload: WorkspaceEventBatch<ObjectRecordCreateEvent>,
|
||||
) {
|
||||
await Promise.all(
|
||||
payload.events.map(async (eventPayload) => {
|
||||
this.analyticsService.create(
|
||||
{
|
||||
action: USER_SIGNUP_EVENT_NAME,
|
||||
payload: {},
|
||||
},
|
||||
eventPayload.userId,
|
||||
payload.workspaceId,
|
||||
);
|
||||
this.analyticsService
|
||||
.createAnalyticsContext({
|
||||
userId: eventPayload.userId,
|
||||
workspaceId: payload.workspaceId,
|
||||
})
|
||||
.track(USER_SIGNUP_EVENT, {});
|
||||
|
||||
this.telemetryService.create(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user