From e08891fbade2b7a1a320ae93c62e05d8a1b287db Mon Sep 17 00:00:00 2001 From: Sachin Chaurasiya Date: Tue, 9 Jan 2024 13:35:40 +0530 Subject: [PATCH] Minor: invoke analytics instance only when it's available (#14636) --- .../ui/src/components/AppRouter/AppRouter.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/AppRouter.tsx b/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/AppRouter.tsx index 49bec08b5f7..af24f59a9b1 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/AppRouter.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/AppRouter.tsx @@ -11,6 +11,7 @@ * limitations under the License. */ +import { isNil } from 'lodash'; import React, { useCallback, useEffect } from 'react'; import { Redirect, Route, Switch, useLocation } from 'react-router-dom'; import { useAnalytics } from 'use-analytics'; @@ -80,8 +81,9 @@ const AppRouter = () => { /** * Ignore the slash path because we are treating my data as * default path. + * And check if analytics instance is available */ - if (pathname !== '/') { + if (pathname !== '/' && !isNil(analytics)) { // track page view on route change analytics.page(); } @@ -91,7 +93,11 @@ const AppRouter = () => { (event: MouseEvent) => { const eventValue = (event.target as HTMLElement)?.textContent || CustomEventTypes.Click; - if (eventValue) { + /** + * Ignore the click event if the event value is undefined + * And analytics instance is not available + */ + if (eventValue && !isNil(analytics)) { analytics.track(eventValue); } },