diff --git a/src/widgets/GoogleAnalyticsWidget/GoogleAnalyticsWidget.tsx b/src/widgets/GoogleAnalyticsWidget/GoogleAnalyticsWidget.tsx new file mode 100644 index 0000000..262e108 --- /dev/null +++ b/src/widgets/GoogleAnalyticsWidget/GoogleAnalyticsWidget.tsx @@ -0,0 +1,44 @@ +'use client' +import React, { useEffect, useState, useCallback } from 'react'; +import { apiInstance } from "@/shared/config/apiConfig"; +import { AxiosError } from "axios"; + +const GoogleAnalyticsWidget = () => { + + const [visitors, setVisitors] = useState(""); + + /* const getAnalytics = async () => { + try { + const response = await apiInstance.get("/report/google_analytics/"); + return response.data; + } catch (error: unknown) { + if (error instanceof AxiosError) console.log(error.message); + } + };*/ + + //const data = await getAnalytics(); + + const fetchMyAPI = useCallback(async () => { + const getAnalytics = async () => { + try { + const response = await apiInstance.get("/report/google_analytics/"); + return response.data; + } catch (error: unknown) { + if (error instanceof AxiosError) console.log(error.message); + } + }; + const data = await getAnalytics(); + setVisitors(data.visitors); + }, [visitors]) + + useEffect(() => { + fetchMyAPI(); + }, []); + + return ( +

Total cummulative visitors: {visitors}

+) + +}; + +export default GoogleAnalyticsWidget;