tailwind-nextjs-blog/components/analytics/index.tsx

33 lines
869 B
TypeScript
Raw Normal View History

2022-10-17 23:37:01 +08:00
import GA from './GoogleAnalytics';
import Plausible from './Plausible';
import SimpleAnalytics from './SimpleAnalytics';
import Umami from './Umami';
import siteMetadata from '@/data/siteMetadata';
2022-07-17 21:40:41 +08:00
declare global {
interface Window {
2022-10-17 23:37:01 +08:00
gtag?: (...args: any[]) => void;
plausible?: (...args: any[]) => void;
sa_event?: (...args: any[]) => void;
}
}
2022-10-17 23:37:01 +08:00
const isProduction = process.env.NODE_ENV === 'production';
2022-07-17 21:40:41 +08:00
const Analytics = () => {
return (
<>
2022-10-17 23:37:01 +08:00
{isProduction && siteMetadata.analytics.plausibleDataDomain && (
<Plausible />
)}
{isProduction && siteMetadata.analytics.simpleAnalytics && (
<SimpleAnalytics />
)}
2022-07-17 21:40:41 +08:00
{isProduction && siteMetadata.analytics.umamiWebsiteId && <Umami />}
{isProduction && siteMetadata.analytics.googleAnalyticsId && <GA />}
</>
2022-10-17 23:37:01 +08:00
);
};
2022-07-17 21:40:41 +08:00
2022-10-17 23:37:01 +08:00
export default Analytics;