mirror of
https://github.com/2930134478/AI-CS.git
synced 2026-06-15 00:44:30 +08:00
34 lines
753 B
TypeScript
34 lines
753 B
TypeScript
'use client';
|
|
|
|
import { useEffect } from 'react';
|
|
|
|
interface MatomoTrackerProps {
|
|
containerUrl?: string;
|
|
}
|
|
|
|
export default function MatomoTracker({ containerUrl }: MatomoTrackerProps) {
|
|
useEffect(() => {
|
|
if (!containerUrl) {
|
|
console.warn('Matomo 容器 URL 未配置');
|
|
return;
|
|
}
|
|
|
|
// 初始化 Matomo Tag Manager
|
|
const _mtm = (window._mtm = window._mtm || []);
|
|
_mtm.push({ 'mtm.startTime': new Date().getTime(), event: 'mtm.Start' });
|
|
|
|
const d = document;
|
|
const g = d.createElement('script');
|
|
const s = d.getElementsByTagName('script')[0];
|
|
|
|
g.async = true;
|
|
g.src = containerUrl;
|
|
if (s.parentNode) {
|
|
s.parentNode.insertBefore(g, s);
|
|
}
|
|
}, [containerUrl]);
|
|
|
|
return null;
|
|
}
|
|
|