From c84e3c00fe6cd247a87c394d1f244c9546c9cc16 Mon Sep 17 00:00:00 2001 From: Patrick O'Carroll Date: Thu, 26 Oct 2017 13:22:45 +0200 Subject: [PATCH] converted analytics.js to ts, minor code formatting fix to timer.ts (#9663) --- public/app/core/services/analytics.js | 41 --------------------------- public/app/core/services/analytics.ts | 36 +++++++++++++++++++++++ public/app/core/services/timer.ts | 2 +- 3 files changed, 37 insertions(+), 42 deletions(-) delete mode 100644 public/app/core/services/analytics.js create mode 100644 public/app/core/services/analytics.ts diff --git a/public/app/core/services/analytics.js b/public/app/core/services/analytics.js deleted file mode 100644 index 9f71045b008..00000000000 --- a/public/app/core/services/analytics.js +++ /dev/null @@ -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(); - } - - }); -}); diff --git a/public/app/core/services/analytics.ts b/public/app/core/services/analytics.ts new file mode 100644 index 00000000000..87e84efa706 --- /dev/null +++ b/public/app/core/services/analytics.ts @@ -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 = (window).ga = (window).ga || function () { (ga.q = ga.q || []).push(arguments); }; ga.l = +new Date; + ga('create', (config).googleAnalyticsId, 'auto'); + return ga; + } + + init() { + this.$rootScope.$on('$viewContentLoaded', () => { + var track = { page: this.$location.url() }; + var ga = (window).ga || this.gaInit(); + ga('set', track); + ga('send', 'pageview'); + }); + } +} + +/** @ngInject */ +function startAnalytics(googleAnalyticsSrv) { + if ((config).googleAnalyticsId) { + googleAnalyticsSrv.init(); + } +} + +coreModule.service('googleAnalyticsSrv', Analytics).run(startAnalytics); + diff --git a/public/app/core/services/timer.ts b/public/app/core/services/timer.ts index 191ea63af83..6356e1f2910 100644 --- a/public/app/core/services/timer.ts +++ b/public/app/core/services/timer.ts @@ -6,7 +6,7 @@ import coreModule from 'app/core/core_module'; export class Timer { timers = []; - /** @ngInject */ + /** @ngInject */ constructor(private $timeout) { }