From a06f4a9df6367beb65890bd3fc9886a110d88d6d Mon Sep 17 00:00:00 2001 From: "grafana-delivery-bot[bot]" <132647405+grafana-delivery-bot[bot]@users.noreply.github.com> Date: Mon, 17 Jun 2024 18:40:41 +0300 Subject: [PATCH] [v11.0.x] Analytics: Fix ApplicationInsights integration (#89300) Analytics: Fix ApplicationInsights integration (#89299) change ApplicationInsights backend to use SystemJS to load (cherry picked from commit 7bb883e375c52537da33f8c64d0dcd70d3722f82) Co-authored-by: Ashley Harrison --- .betterer.results | 4 ---- .../backends/analytics/ApplicationInsightsBackend.ts | 12 ++++++------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/.betterer.results b/.betterer.results index f84227274d1..9c6f3c30dfe 100644 --- a/.betterer.results +++ b/.betterer.results @@ -1295,10 +1295,6 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"] ], - "public/app/core/services/echo/backends/analytics/ApplicationInsightsBackend.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"] - ], "public/app/core/services/echo/backends/analytics/RudderstackBackend.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], diff --git a/public/app/core/services/echo/backends/analytics/ApplicationInsightsBackend.ts b/public/app/core/services/echo/backends/analytics/ApplicationInsightsBackend.ts index 433d4582aff..78db86015cd 100644 --- a/public/app/core/services/echo/backends/analytics/ApplicationInsightsBackend.ts +++ b/public/app/core/services/echo/backends/analytics/ApplicationInsightsBackend.ts @@ -7,8 +7,6 @@ import { PageviewEchoEvent, } from '@grafana/runtime'; -import { loadScript } from '../../utils'; - interface ApplicationInsights { trackPageView: () => void; trackEvent: (event: { name: string; properties?: Record }) => void; @@ -39,10 +37,12 @@ export class ApplicationInsightsBackend implements EchoBackend { - const init = new (window as any).Microsoft.ApplicationInsights.ApplicationInsights(applicationInsightsOpts); - window.applicationInsights = init.loadAppInsights(); - }); + System.import(url) + .then((m) => (m.default ? m.default : m)) + .then(({ ApplicationInsights }) => { + const init = new ApplicationInsights(applicationInsightsOpts); + window.applicationInsights = init.loadAppInsights(); + }); } addEvent = (e: PageviewEchoEvent | InteractionEchoEvent) => {