diff --git a/public/app/core/services/echo/backends/analytics/ApplicationInsightsBackend.ts b/public/app/core/services/echo/backends/analytics/ApplicationInsightsBackend.ts index 6430c22fd1b..3fae56b9b13 100644 --- a/public/app/core/services/echo/backends/analytics/ApplicationInsightsBackend.ts +++ b/public/app/core/services/echo/backends/analytics/ApplicationInsightsBackend.ts @@ -1,5 +1,3 @@ -import $ from 'jquery'; - import { EchoBackend, EchoEventType, @@ -9,6 +7,8 @@ import { PageviewEchoEvent, } from '@grafana/runtime'; +import { loadScript } from '../../utils'; + interface ApplicationInsights { trackPageView: () => void; trackEvent: (event: { name: string; properties?: Record }) => void; @@ -31,18 +31,15 @@ export class ApplicationInsightsBackend implements EchoBackend { const init = new (window as any).Microsoft.ApplicationInsights.ApplicationInsights(applicationInsightsOpts); (window as any).applicationInsights = init.loadAppInsights(); }); diff --git a/public/app/core/services/echo/backends/analytics/GA4Backend.ts b/public/app/core/services/echo/backends/analytics/GA4Backend.ts index 15e118b786d..17b8f0f47f5 100644 --- a/public/app/core/services/echo/backends/analytics/GA4Backend.ts +++ b/public/app/core/services/echo/backends/analytics/GA4Backend.ts @@ -1,9 +1,7 @@ -import $ from 'jquery'; - import { CurrentUserDTO } from '@grafana/data'; import { EchoBackend, EchoEventType, PageviewEchoEvent } from '@grafana/runtime'; -import { getUserIdentifier } from '../../utils'; +import { getUserIdentifier, loadScript } from '../../utils'; declare global { interface Window { @@ -22,12 +20,7 @@ export class GA4EchoBackend implements EchoBackend { + const script = document.createElement('script'); + script.onload = resolve; + script.src = url; + document.head.appendChild(script); + }); +} + /** @internal */ export const echoLogger = createLogger('EchoSrv'); export const echoLog = echoLogger.logger;