cache analytics id in utils service

This commit is contained in:
Kyle Spearrin 2016-10-02 00:34:19 -04:00
parent 7129e8b3e6
commit ddd76357cd
2 changed files with 23 additions and 15 deletions

View File

@ -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');

View File

@ -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';