forked from Transparency/kgroad-frontend2
Merge
This commit is contained in:
commit
b10ab93bf1
44
src/widgets/GoogleAnalyticsWidget/GoogleAnalyticsWidget.tsx
Normal file
44
src/widgets/GoogleAnalyticsWidget/GoogleAnalyticsWidget.tsx
Normal 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;
|
Loading…
Reference in New Issue
Block a user