{"version":3,"file":"utils.mjs","sources":["../../../src/analytics/utils.ts"],"sourcesContent":["import { config } from '../config';\nimport { locationService } from '../services';\nimport { getEchoSrv, EchoEventType } from '../services/EchoSrv';\n\nimport {\n  type ExperimentViewEchoEvent,\n  type InteractionEchoEvent,\n  type MetaAnalyticsEvent,\n  type MetaAnalyticsEventPayload,\n  type PageviewEchoEvent,\n} from './types';\n\n/**\n * Helper function to report meta analytics to the {@link EchoSrv}.\n *\n * @public\n */\nexport const reportMetaAnalytics = (payload: MetaAnalyticsEventPayload) => {\n  getEchoSrv().addEvent<MetaAnalyticsEvent>({\n    type: EchoEventType.MetaAnalytics,\n    payload,\n  });\n};\n\nexport const MAX_PAGE_URL_LENGTH = 2048;\nexport const TRUNCATION_MARKER = '[url too long]';\n\n/**\n * Helper function to report pageview events to the {@link EchoSrv}.\n *\n * @public\n */\nexport const reportPageview = () => {\n  const location = locationService.getLocation();\n  const fullPage = `${config.appSubUrl ?? ''}${location.pathname}${location.search}${location.hash}`;\n  const page =\n    fullPage.length > MAX_PAGE_URL_LENGTH\n      ? `${fullPage.substring(0, MAX_PAGE_URL_LENGTH - TRUNCATION_MARKER.length)}${TRUNCATION_MARKER}`\n      : fullPage;\n  getEchoSrv().addEvent<PageviewEchoEvent>({\n    type: EchoEventType.Pageview,\n    payload: {\n      page,\n    },\n  });\n};\n\n/**\n * Helper function to report interaction events to the {@link EchoSrv}.\n *\n * @param options.silent - If true, the event is dispatched to EchoSrv subscribers\n * but not forwarded to analytics backends. Use for high-frequency UI signals\n * that downstream subscribers care about but shouldn't pollute the analytics stream.\n *\n * @public\n */\nexport const reportInteraction = (\n  interactionName: string,\n  properties?: Record<string, unknown>,\n  options?: { silent?: boolean }\n) => {\n  // get static reporting context and append it to properties\n  if (config.reportingStaticContext && config.reportingStaticContext instanceof Object) {\n    properties = { ...properties, ...config.reportingStaticContext };\n  }\n  getEchoSrv().addEvent<InteractionEchoEvent>({\n    type: EchoEventType.Interaction,\n    payload: {\n      interactionName,\n      properties,\n      silent: options?.silent,\n    },\n  });\n};\n\n/**\n * Helper function to report experimentview events to the {@link EchoSrv}.\n *\n * @public\n */\nexport const reportExperimentView = (id: string, group: string, variant: string) => {\n  getEchoSrv().addEvent<ExperimentViewEchoEvent>({\n    type: EchoEventType.ExperimentView,\n    payload: {\n      experimentId: id,\n      experimentGroup: group,\n      experimentVariant: variant,\n    },\n  });\n};\n"],"names":[],"mappings":";;;;;;AAiBO,MAAM,mBAAA,GAAsB,CAAC,OAAA,KAAuC;AACzE,EAAA,UAAA,GAAa,QAAA,CAA6B;AAAA,IACxC,MAAM,aAAA,CAAc,aAAA;AAAA,IACpB;AAAA,GACD,CAAA;AACH;AAEO,MAAM,mBAAA,GAAsB;AAC5B,MAAM,iBAAA,GAAoB;AAO1B,MAAM,iBAAiB,MAAM;AAhCpC,EAAA,IAAA,EAAA;AAiCE,EAAA,MAAM,QAAA,GAAW,gBAAgB,WAAA,EAAY;AAC7C,EAAA,MAAM,QAAA,GAAW,CAAA,EAAA,CAAG,EAAA,GAAA,MAAA,CAAO,SAAA,KAAP,YAAoB,EAAE,CAAA,EAAG,QAAA,CAAS,QAAQ,CAAA,EAAG,QAAA,CAAS,MAAM,CAAA,EAAG,SAAS,IAAI,CAAA,CAAA;AAChG,EAAA,MAAM,IAAA,GACJ,QAAA,CAAS,MAAA,GAAS,mBAAA,GACd,GAAG,QAAA,CAAS,SAAA,CAAU,CAAA,EAAG,mBAAA,GAAsB,iBAAA,CAAkB,MAAM,CAAC,CAAA,EAAG,iBAAiB,CAAA,CAAA,GAC5F,QAAA;AACN,EAAA,UAAA,GAAa,QAAA,CAA4B;AAAA,IACvC,MAAM,aAAA,CAAc,QAAA;AAAA,IACpB,OAAA,EAAS;AAAA,MACP;AAAA;AACF,GACD,CAAA;AACH;AAWO,MAAM,iBAAA,GAAoB,CAC/B,eAAA,EACA,UAAA,EACA,OAAA,KACG;AAEH,EAAA,IAAI,MAAA,CAAO,sBAAA,IAA0B,MAAA,CAAO,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