export function trackEvent(name, params = {}) {
if (typeof window.gtag === 'function') {
window.gtag('event', name, params);
}
}
function anonymizeFile(name, size) {
const ext = name.includes('.') ? name.slice(name.lastIndexOf('.')) : 'unknown';
return { ext, size_kb: Math.round(size / 1024) };
}
export function trackFileUpload(fileName, fileSize, fileType) {
const { ext, size_kb } = anonymizeFile(fileName, fileSize);
trackEvent('file_upload', { file_ext: ext, size_kb, file_type: fileType });
}
export function trackTabView(tabId) {
trackEvent('tab_view', { tab_id: tabId });
}
export function trackExport(format, tabId) {
trackEvent('export', { format, tab_id: tabId });
}
export function trackFeatureUse(feature, details = {}) {
trackEvent('feature_use', { feature, ...details });
}
export function trackError(context, message) {
trackEvent('error', { context, message: String(message).slice(0, 100) });
}
export function trackPerformance(metric, durationMs) {
trackEvent('performance', { metric, duration_ms: Math.round(durationMs) });
}