From d52ab5de2e33f2972c8c7edadddae6451e76c86d Mon Sep 17 00:00:00 2001 From: Josh Hunt Date: Tue, 11 Oct 2022 11:11:23 +0100 Subject: [PATCH] EchoSrv: Remove $.ajax for loading scripts (#56678) * user essentials mob! :trident: lastFile:public/app/core/services/echo/backends/analytics/RudderstackBackend.ts * user essentials mob! :trident: lastFile:public/app/core/services/echo/backends/analytics/ApplicationInsightsBackend.ts * user essentials mob! :trident: Co-authored-by: Joao Silva Co-authored-by: Ashley Harrison --- .../analytics/ApplicationInsightsBackend.ts | 23 ++++++++----------- .../echo/backends/analytics/GA4Backend.ts | 11 ++------- .../echo/backends/analytics/GABackend.ts | 11 +++------ .../backends/analytics/RudderstackBackend.ts | 10 ++------ public/app/core/services/echo/utils.ts | 9 ++++++++ 5 files changed, 26 insertions(+), 38 deletions(-) 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;