()
| 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 | } |
| 118 | ); |
| 119 | console.error('Tracker injection error:', error); |
| 120 | } finally { |
| 121 | setIsInjecting(false); |
| 122 | } |
| 123 | }; |
| 124 | |
| 125 | const incrementEventCount = (eventType: string, count: number = 1) => { |
| 126 | setEventCounts((prev) => ({ |
nothing calls this directly
no test coverage detected