The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/core/services/analytics.ts

45 lines
1.3 KiB

import $ from 'jquery';
import coreModule from 'app/core/core_module';
import config from 'app/core/config';
import { GrafanaRootScope } from 'app/routes/GrafanaCtrl';
export class Analytics {
/** @ngInject */
constructor(private $rootScope: GrafanaRootScope, private $location: any) {}
gaInit() {
$.ajax({
url: 'https://www.google-analytics.com/analytics.js',
dataType: 'script',
cache: true,
});
const ga = ((window as any).ga =
(window as any).ga ||
// this had the equivalent of `eslint-disable-next-line prefer-arrow/prefer-arrow-functions`
function() {
(ga.q = ga.q || []).push(arguments);
});
ga.l = +new Date();
ga('create', (config as any).googleAnalyticsId, 'auto');
ga('set', 'anonymizeIp', true);
return ga;
}
init() {
this.$rootScope.$on('$viewContentLoaded', () => {
const track = { page: `${config.appSubUrl ?? ''}${this.$location.url()}` };
const ga = (window as any).ga || this.gaInit();
ga('set', track);
ga('send', 'pageview');
});
}
}
/** @ngInject */
function startAnalytics(googleAnalyticsSrv: Analytics) {
if ((config as any).googleAnalyticsId) {
googleAnalyticsSrv.init();
}
}
coreModule.service('googleAnalyticsSrv', Analytics).run(startAnalytics);