mirror of https://github.com/grafana/grafana
Analytics: Instrument Azure Application Insights (#38553)
* add backend * read config and pass to backend * update config docs * change var name * use connection string instead of instrumentation key * add config for endpoint url. update docs * update default ini * add spaces * remove space * Update docs/sources/administration/configuration.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update conf/defaults.ini Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update conf/defaults.ini Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>pull/39239/head
parent
6005e6572d
commit
9d3f4f5983
@ -0,0 +1,48 @@ |
|||||||
|
import $ from 'jquery'; |
||||||
|
import { EchoBackend, EchoEventType, isInteractionEvent, isPageviewEvent, PageviewEchoEvent } from '@grafana/runtime'; |
||||||
|
|
||||||
|
export interface ApplicationInsightsBackendOptions { |
||||||
|
connectionString: string; |
||||||
|
endpointUrl?: string; |
||||||
|
} |
||||||
|
|
||||||
|
export class ApplicationInsightsBackend implements EchoBackend<PageviewEchoEvent, ApplicationInsightsBackendOptions> { |
||||||
|
supportedEvents = [EchoEventType.Pageview]; |
||||||
|
|
||||||
|
constructor(public options: ApplicationInsightsBackendOptions) { |
||||||
|
$.ajax({ |
||||||
|
url: 'https://js.monitor.azure.com/scripts/b/ai.2.min.js', |
||||||
|
dataType: 'script', |
||||||
|
cache: true, |
||||||
|
}).done(function () { |
||||||
|
var applicationInsightsOpts = { |
||||||
|
config: { |
||||||
|
connectionString: options.connectionString, |
||||||
|
endpointUrl: options.endpointUrl, |
||||||
|
}, |
||||||
|
}; |
||||||
|
var init = new (window as any).Microsoft.ApplicationInsights.ApplicationInsights(applicationInsightsOpts); |
||||||
|
(window as any).applicationInsights = init.loadAppInsights(); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
addEvent = (e: PageviewEchoEvent) => { |
||||||
|
if (!(window as any).applicationInsights) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
if (isPageviewEvent(e)) { |
||||||
|
(window as any).applicationInsights.trackPageView(); |
||||||
|
} |
||||||
|
|
||||||
|
if (isInteractionEvent(e)) { |
||||||
|
(window as any).applicationInsights.trackPageView({ |
||||||
|
name: e.payload.interactionName, |
||||||
|
properties: e.payload.properties, |
||||||
|
}); |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
// Not using Echo buffering, addEvent above sends events to Application Insights as soon as they appear
|
||||||
|
flush = () => {}; |
||||||
|
} |
Loading…
Reference in new issue