@grafana/runtime
Version:
Grafana Runtime Library
1 lines • 3.22 kB
Source Map (JSON)
{"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 ExperimentViewEchoEvent,\n InteractionEchoEvent,\n MetaAnalyticsEvent,\n MetaAnalyticsEventPayload,\n 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\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 page = `${config.appSubUrl ?? ''}${location.pathname}${location.search}${location.hash}`;\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 * @public\n */\nexport const reportInteraction = (interactionName: string, properties?: Record<string, unknown>) => {\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 },\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":";;;;;;;;;;AAiBa,MAAA,mBAAA,GAAsB,CAAC,OAAuC,KAAA;AACzE,EAAA,UAAA,GAA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