From ddd76357cd99677e08e88d632e91bccc808821af Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sun, 2 Oct 2016 00:34:19 -0400 Subject: [PATCH] cache analytics id in utils service --- src/scripts/analytics.js | 16 +--------------- src/services/utilsService.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/scripts/analytics.js b/src/scripts/analytics.js index f711b2920f..92577178eb 100644 --- a/src/scripts/analytics.js +++ b/src/scripts/analytics.js @@ -1,18 +1,4 @@ -var gaUtils = chrome.extension.getBackgroundPage().utilsService, - gaTrackingId = null; - -if (gaUtils.isChrome()) { - gaTrackingId = 'UA-81915606-6'; -} -else if (gaUtils.isFirefox()) { - gaTrackingId = 'UA-81915606-7'; -} -else if (gaUtils.isEdge()) { - gaTrackingId = 'UA-81915606-9'; -} -else if (gaUtils.isOpera()) { - gaTrackingId = 'UA-81915606-8'; -} +var gaTrackingId = chrome.extension.getBackgroundPage().utilsService.analyticsId(); if (gaTrackingId) { ga('create', gaTrackingId, 'auto'); diff --git a/src/services/utilsService.js b/src/services/utilsService.js index c994ff0c59..6b91dd76df 100644 --- a/src/services/utilsService.js +++ b/src/services/utilsService.js @@ -2,6 +2,7 @@ function UtilsService() { initUtilsService(); this.browserCache = null; + this.analyticsIdCache = null; }; function initUtilsService() { @@ -42,6 +43,27 @@ function initUtilsService() { return this.getBrowser() === 'opera'; } + UtilsService.prototype.analyticsId = function () { + if (this.analyticsIdCache) { + return this.analyticsIdCache; + } + + if (this.isChrome()) { + this.analyticsIdCache = 'UA-81915606-6'; + } + else if (this.isFirefox()) { + this.analyticsIdCache = 'UA-81915606-7'; + } + else if (this.isEdge()) { + this.analyticsIdCache = 'UA-81915606-9'; + } + else if (this.isOpera()) { + this.analyticsIdCache = 'UA-81915606-8'; + } + + return this.analyticsIdCache; + } + UtilsService.prototype.initListSectionItemListeners = function (doc, angular) { if (!doc) { throw 'doc parameter required';