{"version":3,"file":"event-CCsvbZxR.js","sources":["../../../app/assets/javascripts/app/tracking/google/event.ts"],"sourcesContent":["\nimport log from \"plugins/loglevel/index\"\nimport WaitObjectByPathPromise from \"app/wait_object_by_path_promise\"\nimport DataRetriever from \"app/data_retriever\"\n\n\nconst LOGGING_PREFIX = \"App.Tracking.Google.Event\"\nconst GOOGLE_ANALYTICS_TRACKER_NAME = (() => {\n const name: unknown = DataRetriever.get(\"google-analytics-tracker-name\")\n if (typeof name !== \"string\" || name.length === 0) {\n return null\n }\n return name\n})()\n\ninterface EventParams {\n category: string,\n action: string,\n options?: {\n eventLabel?: string,\n eventValue?: number,\n nonInteraction?: boolean,\n [key: string]: unknown,\n },\n}\n\n/*\n * @see https://developers.google.com/analytics/devguides/collection/analyticsjs/events\n *\n */\nconst track = ({category, action, options= {}}: EventParams): void => {\n if (typeof category === \"undefined\") {\n log.debug(\"category missing!\")\n return\n }\n\n if (typeof action === \"undefined\") {\n log.debug(\"action missing\")\n return\n }\n\n const debug_message_fragments = [\n LOGGING_PREFIX,\n \"about to track event with:\",\n [\n `category: [${category}]`,\n `action: [${action}]`,\n `options: [${JSON.stringify(options)}]`,\n ].join(\" ,\"),\n ]\n\n log.debug(debug_message_fragments.join(\" \"))\n\n // UA event implementation\n WaitObjectByPathPromise(\"ga\")\n .then((ga) => {\n const final_options = Object.assign({}, {\n hitType: \"event\", // Required.\n eventCategory: category, // Required.\n eventAction: action, // Required.\n }, options)\n\n const dest = GOOGLE_ANALYTICS_TRACKER_NAME === null ? \"send\" : `${GOOGLE_ANALYTICS_TRACKER_NAME}.send`\n\n ga(dest, final_options)\n\n log.debug(`${LOGGING_PREFIX} PageView tracked`)\n })\n .catch(() => {\n log.warn(\"ga is undefined!\")\n })\n}\n\nexport default { track }\nexport { track }\n"],"names":["LOGGING_PREFIX","GOOGLE_ANALYTICS_TRACKER_NAME","name","DataRetriever","track","category","action","options","log","debug_message_fragments","WaitObjectByPathPromise","ga","final_options","dest","Google_Event"],"mappings":"uJAMA,MAAMA,EAAiB,4BACjBC,GAAiC,IAAM,CACrC,MAAAC,EAAgBC,EAAc,IAAI,+BAA+B,EACvE,OAAI,OAAOD,GAAS,UAAYA,EAAK,SAAW,EACvC,KAEFA,CACT,GAAG,EAiBGE,EAAQ,CAAC,CAAC,SAAAC,EAAU,OAAAC,EAAQ,QAAAC,EAAS,MAA2B,CAChE,GAAA,OAAOF,EAAa,IAAa,CACnCG,EAAI,MAAM,mBAAmB,EAC7B,MAAA,CAGE,GAAA,OAAOF,EAAW,IAAa,CACjCE,EAAI,MAAM,gBAAgB,EAC1B,MAAA,CAGF,MAAMC,EAA0B,CAC9BT,EACA,6BACA,CACE,cAAc,OAAAK,EAAQ,KACtB,YAAY,OAAAC,EAAM,KAClB,aAAa,YAAK,UAAUC,CAAO,EAAC,IACtC,EAAE,KAAK,IAAI,CACb,EAEAC,EAAI,MAAMC,EAAwB,KAAK,GAAG,CAAC,EAG3CC,EAAwB,IAAI,EAC3B,KAAMC,GAAO,CACZ,MAAMC,EAAgB,OAAO,OAAO,GAAI,CACtC,QAAgB,QAChB,cAAgBP,EAChB,YAAgBC,GACfC,CAAO,EAEJM,EAAOZ,IAAkC,KAAO,OAAS,GAAG,OAAAA,EAA6B,SAE/FU,EAAGE,EAAMD,CAAa,EAElBJ,EAAA,MAAM,GAAG,OAAAR,EAAc,oBAAmB,CAAA,CAC/C,EACA,MAAM,IAAM,CACXQ,EAAI,KAAK,kBAAkB,CAAA,CAC5B,CACH,EAEeM,EAAA,CAAE,MAAAV,CAAM"}