Skip to content

Commit

Permalink
Merge pull request greatsuspender#1239 from greatsuspender/tracking_o…
Browse files Browse the repository at this point in the history
…pt_out

Tracking Opt-Out
  • Loading branch information
greatsuspender committed Oct 18, 2020
2 parents 03ea20d + e06c1e1 commit 108c237
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@
"html_options_other_enable_sync_tooltip_line1b": { "message": "logged in with the same profile." },
"html_options_other_enable_sync_tooltip_line2": { "message": "This will also synchronise settings in incognito mode." },
"html_options_other_enable_sync_warning": { "message": "Turning this on will overwrite settings on all other browsers logged into the same Chrome profile" },
"html_options_tracking_opt_out": { "message": "Automatic deactivation of any kind of tracking" },
"html_options_tracking_opt_out_line1": { "message": "This option will disable tracking code, such as that from Google Analytics." },
"html_options_suspend_on_low_memory": { "message": "Instantly suspend when system memory gets very low" },
"html_options_suspend_on_low_memory_tooltip_line1": { "message": "This option will override Chrome's automatic tab discarding functionality." },
"html_options_suspend_on_low_memory_tooltip_line2": { "message": "If enabled, it will force a tab to suspend instead of being discarded by Chrome." },
Expand Down
92 changes: 81 additions & 11 deletions src/js/gsAnalytics.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*global ga, gsStorage, gsSession, gsUtils */
// eslint-disable-next-line no-unused-vars
var gsAnalytics = (function() {
var gsAnalytics = function() {
'use strict';

const DIMENSION_VERSION = 'dimension1';
Expand All @@ -16,6 +16,13 @@ var gsAnalytics = (function() {

function initAsPromised() {
return new Promise(function(resolve) {
if (gsStorage.getOption('trackingOptOut')) {
gsUtils.log(
'gsAnalytics',
'init tracking aborted because tracking is disabled'
);
resolve();
}
try {
ga('create', 'UA-167314577-2', 'auto');
ga('set', 'checkProtocolTask', function() {});
Expand All @@ -29,6 +36,13 @@ var gsAnalytics = (function() {
}

function setUserDimensions() {
if (gsStorage.getOption('trackingOptOut')) {
gsUtils.log(
'gsAnalytics',
'setting dimensions aborted because tracking is disabled'
);
return;
}
const dimensions = {
[DIMENSION_VERSION]: chrome.runtime.getManifest().version + '',
[DIMENSION_SCREEN_CAPTURE]:
Expand All @@ -44,6 +58,13 @@ var gsAnalytics = (function() {
}

function performStartupReport() {
if (gsStorage.getOption('trackingOptOut')) {
gsUtils.log(
'gsAnalytics',
'perfomStartupReport aborted because tracking is disabled'
);
return;
}
const category = 'System';
const action = gsSession.getStartupType();

Expand All @@ -68,6 +89,13 @@ var gsAnalytics = (function() {
}

function performVersionReport() {
if (gsStorage.getOption('trackingOptOut')) {
gsUtils.log(
'gsAnalytics',
'performVersionReport aborted because tracking is disabled'
);
return;
}
const startupType = gsSession.getStartupType();
if (!['Install', 'Update'].includes(startupType)) {
return;
Expand All @@ -87,6 +115,13 @@ var gsAnalytics = (function() {
}

function performPingReport() {
if (gsStorage.getOption('trackingOptOut')) {
gsUtils.log(
'gsAnalytics',
'performPingReport aborted because tracking is disabled'
);
return;
}
const category = 'System';
const action = 'Ping';

Expand All @@ -103,18 +138,38 @@ var gsAnalytics = (function() {
}

function reportPageView(pageName) {
if (gsStorage.getOption('trackingOptOut')) {
gsUtils.log(
'gsAnalytics',
'reportPageView aborted because tracking is disabled'
);
return;
}
ga('send', 'pageview', pageName);
}
function reportEvent(category, action, label) {
if (gsStorage.getOption('trackingOptOut')) {
gsUtils.log(
'gsAnalytics',
'reportEvent aborted because tracking is disabled'
);
return;
}
ga('send', 'event', category, action, label);
}
function reportException(errorMessage) {
if (gsStorage.getOption('trackingOptOut')) {
gsUtils.log(
'gsAnalytics',
'reportException aborted because tracking is disabled'
);
return;
}
ga('send', 'exception', {
exDescription: errorMessage,
exFatal: false,
});
}

return {
initAsPromised,
performStartupReport,
Expand All @@ -125,9 +180,9 @@ var gsAnalytics = (function() {
reportEvent,
reportException,
};
})();
};

(function(i, s, o, g, r, a, m) {
function loadGoogleAnalytics(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
(i[r] =
i[r] ||
Expand All @@ -139,10 +194,25 @@ var gsAnalytics = (function() {
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m);
})(
window,
document,
'script',
'https://www.google-analytics.com/analytics.js',
'ga'
);
}

function init() {
if (!gsStorage.getOption('trackingOptOut')) {
loadGoogleAnalytics(
window,
document,
'script',
'https://www.google-analytics.com/analytics.js',
'ga'
);
}
gsAnalytics = gsAnalytics();
}

if (document.readyState == 'complete') {
init();
} else {
document.addEventListener('DOMContentLoaded', function() {
init();
});
}
4 changes: 3 additions & 1 deletion src/js/gsStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const gsStorageSettings = {
DISCARD_AFTER_SUSPEND: 'discardAfterSuspend',
DISCARD_IN_PLACE_OF_SUSPEND: 'discardInPlaceOfSuspend',
USE_ALT_SCREEN_CAPTURE_LIB: 'useAlternateScreenCaptureLib',
ENABLE_CLEAN_SCREENCAPS: 'cleanScreencaps',
TRACKING_OPT_OUT: 'trackingOptOut',
ENABLE_CLEAN_SCREENCAPS: 'cleanScreencaps'
};

var gsStorage = {
Expand Down Expand Up @@ -65,6 +66,7 @@ var gsStorage = {
defaults[gsStorage.NO_NAG] = false;
defaults[gsStorage.WHITELIST] = '';
defaults[gsStorage.THEME] = 'light';
defaults[gsStorage.TRACKING_OPT_OUT] = false;
defaults[gsStorage.ENABLE_CLEAN_SCREENCAPS] = false;

return defaults;
Expand Down
1 change: 1 addition & 0 deletions src/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
timeToSuspend: gsStorage.SUSPEND_TIME,
theme: gsStorage.THEME,
whitelist: gsStorage.WHITELIST,
trackingOptOut: gsStorage.TRACKING_OPT_OUT
};

function selectComboBox(element, key) {
Expand Down
7 changes: 7 additions & 0 deletions src/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ <h2 data-i18n="__MSG_html_options_other_title__"></h2>
<i class="tooltipIcon icon icon-help-circled"></i>
</span>
</div>
<div class="formRow">
<input type="checkbox" id="trackingOptOut" class='option' />
<label for="trackingOptOut" class="cbLabel" data-i18n="__MSG_html_options_tracking_opt_out__"></label>
<span data-i18n-tooltip="__MSG_html_options_tracking_opt_out_line1__">
<i class="tooltipIcon icon icon-help-circled"></i>
</span>
</div>
</div>
</div>

Expand Down

0 comments on commit 108c237

Please sign in to comment.