Skip to content

Commit

Permalink
added setting to disable google analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
kspearrin committed Oct 18, 2016
1 parent 42830e5 commit 9f12079
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
31 changes: 29 additions & 2 deletions src/popup/app/settings/settingsController.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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');

Expand All @@ -94,6 +122,5 @@
default:
return;
}

};
});
4 changes: 4 additions & 0 deletions src/popup/app/settings/views/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
{{i18n.other}}
</div>
<div class="list-section-items">
<div class="list-section-item list-section-item-checkbox">
<label for="ga">Disable Google Analytics</label>
<input id="ga" type="checkbox" ng-model="disableGa" ng-change="updateGa()">
</div>
<a class="list-section-item" ui-sref="about({animation: 'in-slide-left'})">
{{i18n.about}}
<i class="fa fa-chevron-right fa-lg"></i>
Expand Down
14 changes: 9 additions & 5 deletions src/scripts/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@ 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) {
return '&t=event&ec=' + (options.eventCategory ? encodeURIComponent(options.eventCategory) : 'Event') +
'&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) {
Expand Down

0 comments on commit 9f12079

Please sign in to comment.