Analytics: Fix ApplicationInsights integration (#89299)

change ApplicationInsights backend to use SystemJS to load
This commit is contained in:
Ashley Harrison 2024-06-17 16:19:12 +01:00 committed by GitHub
parent 8c5a925202
commit 7bb883e375
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 10 deletions

View File

@ -1320,10 +1320,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Do not use any type assertions.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"] [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": [ "public/app/core/services/echo/backends/analytics/RudderstackBackend.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Do not use any type assertions.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"],

View File

@ -7,8 +7,6 @@ import {
PageviewEchoEvent, PageviewEchoEvent,
} from '@grafana/runtime'; } from '@grafana/runtime';
import { loadScript } from '../../utils';
interface ApplicationInsights { interface ApplicationInsights {
trackPageView: () => void; trackPageView: () => void;
trackEvent: (event: { name: string; properties?: Record<string, unknown> }) => void; trackEvent: (event: { name: string; properties?: Record<string, unknown> }) => void;
@ -39,10 +37,12 @@ export class ApplicationInsightsBackend implements EchoBackend<PageviewEchoEvent
}; };
const url = 'https://js.monitor.azure.com/scripts/b/ai.2.min.js'; const url = 'https://js.monitor.azure.com/scripts/b/ai.2.min.js';
loadScript(url).then(() => { System.import(url)
const init = new (window as any).Microsoft.ApplicationInsights.ApplicationInsights(applicationInsightsOpts); .then((m) => (m.default ? m.default : m))
window.applicationInsights = init.loadAppInsights(); .then(({ ApplicationInsights }) => {
}); const init = new ApplicationInsights(applicationInsightsOpts);
window.applicationInsights = init.loadAppInsights();
});
} }
addEvent = (e: PageviewEchoEvent | InteractionEchoEvent) => { addEvent = (e: PageviewEchoEvent | InteractionEchoEvent) => {