From b56ee4fe3e1ce539131d4fac4f2d9123d38ec493 Mon Sep 17 00:00:00 2001 From: karan Date: Tue, 1 Oct 2024 14:08:50 +0530 Subject: [PATCH] feat: :sparkles: GA hook file added --- hooks/GoogleAnalytics/useGoogleAnalyticsHandler.ts | 14 ++++++++++++++ services/config/app-config.ts | 1 + 2 files changed, 15 insertions(+) create mode 100644 hooks/GoogleAnalytics/useGoogleAnalyticsHandler.ts diff --git a/hooks/GoogleAnalytics/useGoogleAnalyticsHandler.ts b/hooks/GoogleAnalytics/useGoogleAnalyticsHandler.ts new file mode 100644 index 0000000..e3da285 --- /dev/null +++ b/hooks/GoogleAnalytics/useGoogleAnalyticsHandler.ts @@ -0,0 +1,14 @@ +import { useEffect } from 'react'; +import ReactGA from 'react-ga'; + +const useGoogleAnalyticsHandler = () => { + const TRACKING_ID: string | undefined = process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS_TRACKING_CODE; + if (TRACKING_ID) { + ReactGA.initialize(TRACKING_ID); + } else { + console.error('You have enabled Google Analytics but tracking ID is not specified. Please add Tracking ID!'); + } + return {}; +}; + +export default useGoogleAnalyticsHandler; diff --git a/services/config/app-config.ts b/services/config/app-config.ts index e68bfb6..a33423b 100644 --- a/services/config/app-config.ts +++ b/services/config/app-config.ts @@ -30,4 +30,5 @@ export const CONSTANTS = { DEFAULT_CURRENCY_VALUE: 'rupee', DEFAULT_LANGUAGE: 'en', ENABLE_SHOP_ON_AMAZON: false, + ENABLE_GOOGLE_ANALYTICS: false, };