From f951d16b2b4c293cb0aeb06eaf033eabf486c9e4 Mon Sep 17 00:00:00 2001 From: Ryan Bennett Date: Wed, 7 Feb 2024 15:29:14 -0800 Subject: [PATCH 1/4] apply port adapter pattern to mixpanel analytics --- libs/adapters/src/index.ts | 1 + libs/adapters/src/mixpanel/index.ts | 30 ++++++++++++++ libs/core/src/ports/index.ts | 19 ++++++++- libs/core/src/ports/interfaces.ts | 9 ++++- libs/core/src/types.ts | 2 + packages/commonwealth/server.ts | 4 +- .../server_analytics_controller.ts | 8 +++- .../server_analytics_methods/track.ts | 8 ---- .../create_comment_reaction.ts | 2 +- .../update_community.ts | 2 +- .../server_groups_methods/create_group.ts | 2 +- .../server_groups_methods/update_group.ts | 2 +- .../server_polls_methods/update_poll_vote.ts | 2 +- .../server_threads_methods/create_thread.ts | 2 +- .../create_thread_comment.ts | 2 +- .../create_thread_poll.ts | 2 +- .../create_thread_reaction.ts | 2 +- .../server_threads_methods/update_thread.ts | 2 +- .../server_topics_methods/create_topic.ts | 2 +- .../server_topics_methods/update_topic.ts | 2 +- .../shared/analytics/server-track.ts | 39 ------------------- 21 files changed, 80 insertions(+), 64 deletions(-) create mode 100644 libs/adapters/src/mixpanel/index.ts delete mode 100644 packages/commonwealth/server/controllers/server_analytics_methods/track.ts delete mode 100644 packages/commonwealth/shared/analytics/server-track.ts diff --git a/libs/adapters/src/index.ts b/libs/adapters/src/index.ts index f136a150d7a..471f214ab3b 100644 --- a/libs/adapters/src/index.ts +++ b/libs/adapters/src/index.ts @@ -1,5 +1,6 @@ export * from './express'; export * from './hot-shots'; +export * from './mixpanel'; export * from './rabbitmq'; export * from './redis'; export * from './typescript-logging'; diff --git a/libs/adapters/src/mixpanel/index.ts b/libs/adapters/src/mixpanel/index.ts new file mode 100644 index 00000000000..02ce33b6cf9 --- /dev/null +++ b/libs/adapters/src/mixpanel/index.ts @@ -0,0 +1,30 @@ +import { Analytics, AnalyticsOptions } from '@hicommonwealth/core'; +import MixpanelLib from 'mixpanel'; + +export const MixpanelAnalytics = (): Analytics => { + let mixpanelNode; + + try { + if (process.env.NODE_ENV === 'production') { + mixpanelNode = MixpanelLib.init(process.env.MIXPANEL_PROD_TOKEN); + } else if (process.env.NODE_ENV === 'development') { + // NOTE: Only works if NODE_ENV defined in .env + // Make sure that is set to development if you want to use backend Mixpanel locally. + mixpanelNode = MixpanelLib.init(process.env.MIXPANEL_DEV_TOKEN); + } + } catch (e) { + console.error('Unable to initialized the backend mixpanel client: ', e); + } + + return { + name: 'mixpanel-analytics', + dispose: async () => {}, + track: (event: string, payload: AnalyticsOptions) => { + try { + mixpanelNode?.track(event, payload); + } catch (e) { + console.log(`Failed to track event, ${event.toString()}:`, e.message); + } + }, + }; +}; diff --git a/libs/core/src/ports/index.ts b/libs/core/src/ports/index.ts index f9338d6f1e2..50e2a01d008 100644 --- a/libs/core/src/ports/index.ts +++ b/libs/core/src/ports/index.ts @@ -1,4 +1,5 @@ -import { Cache, Logger, Stats } from './interfaces'; +import { AnalyticsOptions } from '../types'; +import { Analytics, Cache, Logger, Stats } from './interfaces'; import { port } from './port'; export * from './enums'; @@ -81,3 +82,19 @@ export const cache = port(function cache(cache?: Cache) { } ); }); + +/** + * Analytics port factory + */ + +export const analytics = port(function analytics(analytics?: Analytics) { + return ( + analytics || { + name: 'in-memory-analytics', + dispose: () => Promise.resolve(), + track: (event: string, payload: AnalyticsOptions) => { + console.log(`TRACK [${event}]: ${JSON.stringify(payload)}`); + }, + } + ); +}); diff --git a/libs/core/src/ports/interfaces.ts b/libs/core/src/ports/interfaces.ts index bc7af156080..d0f1d85642e 100644 --- a/libs/core/src/ports/interfaces.ts +++ b/libs/core/src/ports/interfaces.ts @@ -1,4 +1,4 @@ -import { CacheNamespaces } from '../types'; +import { AnalyticsOptions, CacheNamespaces } from '../types'; /** * Resource disposer function @@ -104,3 +104,10 @@ export interface Cache extends Disposable { ttlInSeconds: number, ): Promise; } + +/** + * Analytics port + */ +export interface Analytics extends Disposable { + track(event: string, payload: AnalyticsOptions): void; +} diff --git a/libs/core/src/types.ts b/libs/core/src/types.ts index 558c4bd865a..b41bf9d4195 100644 --- a/libs/core/src/types.ts +++ b/libs/core/src/types.ts @@ -239,3 +239,5 @@ export type ChainEventNotification = { created_at: Date; ChainEvent: ChainEventAttributes; }; + +export type AnalyticsOptions = Record; diff --git a/packages/commonwealth/server.ts b/packages/commonwealth/server.ts index 6d88189ca63..d57bc3364a5 100644 --- a/packages/commonwealth/server.ts +++ b/packages/commonwealth/server.ts @@ -1,15 +1,17 @@ import { HotShotsStats, + MixpanelAnalytics, ServiceKey, TypescriptLoggingLogger, startHealthCheckLoop, } from '@hicommonwealth/adapters'; -import { logger, stats } from '@hicommonwealth/core'; +import { analytics, logger, stats } from '@hicommonwealth/core'; import express from 'express'; // bootstrap production adapters const log = logger(TypescriptLoggingLogger()).getLogger(__filename); stats(HotShotsStats()); +analytics(MixpanelAnalytics()); let isServiceHealthy = false; startHealthCheckLoop({ diff --git a/packages/commonwealth/server/controllers/server_analytics_controller.ts b/packages/commonwealth/server/controllers/server_analytics_controller.ts index 19f486a9f0b..964a860fc3c 100644 --- a/packages/commonwealth/server/controllers/server_analytics_controller.ts +++ b/packages/commonwealth/server/controllers/server_analytics_controller.ts @@ -1,5 +1,8 @@ +import { analytics } from '@hicommonwealth/core'; +import { AnalyticsPayload } from 'shared/analytics/types'; import { SERVER_URL } from '../config'; -import { TrackOptions, __track } from './server_analytics_methods/track'; + +export type TrackOptions = Record & AnalyticsPayload; export class ServerAnalyticsController { /** @@ -17,7 +20,8 @@ export class ServerAnalyticsController { ...(host && { isCustomDomain: SERVER_URL.includes(host) }), }; } - return __track.call(this, newOptions); + const { event, ...payload } = newOptions; + analytics().track(event, payload); } } diff --git a/packages/commonwealth/server/controllers/server_analytics_methods/track.ts b/packages/commonwealth/server/controllers/server_analytics_methods/track.ts deleted file mode 100644 index 1a624c50fca..00000000000 --- a/packages/commonwealth/server/controllers/server_analytics_methods/track.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { serverAnalyticsTrack } from '../../../shared/analytics/server-track'; -import { AnalyticsPayload } from '../../../shared/analytics/types'; - -export type TrackOptions = Record & AnalyticsPayload; - -export async function __track(options: TrackOptions) { - return serverAnalyticsTrack(options); -} diff --git a/packages/commonwealth/server/controllers/server_comments_methods/create_comment_reaction.ts b/packages/commonwealth/server/controllers/server_comments_methods/create_comment_reaction.ts index 5be4d4fb5d7..b1706cbf88a 100644 --- a/packages/commonwealth/server/controllers/server_comments_methods/create_comment_reaction.ts +++ b/packages/commonwealth/server/controllers/server_comments_methods/create_comment_reaction.ts @@ -14,7 +14,7 @@ import { REACTION_WEIGHT_OVERRIDE } from 'server/config'; import { MixpanelCommunityInteractionEvent } from '../../../shared/analytics/types'; import { validateTopicGroupsMembership } from '../../util/requirementsModule/validateTopicGroupsMembership'; import { findAllRoles } from '../../util/roles'; -import { TrackOptions } from '../server_analytics_methods/track'; +import { TrackOptions } from '../server_analytics_controller'; import { ServerCommentsController } from '../server_comments_controller'; import { EmitOptions } from '../server_notifications_methods/emit'; diff --git a/packages/commonwealth/server/controllers/server_communities_methods/update_community.ts b/packages/commonwealth/server/controllers/server_communities_methods/update_community.ts index fc08ffee1f3..996927bdcd5 100644 --- a/packages/commonwealth/server/controllers/server_communities_methods/update_community.ts +++ b/packages/commonwealth/server/controllers/server_communities_methods/update_community.ts @@ -10,7 +10,7 @@ import { MixpanelCommunityInteractionEvent } from '../../../shared/analytics/typ import { urlHasValidHTTPPrefix } from '../../../shared/utils'; import { ALL_COMMUNITIES } from '../../middleware/databaseValidationService'; import { findOneRole } from '../../util/roles'; -import { TrackOptions } from '../server_analytics_methods/track'; +import { TrackOptions } from '../server_analytics_controller'; import { ServerCommunitiesController } from '../server_communities_controller'; export const Errors = { diff --git a/packages/commonwealth/server/controllers/server_groups_methods/create_group.ts b/packages/commonwealth/server/controllers/server_groups_methods/create_group.ts index 32d81227c26..95602098555 100644 --- a/packages/commonwealth/server/controllers/server_groups_methods/create_group.ts +++ b/packages/commonwealth/server/controllers/server_groups_methods/create_group.ts @@ -12,7 +12,7 @@ import { MixpanelCommunityInteractionEvent } from '../../../shared/analytics/typ import validateMetadata from '../../util/requirementsModule/validateMetadata'; import validateRequirements from '../../util/requirementsModule/validateRequirements'; import { validateOwner } from '../../util/validateOwner'; -import { TrackOptions } from '../server_analytics_methods/track'; +import { TrackOptions } from '../server_analytics_controller'; import { ServerGroupsController } from '../server_groups_controller'; const MAX_GROUPS_PER_COMMUNITY = 20; diff --git a/packages/commonwealth/server/controllers/server_groups_methods/update_group.ts b/packages/commonwealth/server/controllers/server_groups_methods/update_group.ts index 5fde43c4fee..633169bbfbc 100644 --- a/packages/commonwealth/server/controllers/server_groups_methods/update_group.ts +++ b/packages/commonwealth/server/controllers/server_groups_methods/update_group.ts @@ -12,7 +12,7 @@ import { MixpanelCommunityInteractionEvent } from '../../../shared/analytics/typ import validateMetadata from '../../util/requirementsModule/validateMetadata'; import validateRequirements from '../../util/requirementsModule/validateRequirements'; import { validateOwner } from '../../util/validateOwner'; -import { TrackOptions } from '../server_analytics_methods/track'; +import { TrackOptions } from '../server_analytics_controller'; import { ServerGroupsController } from '../server_groups_controller'; const Errors = { diff --git a/packages/commonwealth/server/controllers/server_polls_methods/update_poll_vote.ts b/packages/commonwealth/server/controllers/server_polls_methods/update_poll_vote.ts index 958ec9c6e10..5d335331a27 100644 --- a/packages/commonwealth/server/controllers/server_polls_methods/update_poll_vote.ts +++ b/packages/commonwealth/server/controllers/server_polls_methods/update_poll_vote.ts @@ -8,7 +8,7 @@ import { } from '@hicommonwealth/model'; import { MixpanelCommunityInteractionEvent } from '../../../shared/analytics/types'; import { validateTopicGroupsMembership } from '../../util/requirementsModule/validateTopicGroupsMembership'; -import { TrackOptions } from '../server_analytics_methods/track'; +import { TrackOptions } from '../server_analytics_controller'; import { ServerPollsController } from '../server_polls_controller'; export const Errors = { diff --git a/packages/commonwealth/server/controllers/server_threads_methods/create_thread.ts b/packages/commonwealth/server/controllers/server_threads_methods/create_thread.ts index 57fea118cc7..c7170ccd2be 100644 --- a/packages/commonwealth/server/controllers/server_threads_methods/create_thread.ts +++ b/packages/commonwealth/server/controllers/server_threads_methods/create_thread.ts @@ -17,7 +17,7 @@ import { renderQuillDeltaToText } from '../../../shared/utils'; import { parseUserMentions } from '../../util/parseUserMentions'; import { validateTopicGroupsMembership } from '../../util/requirementsModule/validateTopicGroupsMembership'; import { validateOwner } from '../../util/validateOwner'; -import { TrackOptions } from '../server_analytics_methods/track'; +import { TrackOptions } from '../server_analytics_controller'; import { EmitOptions } from '../server_notifications_methods/emit'; import { ServerThreadsController } from '../server_threads_controller'; diff --git a/packages/commonwealth/server/controllers/server_threads_methods/create_thread_comment.ts b/packages/commonwealth/server/controllers/server_threads_methods/create_thread_comment.ts index 8ecebdb541a..f6f0b9292d9 100644 --- a/packages/commonwealth/server/controllers/server_threads_methods/create_thread_comment.ts +++ b/packages/commonwealth/server/controllers/server_threads_methods/create_thread_comment.ts @@ -18,7 +18,7 @@ import { getCommentDepth } from '../../util/getCommentDepth'; import { parseUserMentions } from '../../util/parseUserMentions'; import { validateTopicGroupsMembership } from '../../util/requirementsModule/validateTopicGroupsMembership'; import { validateOwner } from '../../util/validateOwner'; -import { TrackOptions } from '../server_analytics_methods/track'; +import { TrackOptions } from '../server_analytics_controller'; import { EmitOptions } from '../server_notifications_methods/emit'; import { ServerThreadsController } from '../server_threads_controller'; diff --git a/packages/commonwealth/server/controllers/server_threads_methods/create_thread_poll.ts b/packages/commonwealth/server/controllers/server_threads_methods/create_thread_poll.ts index e7375cb7bee..ee9514896cc 100644 --- a/packages/commonwealth/server/controllers/server_threads_methods/create_thread_poll.ts +++ b/packages/commonwealth/server/controllers/server_threads_methods/create_thread_poll.ts @@ -3,7 +3,7 @@ import { PollAttributes, UserInstance } from '@hicommonwealth/model'; import moment from 'moment'; import { MixpanelCommunityInteractionEvent } from '../../../shared/analytics/types'; import { validateOwner } from '../../util/validateOwner'; -import { TrackOptions } from '../server_analytics_methods/track'; +import { TrackOptions } from '../server_analytics_controller'; import { ServerThreadsController } from '../server_threads_controller'; export const Errors = { diff --git a/packages/commonwealth/server/controllers/server_threads_methods/create_thread_reaction.ts b/packages/commonwealth/server/controllers/server_threads_methods/create_thread_reaction.ts index ba627f7dc28..046f99e925c 100644 --- a/packages/commonwealth/server/controllers/server_threads_methods/create_thread_reaction.ts +++ b/packages/commonwealth/server/controllers/server_threads_methods/create_thread_reaction.ts @@ -13,7 +13,7 @@ import { REACTION_WEIGHT_OVERRIDE } from 'server/config'; import { MixpanelCommunityInteractionEvent } from '../../../shared/analytics/types'; import { validateTopicGroupsMembership } from '../../util/requirementsModule/validateTopicGroupsMembership'; import { validateOwner } from '../../util/validateOwner'; -import { TrackOptions } from '../server_analytics_methods/track'; +import { TrackOptions } from '../server_analytics_controller'; import { EmitOptions } from '../server_notifications_methods/emit'; import { ServerThreadsController } from '../server_threads_controller'; diff --git a/packages/commonwealth/server/controllers/server_threads_methods/update_thread.ts b/packages/commonwealth/server/controllers/server_threads_methods/update_thread.ts index 96a8548e3f3..76bedf15017 100644 --- a/packages/commonwealth/server/controllers/server_threads_methods/update_thread.ts +++ b/packages/commonwealth/server/controllers/server_threads_methods/update_thread.ts @@ -19,7 +19,7 @@ import { MixpanelCommunityInteractionEvent } from '../../../shared/analytics/typ import { renderQuillDeltaToText, validURL } from '../../../shared/utils'; import { parseUserMentions } from '../../util/parseUserMentions'; import { findAllRoles } from '../../util/roles'; -import { TrackOptions } from '../server_analytics_methods/track'; +import { TrackOptions } from '../server_analytics_controller'; import { EmitOptions } from '../server_notifications_methods/emit'; import { ServerThreadsController } from '../server_threads_controller'; diff --git a/packages/commonwealth/server/controllers/server_topics_methods/create_topic.ts b/packages/commonwealth/server/controllers/server_topics_methods/create_topic.ts index bdd2bb0e7af..c1718a158b0 100644 --- a/packages/commonwealth/server/controllers/server_topics_methods/create_topic.ts +++ b/packages/commonwealth/server/controllers/server_topics_methods/create_topic.ts @@ -7,7 +7,7 @@ import { import { sanitizeQuillText } from 'server/util/sanitizeQuillText'; import { MixpanelCommunityInteractionEvent } from '../../../shared/analytics/types'; import { validateOwner } from '../../util/validateOwner'; -import { TrackOptions } from '../server_analytics_methods/track'; +import { TrackOptions } from '../server_analytics_controller'; import { ServerTopicsController } from '../server_topics_controller'; export const Errors = { diff --git a/packages/commonwealth/server/controllers/server_topics_methods/update_topic.ts b/packages/commonwealth/server/controllers/server_topics_methods/update_topic.ts index 5d294c02ca0..fd105453883 100644 --- a/packages/commonwealth/server/controllers/server_topics_methods/update_topic.ts +++ b/packages/commonwealth/server/controllers/server_topics_methods/update_topic.ts @@ -3,7 +3,7 @@ import { TopicAttributes, UserInstance } from '@hicommonwealth/model'; import { sanitizeQuillText } from 'server/util/sanitizeQuillText'; import { MixpanelCommunityInteractionEvent } from '../../../shared/analytics/types'; import { validateOwner } from '../../util/validateOwner'; -import { TrackOptions } from '../server_analytics_methods/track'; +import { TrackOptions } from '../server_analytics_controller'; import { ServerTopicsController } from '../server_topics_controller'; export const Errors = { diff --git a/packages/commonwealth/shared/analytics/server-track.ts b/packages/commonwealth/shared/analytics/server-track.ts deleted file mode 100644 index 66e686404c9..00000000000 --- a/packages/commonwealth/shared/analytics/server-track.ts +++ /dev/null @@ -1,39 +0,0 @@ -import Mixpanel from 'mixpanel'; -import { AnalyticsPayload, BaseMixpanelPayload, providers } from './types'; - -let mixpanelNode; - -try { - if (process.env.NODE_ENV === 'production') { - mixpanelNode = Mixpanel.init(process.env.MIXPANEL_PROD_TOKEN); - } else if (process.env.NODE_ENV === 'development') { - // NOTE: Only works if NODE_ENV defined in .env - // Make sure that is set to development if you want to use backend Mixpanel locally. - mixpanelNode = Mixpanel.init(process.env.MIXPANEL_DEV_TOKEN); - } -} catch (e) { - console.log('Unable to initialized the backend mixpanel client: ', e); -} - -// ----- Server Side Mixpanel Library Utils ------ // -export function mixpanelTrack(data: T) { - const { event, ...payload } = data; - try { - mixpanelNode?.track(event, payload); - } catch (e) { - console.log(`Failed to track event, ${event.toString()}:`, e.message); - } -} - -export function serverAnalyticsTrack(payload: T) { - providers.forEach((provider) => { - switch (provider) { - case 'mixpanel': - mixpanelTrack(payload as BaseMixpanelPayload); - break; - // Add more providers here - default: - throw new Error(`Unsupported provider: ${provider}`); - } - }); -} From 3f3754974082f75b630e1038e10459b292fe1b7b Mon Sep 17 00:00:00 2001 From: Ryan Bennett Date: Thu, 8 Feb 2024 12:42:21 -0800 Subject: [PATCH 2/4] update import --- libs/adapters/package.json | 1 + packages/commonwealth/package.json | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/adapters/package.json b/libs/adapters/package.json index f766913c25b..7cd2567fce3 100644 --- a/libs/adapters/package.json +++ b/libs/adapters/package.json @@ -18,6 +18,7 @@ "async-rwlock": "^1.1.1", "express": "^4.18.2", "hot-shots": "^9", + "mixpanel": "^0.14.0", "pg": "^8.11.3", "node-fetch": "2", "rascal": "^14.4.5", diff --git a/packages/commonwealth/package.json b/packages/commonwealth/package.json index 84eee36dd44..cd5ec0e146e 100644 --- a/packages/commonwealth/package.json +++ b/packages/commonwealth/package.json @@ -150,7 +150,6 @@ "marked-footnote": "^1.2.2", "marked-smartypants": "1.1.5", "marked-xhtml": "1.0.8", - "mixpanel": "^0.14.0", "mixpanel-browser": "^2.45.0", "moment": "^2.23.0", "morgan": "^1.9.1", From 440c3989b64a79149e24d814e411338397f93167 Mon Sep 17 00:00:00 2001 From: Ryan Bennett Date: Tue, 13 Feb 2024 14:04:19 -0800 Subject: [PATCH 3/4] fix logging --- libs/adapters/src/mixpanel/index.ts | 8 +++++--- libs/core/src/ports/index.ts | 5 +---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/libs/adapters/src/mixpanel/index.ts b/libs/adapters/src/mixpanel/index.ts index 02ce33b6cf9..b4bda0805b9 100644 --- a/libs/adapters/src/mixpanel/index.ts +++ b/libs/adapters/src/mixpanel/index.ts @@ -1,6 +1,8 @@ -import { Analytics, AnalyticsOptions } from '@hicommonwealth/core'; +import { Analytics, AnalyticsOptions, logger } from '@hicommonwealth/core'; import MixpanelLib from 'mixpanel'; +const log = logger().getLogger(__filename); + export const MixpanelAnalytics = (): Analytics => { let mixpanelNode; @@ -13,7 +15,7 @@ export const MixpanelAnalytics = (): Analytics => { mixpanelNode = MixpanelLib.init(process.env.MIXPANEL_DEV_TOKEN); } } catch (e) { - console.error('Unable to initialized the backend mixpanel client: ', e); + log.error('Unable to initialized the backend mixpanel client: ', e); } return { @@ -23,7 +25,7 @@ export const MixpanelAnalytics = (): Analytics => { try { mixpanelNode?.track(event, payload); } catch (e) { - console.log(`Failed to track event, ${event.toString()}:`, e.message); + log.error(`Failed to track event, ${event.toString()}:`, e.message); } }, }; diff --git a/libs/core/src/ports/index.ts b/libs/core/src/ports/index.ts index 50e2a01d008..504087b1a48 100644 --- a/libs/core/src/ports/index.ts +++ b/libs/core/src/ports/index.ts @@ -1,4 +1,3 @@ -import { AnalyticsOptions } from '../types'; import { Analytics, Cache, Logger, Stats } from './interfaces'; import { port } from './port'; @@ -92,9 +91,7 @@ export const analytics = port(function analytics(analytics?: Analytics) { analytics || { name: 'in-memory-analytics', dispose: () => Promise.resolve(), - track: (event: string, payload: AnalyticsOptions) => { - console.log(`TRACK [${event}]: ${JSON.stringify(payload)}`); - }, + track: () => {}, } ); }); From b2dc87e7a69e27236bfc9f22d5b46e07b93ae196 Mon Sep 17 00:00:00 2001 From: Ryan Bennett Date: Tue, 13 Feb 2024 14:24:42 -0800 Subject: [PATCH 4/4] move log --- libs/adapters/src/mixpanel/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/adapters/src/mixpanel/index.ts b/libs/adapters/src/mixpanel/index.ts index b4bda0805b9..9dfbce1ebfc 100644 --- a/libs/adapters/src/mixpanel/index.ts +++ b/libs/adapters/src/mixpanel/index.ts @@ -1,9 +1,9 @@ import { Analytics, AnalyticsOptions, logger } from '@hicommonwealth/core'; import MixpanelLib from 'mixpanel'; -const log = logger().getLogger(__filename); - export const MixpanelAnalytics = (): Analytics => { + const log = logger().getLogger(__filename); + let mixpanelNode; try {