{"version":3,"sources":["webpack:///./src/feature/goal-tracker/goal-tracker.js","webpack:///./src/foundation/utilities/development.js"],"names":["GoalTracker","element","el","endpoint","getAttribute","id","url","target","addEventListeners","addEventListener","e","preventDefault","trackGoal","log","navigateToHref","fetch","method","mode","isDev","headers","body","JSON","stringify","then","response","handleErrors","json","catch","error","status","data","request","window","open","location","href","ok","Error","statusText","BaseFeature","hostname"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;AACA;;;;;;;;;;IAEMA,W;;;AACL,sBAAYC,OAAZ,EAAqB;AAAA;;AAAA,wHACdA,OADc;;AAEpB,QAAKC,EAAL,GAAUD,OAAV;AACA,QAAKE,QAAL,GAAgB,MAAKD,EAAL,CAAQE,YAAR,CAAqB,eAArB,CAAhB;AACA,QAAKC,EAAL,GAAU,MAAKH,EAAL,CAAQE,YAAR,CAAqB,SAArB,CAAV;AACA,QAAKE,GAAL,GAAW,MAAKJ,EAAL,CAAQE,YAAR,CAAqB,MAArB,CAAX;AACA,QAAKG,MAAL,GAAc,MAAKL,EAAL,CAAQE,YAAR,CAAqB,QAArB,CAAd;AACA,QAAKI,iBAAL;AAPoB;AAQpB;;;;sCAEmB;AAAA;;AACnB,QAAKN,EAAL,CAAQO,gBAAR,CAAyB,OAAzB,EAAkC,UAACC,CAAD,EAAO;AACxCA,MAAEC,cAAF;AACA,WAAKC,SAAL;AACA,IAHD;AAIA;;;8BAEW;AAAA;;AACX,OAAI,CAAC,KAAKT,QAAV,EAAoB;AACnB,SAAKU,GAAL,CAAS,gCAAT;AACA,SAAKC,cAAL;AACA;AACA;AACD,OAAI,CAAC,KAAKT,EAAV,EAAc;AACb,SAAKQ,GAAL,CAAS,sBAAT;AACA,SAAKC,cAAL;AACA;AACA;;AAED,QAAKD,GAAL,oBAA0B,KAAKR,EAA/B;AACAU,SACC,KAAKZ,QADN,EACgB;AACda,YAAQ,MADM;AAEdC,UAAMC,qBAAQ,MAAR,GAAiB,aAFT;AAGdC,aAAS;AACR,qBAAgB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xF,C","file":"17-5d5b9c88.pkg.js","sourcesContent":["import BaseFeature from '../../foundation/base/base';\r\nimport { isDev } from '../../foundation/utilities/development';\r\n\r\nclass GoalTracker extends BaseFeature {\r\n\tconstructor(element) {\r\n\t\tsuper(element);\r\n\t\tthis.el = element;\r\n\t\tthis.endpoint = this.el.getAttribute('data-endpoint');\r\n\t\tthis.id = this.el.getAttribute('data-id');\r\n\t\tthis.url = this.el.getAttribute('href');\r\n\t\tthis.target = this.el.getAttribute('target');\r\n\t\tthis.addEventListeners();\r\n\t}\r\n\r\n\taddEventListeners() {\r\n\t\tthis.el.addEventListener('click', (e) => {\r\n\t\t\te.preventDefault();\r\n\t\t\tthis.trackGoal();\r\n\t\t});\r\n\t}\r\n\r\n\ttrackGoal() {\r\n\t\tif (!this.endpoint) {\r\n\t\t\tthis.log('Tracking endpoint is undefined');\r\n\t\t\tthis.navigateToHref();\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tif (!this.id) {\r\n\t\t\tthis.log('Goal ID is undefined');\r\n\t\t\tthis.navigateToHref();\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tthis.log(`Tracking goal:${this.id}`);\r\n\t\tfetch(\r\n\t\t\tthis.endpoint, {\r\n\t\t\t\tmethod: 'POST',\r\n\t\t\t\tmode: isDev ? 'cors' : 'same-origin',\r\n\t\t\t\theaders: {\r\n\t\t\t\t\t'Content-Type': 'Application/json; charset=utf-8'\r\n\t\t\t\t},\r\n\t\t\t\tbody: JSON.stringify({ id: this.id })\r\n\t\t\t})\r\n\t\t\t.then((response) => {\r\n\t\t\t\tGoalTracker.handleErrors(response);\r\n\t\t\t\treturn response.json();\r\n\t\t\t})\r\n\t\t\t.then((response) => {\r\n\t\t\t\tthis.log(response);\r\n\t\t\t\tthis.navigateToHref();\r\n\t\t\t})\r\n\t\t\t.catch((error) => {\r\n\t\t\t\tif (error.response) {\r\n\t\t\t\t\t// Client received an error response (5xx, 4xx)\r\n\t\t\t\t\tthis.log('Response Error', `${error.response.status}: ${error.response.data}`);\r\n\t\t\t\t} else if (error.request) {\r\n\t\t\t\t\t// Client never received a response, or request never left\r\n\t\t\t\t\tthis.log('Network error', error.request);\r\n\t\t\t\t} else {\r\n\t\t\t\t\t// For debugging purposes if something unexpected goes wrong\r\n\t\t\t\t\tthis.log('Unexpected Error', error);\r\n\t\t\t\t}\r\n\t\t\t\tthis.navigateToHref();\r\n\t\t\t});\r\n\t}\r\n\r\n\tnavigateToHref() {\r\n\t\tif (!this.url) return;\r\n\t\tif (this.target) {\r\n\t\t\twindow.open(this.url, this.target);\r\n\t\t} else {\r\n\t\t\twindow.location.href = this.url;\r\n\t\t}\r\n\t}\r\n\r\n\tstatic handleErrors(response) {\r\n\t\tif (!response.ok) {\r\n\t\t\tthrow Error(response.statusText);\r\n\t\t}\r\n\t\treturn response;\r\n\t}\r\n}\r\n\r\nexport default GoalTracker;\r\n","export const isDev = (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1');\r\n"],"sourceRoot":""}