MCPcopy
hub / github.com/msgbyte/tianji / Home

Function Home

example/web/src/app/page.tsx:60–946  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

58}
59
60export default function Home() {
61 const [backendUrl, setBackendUrl] = useLocalStorageState(
62 'tianji.backendUrl',
63 {
64 defaultValue: 'http://localhost:12345',
65 }
66 );
67 const [websiteId, setWebsiteId] = useLocalStorageState('tianji.websiteId', {
68 defaultValue: '',
69 });
70 const [injectedEl, setInjectedEl] = useState<HTMLScriptElement | null>(null);
71 const [isInjecting, setIsInjecting] = useState(false);
72 const [eventCounts, setEventCounts] = useState<Record<string, number>>({});
73 const [isBatchSending, setIsBatchSending] = useState(false);
74 const [batchProgress, setBatchProgress] = useState(0);
75
76 const injectTracker = async () => {
77 if (isInjecting) return;
78
79 setIsInjecting(true);
80
81 if (injectedEl) {
82 injectedEl.remove();
83 setInjectedEl(null);
84 setEventCounts({});
85 }
86
87 if (!backendUrl || !websiteId) {
88 toast.error(
89 'Missing required fields! Please fill in both Backend URL and Website ID.',
90 {
91 description: 'Both fields are required to initialize the tracker.',
92 }
93 );
94 setIsInjecting(false);
95 return;
96 }
97
98 try {
99 const scriptEl = await initTianjiTracker({
100 url: backendUrl,
101 websiteId,
102 });
103
104 console.log('scriptEl', scriptEl);
105 if (scriptEl) {
106 setInjectedEl(scriptEl);
107 }
108 toast.success('Tianji tracker injected successfully!', {
109 description:
110 'You can now start sending events to your analytics dashboard.',
111 });
112 } catch (error) {
113 toast.error(
114 'Failed to inject tracker. Please check your configuration.',
115 {
116 description: 'Make sure your backend URL is correct and accessible.',
117 }

Callers

nothing calls this directly

Calls 8

reportWebsiteEventFunction · 0.85
incrementEventCountFunction · 0.85
sendPageViewFunction · 0.85
identifyWebsiteUserFunction · 0.85
batchSendEventsFunction · 0.85
nowMethod · 0.80
valuesMethod · 0.80
getAttributeMethod · 0.80

Tested by

no test coverage detected