mirror of https://github.com/grafana/grafana
converted analytics.js to ts, minor code formatting fix to timer.ts (#9663)
parent
a7d7f0d9f8
commit
c84e3c00fe
@ -1,41 +0,0 @@ |
|||||||
define([ |
|
||||||
'angular', |
|
||||||
'jquery', |
|
||||||
'app/core/core_module', |
|
||||||
'app/core/config', |
|
||||||
], |
|
||||||
function(angular, $, coreModule, config) { |
|
||||||
'use strict'; |
|
||||||
|
|
||||||
config = config.default; |
|
||||||
|
|
||||||
coreModule.default.service('googleAnalyticsSrv', function($rootScope, $location) { |
|
||||||
|
|
||||||
function gaInit() { |
|
||||||
$.getScript('https://www.google-analytics.com/analytics.js'); // jQuery shortcut
|
|
||||||
var ga = window.ga = window.ga || function () { (ga.q = ga.q || []).push(arguments); }; ga.l = +new Date; |
|
||||||
ga('create', config.googleAnalyticsId, 'auto'); |
|
||||||
return ga; |
|
||||||
} |
|
||||||
|
|
||||||
this.init = function() { |
|
||||||
|
|
||||||
$rootScope.$on('$viewContentLoaded', function() { |
|
||||||
var track = { page: $location.url() }; |
|
||||||
|
|
||||||
var ga = window.ga || gaInit(); |
|
||||||
|
|
||||||
ga('set', track); |
|
||||||
ga('send', 'pageview'); |
|
||||||
}); |
|
||||||
|
|
||||||
}; |
|
||||||
|
|
||||||
}).run(function(googleAnalyticsSrv) { |
|
||||||
|
|
||||||
if (config.googleAnalyticsId) { |
|
||||||
googleAnalyticsSrv.init(); |
|
||||||
} |
|
||||||
|
|
||||||
}); |
|
||||||
}); |
|
||||||
@ -0,0 +1,36 @@ |
|||||||
|
import $ from 'jquery'; |
||||||
|
import coreModule from 'app/core/core_module'; |
||||||
|
import config from 'app/core/config'; |
||||||
|
|
||||||
|
export class Analytics { |
||||||
|
|
||||||
|
/** @ngInject */ |
||||||
|
constructor(private $rootScope, private $location) { |
||||||
|
} |
||||||
|
|
||||||
|
gaInit() { |
||||||
|
$.getScript('https://www.google-analytics.com/analytics.js'); // jQuery shortcut
|
||||||
|
var ga = (<any>window).ga = (<any>window).ga || function () { (ga.q = ga.q || []).push(arguments); }; ga.l = +new Date; |
||||||
|
ga('create', (<any>config).googleAnalyticsId, 'auto'); |
||||||
|
return ga; |
||||||
|
} |
||||||
|
|
||||||
|
init() { |
||||||
|
this.$rootScope.$on('$viewContentLoaded', () => { |
||||||
|
var track = { page: this.$location.url() }; |
||||||
|
var ga = (<any>window).ga || this.gaInit(); |
||||||
|
ga('set', track); |
||||||
|
ga('send', 'pageview'); |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** @ngInject */ |
||||||
|
function startAnalytics(googleAnalyticsSrv) { |
||||||
|
if ((<any>config).googleAnalyticsId) { |
||||||
|
googleAnalyticsSrv.init(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
coreModule.service('googleAnalyticsSrv', Analytics).run(startAnalytics); |
||||||
|
|
||||||
Loading…
Reference in new issue