File size: 995 Bytes
cf30fac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
 * Safe, privacy-first telemetry dispatcher.
 * Dispatches events only if an authorized provider (Google Analytics gtag or Plausible) is mounted.
 * Never collects or transmits personal data, filenames, or image content.
 */

export function trackEvent(eventName, params = {}) {
  if (typeof window === 'undefined') return

  // 1. Google Analytics (gtag)
  if (typeof window.gtag === 'function') {
    try {
      window.gtag('event', eventName, params)
    } catch (e) {
      // Suppress analytics dispatch errors to never disrupt UI
    }
  }

  // 2. Plausible Analytics
  if (typeof window.plausible === 'function') {
    try {
      window.plausible(eventName, { props: params })
    } catch (e) {
      // Suppress analytics dispatch errors
    }
  }

  // 3. Custom Event for extensible listeners
  try {
    window.dispatchEvent(
      new CustomEvent('rembg:track', {
        detail: { eventName, params },
      })
    )
  } catch (e) {
    // Suppress custom event errors
  }
}