DavidWells / analytics

Lightweight analytics abstraction layer for tracking page views, custom events, & identifying visitors
https://getanalytics.io
MIT License
2.46k stars 243 forks source link

analytics constructor can fail to init breaking entire app #391

Open ryanhamilton opened 1 year ago

ryanhamilton commented 1 year ago

Version: "analytics": "^0.8.1",

If you have a URL containing this: ?a=1&%%20Exe The line:

export const analytics = Analytics({ app: 'Pulse', debug:true, plugins: myPlugins });

Will throw an error (stack trace below). Which since I didn't have it trapped and I run this early in my application, causes the whole app not to load.

Stack Trace:

Uncaught TypeError: a is null
    s analytics-utils.module.js:55
    s analytics-utils.module.js:64
    Ve analytics-core.module.js:1142
    analyticsLib analytics.browser.es.js:43
    tsx App.tsx:102
    factory react refresh:6
    Webpack 7
analytics-utils.module.js:55
    s analytics-utils.module.js:55
    s analytics-utils.module.js:64
    Ve analytics-core.module.js:1142
    analyticsLib analytics.browser.es.js:43
    tsx App.tsx:102
    factory react refresh:6
    Webpack 7

As a workaround and to prevent analytics from ever being able to break my app I'm doing:

let analytics:any = { track:()=>{}, page:()=>{}};
try {
  analytics = Analytics({ app: 'Pulse', debug:true, plugins: myPlugins });
} catch {
  console.error("analytics failed to load");
}
export { analytics };