Skip to content

Commit

Permalink
asdf
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcramer committed Feb 8, 2025
1 parent 2a38033 commit 8b9cc52
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
27 changes: 27 additions & 0 deletions src/core/analytics/hooks/useAnalytics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,31 @@ describe('useAnalytics', () => {
}),
);
});

it('should handle undefined apiKey and sessionId', () => {
(useOnchainKit as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
apiKey: undefined,
sessionId: undefined,
config: {
analytics: true,
},
});

const { result } = renderHook(() => useAnalytics());
const event = WalletEvent.ConnectSuccess;
const data = {
address: '0x0000000000000000000000000000000000000000',
} as AnalyticsEventData[typeof event];

result.current.sendAnalytics(event, data);

expect(sendAnalytics).toHaveBeenCalledWith(
expect.objectContaining({
body: expect.objectContaining({
apiKey: 'undefined',
sessionId: 'undefined',
}),
}),
);
});
});
4 changes: 2 additions & 2 deletions src/core/analytics/hooks/useAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useOnchainKit } from '@/useOnchainKit';
import { useEffect, useState } from 'react';

/**
* useAnalytics handles data preparation and business logic
* useAnalytics handles analytics events and data preparation
*/
export const useAnalytics = () => {
const { apiKey, sessionId, config } = useOnchainKit();
Expand Down Expand Up @@ -42,7 +42,7 @@ export const useAnalytics = () => {
event: AnalyticsEvent,
data: AnalyticsEventData[AnalyticsEvent],
) => {
// Don't send analytics if disabled in config
// Don't send analytics if disabled
if (!config?.analytics) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/analytics/utils/sendAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type AnalyticsRequestParams = {
};

/**
* sendAnalytics sends analytics data to the server and handles request logic.
* sendAnalytics sends telemetry data to the specified server endpoint.
*/
export const sendAnalytics = async (request: AnalyticsRequestParams) => {
try {
Expand Down

0 comments on commit 8b9cc52

Please sign in to comment.