Skip to content

Commit

Permalink
fix(api): created at identify using ISO date instead of epoch (#6683)
Browse files Browse the repository at this point in the history
  • Loading branch information
scopsy authored Oct 13, 2024
1 parent af41e92 commit 8be95d4
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions libs/application-generic/src/services/analytics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
};

Expand Down Expand Up @@ -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,
},
});
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 8be95d4

Please sign in to comment.