From 8be95d40421192bf5721a06aded2afb66f9ba2ad Mon Sep 17 00:00:00 2001 From: Dima Grossman Date: Sun, 13 Oct 2024 17:35:07 +0300 Subject: [PATCH] fix(api): created at identify using ISO date instead of epoch (#6683) --- .../src/services/analytics.service.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/libs/application-generic/src/services/analytics.service.ts b/libs/application-generic/src/services/analytics.service.ts index f154a7f2694..1b42926b958 100644 --- a/libs/application-generic/src/services/analytics.service.ts +++ b/libs/application-generic/src/services/analytics.service.ts @@ -49,7 +49,7 @@ export class AnalyticsService { _organization: organizationId, id: organizationId, name: organization.name, - createdAt: organization.createdAt, + createdAt: this.convertToIsoDate(organization.createdAt), domain: organization.domain || user.email?.split('@')[1], }; @@ -99,9 +99,9 @@ export class AnalyticsService { name: `${user.firstName || ''} ${user.lastName || ''}`.trim(), email: user.email, avatar: user.profilePicture, - createdAt: user.createdAt, + createdAt: this.convertToIsoDate(user.createdAt), // For segment auto mapping - created: user.createdAt, + created: this.convertToIsoDate(user.createdAt), githubProfile: githubToken?.username, }, }); @@ -179,4 +179,15 @@ export class AnalyticsService { private get mixpanelEnabled() { return process.env.NODE_ENV !== 'test' && this.mixpanel; } + + private convertToIsoDate(createdAt: string | number | null): string { + const createdAtNumber = Number(createdAt); + const isEpochValidNumber = !Number.isNaN(createdAtNumber); + + if (isEpochValidNumber) { + return new Date(createdAtNumber).toISOString(); + } + + return String(createdAt); + } }