This commit is contained in:
Vladislav Khorev 2024-09-10 17:37:17 +00:00
commit b10ab93bf1

View File

@ -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<string>("");
/* 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 (
<div><p>Total cummulative visitors: {visitors}</p></div>
)
};
export default GoogleAnalyticsWidget;