{"version":3,"file":"LocalTracker-bc65f3c7.js","sources":["../../../app/javascript/analytics/OmniTracker/LocalTracker.ts"],"sourcesContent":["import { PlainObject } from 'shared/util/types.util'\nimport Tracker from 'analytics/OmniTracker/Tracker'\nimport { DateTime } from 'luxon'\nimport { v4 as uuid } from 'uuid'\nimport singleton from 'shared/util/singleton.util'\n\nexport interface LocalEvent {\n id: string\n name: string\n time: DateTime\n payload: PlainObject\n}\n\nexport type ChangeListener = (event: LocalEvent) => void\n\nclass LocalTracker implements Tracker {\n private enabled = false\n\n private listeners: ChangeListener[] = []\n\n trackEvent(name: string, payload: PlainObject): void {\n if (this.enabled) {\n const event: LocalEvent = {\n id: uuid(), name, time: DateTime.now(), payload,\n }\n this.listeners.forEach((listener) => listener(event))\n }\n }\n\n trackView(payload: PlainObject) {\n this.trackEvent('$view', { ...payload, page: window.location.pathname })\n }\n\n trackError(error: Error) {\n this.trackEvent('$error', { name: error.name, message: error.message })\n }\n\n resetSession(): void {\n // No-op\n }\n\n enable(enabled = true): void {\n this.enabled = enabled\n }\n\n isEnabled(): boolean {\n return this.enabled\n }\n\n addListener(listener: ChangeListener): void {\n this.listeners.push(listener)\n }\n\n removeListener(listener: ChangeListener): void {\n this.listeners = this.listeners.filter((l) => l !== listener)\n }\n}\n\n// Singleton export, there can only ever be one LocalTracker\nexport default singleton('LocalTracker', () => new LocalTracker())\n"],"names":["LocalTracker","__publicField","name","payload","event","uuid","DateTime","listener","error","enabled","l","LocalTracker$1","singleton"],"mappings":"2SAeA,MAAMA,CAAgC,CAAtC,cACUC,EAAA,eAAU,IAEVA,EAAA,iBAA8B,CAAA,GAEtC,WAAWC,EAAcC,EAA4B,CACnD,GAAI,KAAK,QAAS,CAChB,MAAMC,EAAoB,CACxB,GAAIC,EAAK,EAAG,KAAAH,EAAM,KAAMI,EAAS,IAAI,EAAG,QAAAH,CAAA,EAE1C,KAAK,UAAU,QAASI,GAAaA,EAASH,CAAK,CAAC,CACtD,CACF,CAEA,UAAUD,EAAsB,CACzB,KAAA,WAAW,QAAS,CAAE,GAAGA,EAAS,KAAM,OAAO,SAAS,QAAA,CAAU,CACzE,CAEA,WAAWK,EAAc,CAClB,KAAA,WAAW,SAAU,CAAE,KAAMA,EAAM,KAAM,QAASA,EAAM,OAAA,CAAS,CACxE,CAEA,cAAqB,CAErB,CAEA,OAAOC,EAAU,GAAY,CAC3B,KAAK,QAAUA,CACjB,CAEA,WAAqB,CACnB,OAAO,KAAK,OACd,CAEA,YAAYF,EAAgC,CACrC,KAAA,UAAU,KAAKA,CAAQ,CAC9B,CAEA,eAAeA,EAAgC,CAC7C,KAAK,UAAY,KAAK,UAAU,OAAQG,GAAMA,IAAMH,CAAQ,CAC9D,CACF,CAGA,MAAeI,EAAAC,EAAU,eAAgB,IAAM,IAAIZ,CAAc"}