From 9f12079f0532559d1462e0513f734f022fd58fd8 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 18 Oct 2016 19:57:15 -0400 Subject: [PATCH] added setting to disable google analytics --- src/popup/app/settings/settingsController.js | 31 ++++++++++++++++++-- src/popup/app/settings/views/settings.html | 4 +++ src/scripts/analytics.js | 14 +++++---- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/popup/app/settings/settingsController.js b/src/popup/app/settings/settingsController.js index 93de11c7b3..7e4778cd53 100644 --- a/src/popup/app/settings/settingsController.js +++ b/src/popup/app/settings/settingsController.js @@ -1,8 +1,19 @@ angular .module('bit.settings') - .controller('settingsController', function ($scope, loginService, $state, SweetAlert, utilsService, $analytics, i18nService) { + .controller('settingsController', function ($scope, loginService, $state, SweetAlert, utilsService, $analytics, + i18nService) { + var gaKey = 'disableGa'; + + $scope.disableGa = false; $scope.i18n = i18nService; + + chrome.storage.local.get(gaKey, function (obj) { + if (obj && obj[gaKey]) { + $scope.disableGa = true; + } + }); + $scope.logOut = function () { SweetAlert.swal({ title: 'Log Out', @@ -69,6 +80,23 @@ } } + $scope.updateGa = function () { + chrome.storage.local.get(gaKey, function (obj) { + if (obj[gaKey]) { + // enable + obj[gaKey] = false; + } + else { + // disable + obj[gaKey] = true; + } + + chrome.storage.local.set(obj, function () { + $scope.disableGa = obj[gaKey]; + }); + }); + }; + $scope.rate = function () { $analytics.eventTrack('Rate Extension'); @@ -94,6 +122,5 @@ default: return; } - }; }); diff --git a/src/popup/app/settings/views/settings.html b/src/popup/app/settings/views/settings.html index c6561f96ed..fe83c92e46 100644 --- a/src/popup/app/settings/views/settings.html +++ b/src/popup/app/settings/views/settings.html @@ -45,6 +45,10 @@ {{i18n.other}}
+
+ + +
{{i18n.about}} diff --git a/src/scripts/analytics.js b/src/scripts/analytics.js index 468f1f7ce1..f1df2106ce 100644 --- a/src/scripts/analytics.js +++ b/src/scripts/analytics.js @@ -5,7 +5,13 @@ window.ga = function (action, param1, param2, param3, param4) { return; } - gaFunc(action, param1, param2, param3, param4); + chrome.storage.local.get('disableGa', function (obj) { + if (obj && obj['disableGa']) { + return; + } + + gaFunc(action, param1, param2, param3, param4); + }); }; function gaTrackEvent(options) { @@ -13,13 +19,11 @@ function gaTrackEvent(options) { '&ea=' + encodeURIComponent(options.eventAction) + (options.eventLabel ? '&el=' + encodeURIComponent(options.eventLabel) : '') + (options.eventValue ? '&ev=' + encodeURIComponent(options.eventValue) : '') + - (options.page ? '&dp=' + encodeURIComponent(options.page) : '') + - (document && document.title ? '&dt=' + encodeURIComponent(document.title) : ''); + (options.page ? '&dp=' + encodeURIComponent(options.page) : ''); } function gaTrackPageView(pagePath) { - return '&t=pageview&dp=' + encodeURIComponent(pagePath) + - (document && document.title ? '&dt=' + encodeURIComponent(document.title) : ''); + return '&t=pageview&dp=' + encodeURIComponent(pagePath); } chrome.extension.getBackgroundPage().appIdService.getAnonymousAppId(function (gaAnonAppId) {