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

29 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
const SimpleAnalyticsScript = () => {
return (
<>
<Script strategy="lazyOnload" id="sa-script">
{`
window.sa_event=window.sa_event||function(){var a=[].slice.call(arguments);window.sa_event.q?window.sa_event.q.push(a):window.sa_event.q=[a]};
`}
</Script>
2022-10-17 23:37:01 +08:00
<Script
strategy="lazyOnload"
src="https://scripts.simpleanalyticscdn.com/latest.js"
/>
2022-07-17 21:40:41 +08:00
</>
2022-10-17 23:37:01 +08:00
);
};
2022-07-17 21:40:41 +08:00
// https://docs.simpleanalytics.com/events
export const logEvent = (eventName, callback) => {
if (callback) {
2022-10-17 23:37:01 +08:00
return window.sa_event?.(eventName, callback);
2022-07-17 21:40:41 +08:00
} else {
2022-10-17 23:37:01 +08:00
return window.sa_event?.(eventName);
2022-07-17 21:40:41 +08:00
}
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 SimpleAnalyticsScript;