add support for interaction events (#39752)

This commit is contained in:
Erik Sundell 2021-09-29 10:41:16 +02:00 committed by GitHub
parent 4682cf5b7c
commit db8c9122aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,12 @@
import $ from 'jquery'; import $ from 'jquery';
import { EchoBackend, EchoEventType, isInteractionEvent, isPageviewEvent, PageviewEchoEvent } from '@grafana/runtime'; import {
EchoBackend,
EchoEventType,
InteractionEchoEvent,
isInteractionEvent,
isPageviewEvent,
PageviewEchoEvent,
} from '@grafana/runtime';
export interface ApplicationInsightsBackendOptions { export interface ApplicationInsightsBackendOptions {
connectionString: string; connectionString: string;
@ -7,7 +14,7 @@ export interface ApplicationInsightsBackendOptions {
} }
export class ApplicationInsightsBackend implements EchoBackend<PageviewEchoEvent, ApplicationInsightsBackendOptions> { export class ApplicationInsightsBackend implements EchoBackend<PageviewEchoEvent, ApplicationInsightsBackendOptions> {
supportedEvents = [EchoEventType.Pageview]; supportedEvents = [EchoEventType.Pageview, EchoEventType.Interaction];
constructor(public options: ApplicationInsightsBackendOptions) { constructor(public options: ApplicationInsightsBackendOptions) {
$.ajax({ $.ajax({
@ -26,7 +33,7 @@ export class ApplicationInsightsBackend implements EchoBackend<PageviewEchoEvent
}); });
} }
addEvent = (e: PageviewEchoEvent) => { addEvent = (e: PageviewEchoEvent | InteractionEchoEvent) => {
if (!(window as any).applicationInsights) { if (!(window as any).applicationInsights) {
return; return;
} }
@ -36,7 +43,7 @@ export class ApplicationInsightsBackend implements EchoBackend<PageviewEchoEvent
} }
if (isInteractionEvent(e)) { if (isInteractionEvent(e)) {
(window as any).applicationInsights.trackPageView({ (window as any).applicationInsights.trackEvent({
name: e.payload.interactionName, name: e.payload.interactionName,
properties: e.payload.properties, properties: e.payload.properties,
}); });