From 7e9fb08ed9b35ad43ab8113757a10e2c94830586 Mon Sep 17 00:00:00 2001 From: VolodymyrBg Date: Sun, 12 Jan 2025 10:53:35 +0200 Subject: [PATCH 1/6] Update logEvent.ts --- libs/base-ui/utils/logEvent.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/libs/base-ui/utils/logEvent.ts b/libs/base-ui/utils/logEvent.ts index 021502a96a4..bbcbd6be6d6 100644 --- a/libs/base-ui/utils/logEvent.ts +++ b/libs/base-ui/utils/logEvent.ts @@ -53,6 +53,25 @@ enum AnalyticsEventImportance { high = 'high', } +enum AnalyticsContext { + // Navigation/UI contexts + Navbar = 'navbar', + Build = 'build', + Explore = 'explore', + Community = 'community', + About = 'about', + Socials = 'socials', + + // Feature-specific contexts + BasenamesClaimFrame = 'basenames_claim_frame', + SliceSo = 'slice.so', + HypersubXyz = 'hypersub.xyz', + HighlightXyz = 'highlight.xyz', + EventsXyz = 'events.xyz', + PaycasterCo = 'paycaster.co', + SocialDex = 'social-dex', +} + type CCAEventData = { // Standard Attributes action?: ActionType; @@ -65,7 +84,7 @@ type CCAEventData = { message_id?: number; response_helpful?: boolean; address?: string; - context?: string; + context?: AnalyticsContext; userId?: string; error?: string; wallet_type?: string; @@ -124,5 +143,5 @@ export function identify(event: CCAEventData) { } } -export { ActionType, AnalyticsEventImportance, ComponentType }; +export { ActionType, AnalyticsEventImportance, ComponentType, AnalyticsContext }; export type { AnalyticsEventData, LogEvent, CCAEventData }; From 85fac235f16357c202ca11f028d22812d1e31feb Mon Sep 17 00:00:00 2001 From: VolodymyrBg Date: Sun, 12 Jan 2025 10:54:35 +0200 Subject: [PATCH 2/6] Update Analytics.tsx --- apps/web/contexts/Analytics.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/web/contexts/Analytics.tsx b/apps/web/contexts/Analytics.tsx index d3e2bec6791..663f7ae8b1c 100644 --- a/apps/web/contexts/Analytics.tsx +++ b/apps/web/contexts/Analytics.tsx @@ -4,6 +4,7 @@ import logEvent, { ActionType, AnalyticsEventImportance, CCAEventData, + AnalyticsContext, } from 'libs/base-ui/utils/logEvent'; import { ReactNode, createContext, useCallback, useContext, useMemo } from 'react'; @@ -12,7 +13,7 @@ export type AnalyticsContextProps = { fullContext: string; }; -export const AnalyticsContext = createContext({ +export const AnalyticsReactContext = createContext({ logEventWithContext: function () { return undefined; }, @@ -20,7 +21,7 @@ export const AnalyticsContext = createContext({ }); export function useAnalytics() { - const context = useContext(AnalyticsContext); + const context = useContext(AnalyticsReactContext); if (context === undefined) { throw new Error('useAnalytics must be used within a AnalyticsProvider'); } @@ -29,7 +30,7 @@ export function useAnalytics() { type AnalyticsProviderProps = { children?: ReactNode; - context: string; // TODO: This could be an enum in CCAEventData + context: AnalyticsContext; }; export default function AnalyticsProvider({ children, context }: AnalyticsProviderProps) { @@ -41,10 +42,10 @@ export default function AnalyticsProvider({ children, context }: AnalyticsProvid const sanitizedEventName = eventName.toLocaleLowerCase(); if (typeof window === 'undefined') return; logEvent( - sanitizedEventName, // TODO: Do we want context here? + sanitizedEventName, { action: action, - context: fullContext, + context: fullContext as AnalyticsContext, page_path: window.location.pathname, ...eventData, }, @@ -58,5 +59,5 @@ export default function AnalyticsProvider({ children, context }: AnalyticsProvid return { logEventWithContext, context, fullContext }; }, [context, fullContext, logEventWithContext]); - return {children}; + return {children}; } From 36f434d8345d55a5c076553f33faaafe312504f2 Mon Sep 17 00:00:00 2001 From: VolodymyrBg Date: Tue, 21 Jan 2025 16:18:16 +0200 Subject: [PATCH 3/6] Update Analytics.tsx --- apps/web/contexts/Analytics.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/web/contexts/Analytics.tsx b/apps/web/contexts/Analytics.tsx index 663f7ae8b1c..6fa8d0e291e 100644 --- a/apps/web/contexts/Analytics.tsx +++ b/apps/web/contexts/Analytics.tsx @@ -13,7 +13,7 @@ export type AnalyticsContextProps = { fullContext: string; }; -export const AnalyticsReactContext = createContext({ +export const AnalyticsContext = createContext({ logEventWithContext: function () { return undefined; }, @@ -21,7 +21,7 @@ export const AnalyticsReactContext = createContext({ }); export function useAnalytics() { - const context = useContext(AnalyticsReactContext); + const context = useContext(AnalyticsContext); if (context === undefined) { throw new Error('useAnalytics must be used within a AnalyticsProvider'); } @@ -59,5 +59,5 @@ export default function AnalyticsProvider({ children, context }: AnalyticsProvid return { logEventWithContext, context, fullContext }; }, [context, fullContext, logEventWithContext]); - return {children}; + return {children}; } From aa5060a6566dc8f023d9cffa8ced14822301d757 Mon Sep 17 00:00:00 2001 From: VolodymyrBg Date: Tue, 21 Jan 2025 16:20:57 +0200 Subject: [PATCH 4/6] Update Analytics.tsx --- apps/web/contexts/Analytics.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/contexts/Analytics.tsx b/apps/web/contexts/Analytics.tsx index 6fa8d0e291e..2e6febb10cf 100644 --- a/apps/web/contexts/Analytics.tsx +++ b/apps/web/contexts/Analytics.tsx @@ -45,7 +45,7 @@ export default function AnalyticsProvider({ children, context }: AnalyticsProvid sanitizedEventName, { action: action, - context: fullContext as AnalyticsContext, + context: fullContext, page_path: window.location.pathname, ...eventData, }, From 9819ef27587f6b64562639873382021ce632fac7 Mon Sep 17 00:00:00 2001 From: VolodymyrBg Date: Tue, 21 Jan 2025 16:21:53 +0200 Subject: [PATCH 5/6] Update logEvent.ts --- libs/base-ui/utils/logEvent.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/base-ui/utils/logEvent.ts b/libs/base-ui/utils/logEvent.ts index bbcbd6be6d6..88726147fd7 100644 --- a/libs/base-ui/utils/logEvent.ts +++ b/libs/base-ui/utils/logEvent.ts @@ -53,7 +53,7 @@ enum AnalyticsEventImportance { high = 'high', } -enum AnalyticsContext { +enum AnalyticsEventContext { // Navigation/UI contexts Navbar = 'navbar', Build = 'build', From 441cdc1242904f5b906c362f170c6ca00e95fcce Mon Sep 17 00:00:00 2001 From: VolodymyrBg Date: Tue, 21 Jan 2025 16:22:54 +0200 Subject: [PATCH 6/6] Update logEvent.ts --- libs/base-ui/utils/logEvent.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/base-ui/utils/logEvent.ts b/libs/base-ui/utils/logEvent.ts index 88726147fd7..155bcc9f71b 100644 --- a/libs/base-ui/utils/logEvent.ts +++ b/libs/base-ui/utils/logEvent.ts @@ -84,7 +84,7 @@ type CCAEventData = { message_id?: number; response_helpful?: boolean; address?: string; - context?: AnalyticsContext; + context?: AnalyticsEventContext; userId?: string; error?: string; wallet_type?: string; @@ -143,5 +143,5 @@ export function identify(event: CCAEventData) { } } -export { ActionType, AnalyticsEventImportance, ComponentType, AnalyticsContext }; +export { ActionType, AnalyticsEventImportance, ComponentType, AnalyticsEventContext }; export type { AnalyticsEventData, LogEvent, CCAEventData };