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

28 lines
730 B
TypeScript
Raw Permalink Normal View History

2022-10-17 23:37:01 +08:00
import Script from 'next/script';
2022-07-17 21:40:41 +08:00
2022-10-17 23:37:01 +08:00
import siteMetadata from '@/data/siteMetadata';
2022-07-17 21:40:41 +08:00
const PlausibleScript = () => {
return (
<>
<Script
strategy="lazyOnload"
data-domain={siteMetadata.analytics.plausibleDataDomain}
src="https://plausible.io/js/plausible.js"
/>
<Script strategy="lazyOnload" id="plausible-script">
{`
window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }
`}
</Script>
</>
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 PlausibleScript;
2022-07-17 21:40:41 +08:00
// https://plausible.io/docs/custom-event-goals
export const logEvent = (eventName, ...rest) => {
2022-10-17 23:37:01 +08:00
return window.plausible?.(eventName, ...rest);
};