From ddb8ae59e607ccdd39a30c66bc3949f37ecd85a3 Mon Sep 17 00:00:00 2001 From: Maksim Sitnikov Date: Wed, 20 Sep 2023 19:03:12 +0300 Subject: [PATCH] fix: fixes after review --- README.md | 4 ++-- src/context/analyticsContext/analyticsContext.tsx | 1 - src/hooks/useAnalytics.ts | 10 +++------- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 85ec78c1c..092b00aa0 100644 --- a/README.md +++ b/README.md @@ -222,7 +222,7 @@ You can define environment variables for dev-mode in .env.development file withi To start using any analytics, pass a handler to the constructor. The handler must be created on a project side. The handler will receive the `default` and `custom` event objects. The passed handler will be fired on a button, link, navigation, and control clicks. As one handler is used for all events treatment, pay attention to how to treat different events while creating the handler. There are predefined fields that serve to help you to build complex logic. -Pass `autoEvents: true` to constructor to fire automatically configured events. Pass `multipleEvents: true` to constructor to fire events multiple times. +Pass `autoEvents: true` to constructor to fire automatically configured events. ```ts function sendEvents(events: MyEventType []) { @@ -232,7 +232,7 @@ function sendEvents(events: MyEventType []) { diff --git a/src/context/analyticsContext/analyticsContext.tsx b/src/context/analyticsContext/analyticsContext.tsx index 5061b8988..69b412b19 100644 --- a/src/context/analyticsContext/analyticsContext.tsx +++ b/src/context/analyticsContext/analyticsContext.tsx @@ -5,7 +5,6 @@ import {AnalyticsEvent} from '../../models'; export interface AnalyticsContextProps { sendEvents?: (events: AnalyticsEvent[]) => void; autoEvents?: boolean; - multipleEvents?: boolean; } export const AnalyticsContext = React.createContext({}); diff --git a/src/hooks/useAnalytics.ts b/src/hooks/useAnalytics.ts index 762ff2a5f..fd6295e1c 100644 --- a/src/hooks/useAnalytics.ts +++ b/src/hooks/useAnalytics.ts @@ -1,13 +1,11 @@ import {useContext, useMemo} from 'react'; -import {memoize} from 'lodash'; - import {AnalyticsContext} from '../context/analyticsContext'; import {BlockIdContext} from '../context/blockIdContext'; import {AnalyticsEvent, PredefinedEventTypes} from '../models'; export const useAnalytics = (name = '', target?: string) => { - const {sendEvents, autoEvents, multipleEvents} = useContext(AnalyticsContext); + const {sendEvents, autoEvents} = useContext(AnalyticsContext); const context = useContext(BlockIdContext); const defaultEvent = useMemo( () => @@ -23,12 +21,12 @@ export const useAnalytics = (name = '', target?: string) => { ); if (!sendEvents) { - return memoize(() => {}); + return () => {}; } const defaultEvents = defaultEvent && autoEvents ? [defaultEvent] : []; - const handler = ( + return ( e?: AnalyticsEvent | AnalyticsEvent[] | null, additionalContext?: Record, ) => { @@ -51,6 +49,4 @@ export const useAnalytics = (name = '', target?: string) => { sendEvents(preparedEvents); }; - - return multipleEvents ? handler : memoize(handler); };