mirror of
https://github.com/standardnotes/server
synced 2026-07-14 00:01:54 -04:00
29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
import { SessionRefreshedEvent, DomainEventHandlerInterface } from '@standardnotes/domain-events'
|
|
import { inject, injectable, optional } from 'inversify'
|
|
import { Mixpanel } from 'mixpanel'
|
|
|
|
import TYPES from '../../Bootstrap/Types'
|
|
import { GetUserAnalyticsId } from '../UseCase/GetUserAnalyticsId/GetUserAnalyticsId'
|
|
|
|
@injectable()
|
|
export class SessionRefreshedEventHandler implements DomainEventHandlerInterface {
|
|
constructor(
|
|
@inject(TYPES.GetUserAnalyticsId) private getUserAnalyticsId: GetUserAnalyticsId,
|
|
@inject(TYPES.MixpanelClient) @optional() private mixpanelClient: Mixpanel | null,
|
|
) {}
|
|
|
|
async handle(event: SessionRefreshedEvent): Promise<void> {
|
|
const { analyticsId } = await this.getUserAnalyticsId.execute({ userUuid: event.payload.userUuid })
|
|
|
|
if (this.mixpanelClient !== null) {
|
|
this.mixpanelClient.track(event.type, {
|
|
distinct_id: analyticsId.toString(),
|
|
})
|
|
|
|
this.mixpanelClient.track('GENERAL_ACTIVITY', {
|
|
distinct_id: analyticsId.toString(),
|
|
})
|
|
}
|
|
}
|
|
}
|