From ba2e5ca873ae14a08280c41321cfa4c0380e2f18 Mon Sep 17 00:00:00 2001 From: thegreatsuspender Date: Thu, 24 Sep 2020 10:32:37 +0200 Subject: [PATCH 1/7] added option to disable tracking --- src/_locales/en/messages.json | 1 + src/js/gsAnalytics.js | 63 +++++++++++++++++++++++++++++------ src/js/gsStorage.js | 4 ++- src/js/options.js | 1 + src/options.html | 4 +++ 5 files changed, 62 insertions(+), 11 deletions(-) diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 6ddfeb7c..d699154c 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -113,6 +113,7 @@ "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": "Disable all tracking"}, "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." }, diff --git a/src/js/gsAnalytics.js b/src/js/gsAnalytics.js index 1615526c..5489806e 100644 --- a/src/js/gsAnalytics.js +++ b/src/js/gsAnalytics.js @@ -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'; @@ -16,6 +16,10 @@ 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() {}); @@ -29,6 +33,10 @@ 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]: @@ -44,6 +52,10 @@ 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(); @@ -68,6 +80,10 @@ 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; @@ -87,6 +103,10 @@ 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'; @@ -103,12 +123,24 @@ 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, @@ -125,9 +157,10 @@ var gsAnalytics = (function() { reportEvent, reportException, }; -})(); +}; -(function(i, s, o, g, r, a, m) { +function loadGoogleAnalytics(i, s, o, g, r, a, m) { + //TODO this code seems to not get executed at all?!? i['GoogleAnalyticsObject'] = r; (i[r] = i[r] || @@ -139,10 +172,20 @@ 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() +} + +document.addEventListener("DOMContentLoaded", function() { + init() +}); + +if(document.readyState == "complete") { + init() +} \ No newline at end of file diff --git a/src/js/gsStorage.js b/src/js/gsStorage.js index 3a7cda8f..5188bca0 100755 --- a/src/js/gsStorage.js +++ b/src/js/gsStorage.js @@ -25,7 +25,8 @@ const gsStorageSettings = { DISCARD_AFTER_SUSPEND: 'discardAfterSuspend', DISCARD_IN_PLACE_OF_SUSPEND: 'discardInPlaceOfSuspend', - USE_ALT_SCREEN_CAPTURE_LIB: 'useAlternateScreenCaptureLib' + USE_ALT_SCREEN_CAPTURE_LIB: 'useAlternateScreenCaptureLib', + TRACKING_OPT_OUT: 'trackingOptOut' }; var gsStorage = { @@ -64,6 +65,7 @@ var gsStorage = { defaults[gsStorage.NO_NAG] = false; defaults[gsStorage.WHITELIST] = ''; defaults[gsStorage.THEME] = 'light'; + defaults[gsStorage.TRACKING_OPT_OUT] = true return defaults; }, diff --git a/src/js/options.js b/src/js/options.js index a4445a65..551c76a6 100644 --- a/src/js/options.js +++ b/src/js/options.js @@ -25,6 +25,7 @@ timeToSuspend: gsStorage.SUSPEND_TIME, theme: gsStorage.THEME, whitelist: gsStorage.WHITELIST, + trackingOptOut: gsStorage.TRACKING_OPT_OUT }; function selectComboBox(element, key) { diff --git a/src/options.html b/src/options.html index 717335a3..e469b1e6 100644 --- a/src/options.html +++ b/src/options.html @@ -226,6 +226,10 @@

+
+ + +
From a959e2299ebb9cfd83f7f5221330328c448ae538 Mon Sep 17 00:00:00 2001 From: thegreatsuspender Date: Fri, 2 Oct 2020 11:19:08 +0200 Subject: [PATCH 2/7] changed description of disable tracking option --- src/_locales/en/messages.json | 3 ++- src/options.html | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index d699154c..59ac13f0 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -113,7 +113,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": "Disable all tracking"}, + "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." }, diff --git a/src/options.html b/src/options.html index e469b1e6..ffa0086b 100644 --- a/src/options.html +++ b/src/options.html @@ -229,6 +229,9 @@

+ + +
From b2db0265058e9ebab141d6c353c6b7a81e5b4cb6 Mon Sep 17 00:00:00 2001 From: thegreatsuspender Date: Mon, 5 Oct 2020 11:22:52 +0200 Subject: [PATCH 3/7] added semicolons & removed comment --- src/js/gsAnalytics.js | 97 +++++++++++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 35 deletions(-) diff --git a/src/js/gsAnalytics.js b/src/js/gsAnalytics.js index 5489806e..9a7e8ef2 100644 --- a/src/js/gsAnalytics.js +++ b/src/js/gsAnalytics.js @@ -16,9 +16,12 @@ 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() + if (gsStorage.getOption('trackingOptOut')) { + gsUtils.log( + 'gsAnalytics', + 'init tracking aborted because tracking is disabled' + ); + resolve(); } try { ga('create', 'UA-167314577-2', 'auto'); @@ -33,9 +36,12 @@ var gsAnalytics = function() { } function setUserDimensions() { - if(gsStorage.getOption("trackingOptOut")) { - gsUtils.log('gsAnalytics', 'setting dimensions aborted because tracking is disabled') - return + if (gsStorage.getOption('trackingOptOut')) { + gsUtils.log( + 'gsAnalytics', + 'setting dimensions aborted because tracking is disabled' + ); + return; } const dimensions = { [DIMENSION_VERSION]: chrome.runtime.getManifest().version + '', @@ -52,9 +58,12 @@ var gsAnalytics = function() { } function performStartupReport() { - if(gsStorage.getOption("trackingOptOut")) { - gsUtils.log('gsAnalytics', 'perfomStartupReport aborted because tracking is disabled') - return + if (gsStorage.getOption('trackingOptOut')) { + gsUtils.log( + 'gsAnalytics', + 'perfomStartupReport aborted because tracking is disabled' + ); + return; } const category = 'System'; const action = gsSession.getStartupType(); @@ -80,9 +89,12 @@ var gsAnalytics = function() { } function performVersionReport() { - if(gsStorage.getOption("trackingOptOut")) { - gsUtils.log('gsAnalytics', 'performVersionReport aborted because tracking is disabled') - return + if (gsStorage.getOption('trackingOptOut')) { + gsUtils.log( + 'gsAnalytics', + 'performVersionReport aborted because tracking is disabled' + ); + return; } const startupType = gsSession.getStartupType(); if (!['Install', 'Update'].includes(startupType)) { @@ -103,9 +115,12 @@ var gsAnalytics = function() { } function performPingReport() { - if(gsStorage.getOption("trackingOptOut")) { - gsUtils.log('gsAnalytics', 'performPingReport aborted because tracking is disabled') - return + if (gsStorage.getOption('trackingOptOut')) { + gsUtils.log( + 'gsAnalytics', + 'performPingReport aborted because tracking is disabled' + ); + return; } const category = 'System'; const action = 'Ping'; @@ -123,30 +138,38 @@ var gsAnalytics = function() { } function reportPageView(pageName) { - if(gsStorage.getOption("trackingOptOut")) { - gsUtils.log('gsAnalytics', 'reportPageView aborted because tracking is disabled') - return + 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 + 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 + if (gsStorage.getOption('trackingOptOut')) { + gsUtils.log( + 'gsAnalytics', + 'reportException aborted because tracking is disabled' + ); + return; } ga('send', 'exception', { exDescription: errorMessage, exFatal: false, }); } - return { initAsPromised, performStartupReport, @@ -160,7 +183,6 @@ var gsAnalytics = function() { }; function loadGoogleAnalytics(i, s, o, g, r, a, m) { - //TODO this code seems to not get executed at all?!? i['GoogleAnalyticsObject'] = r; (i[r] = i[r] || @@ -174,18 +196,23 @@ function loadGoogleAnalytics(i, s, o, g, r, a, m) { m.parentNode.insertBefore(a, m); } - function init() { - if(!gsStorage.getOption("trackingOptOut")) { - loadGoogleAnalytics(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga') + if (!gsStorage.getOption('trackingOptOut')) { + loadGoogleAnalytics( + window, + document, + 'script', + 'https://www.google-analytics.com/analytics.js', + 'ga' + ); } - gsAnalytics = gsAnalytics() + gsAnalytics = gsAnalytics(); } -document.addEventListener("DOMContentLoaded", function() { - init() +document.addEventListener('DOMContentLoaded', function() { + init(); }); -if(document.readyState == "complete") { - init() -} \ No newline at end of file +if (document.readyState == 'complete') { + init(); +} From c6a2bfdb1e5837c888952fc5b1554e0027363b4d Mon Sep 17 00:00:00 2001 From: thegreatsuspender Date: Mon, 5 Oct 2020 15:48:51 +0200 Subject: [PATCH 4/7] prevent double-initialization --- src/js/gsAnalytics.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/js/gsAnalytics.js b/src/js/gsAnalytics.js index 9a7e8ef2..2352dbf7 100644 --- a/src/js/gsAnalytics.js +++ b/src/js/gsAnalytics.js @@ -209,10 +209,10 @@ function init() { gsAnalytics = gsAnalytics(); } -document.addEventListener('DOMContentLoaded', function() { - init(); -}); - if (document.readyState == 'complete') { init(); +} else { + document.addEventListener('DOMContentLoaded', function() { + init(); + }); } From ca2d31191a812d6bbc60d4dddcd9ddb5a2e432b3 Mon Sep 17 00:00:00 2001 From: thegreatsuspender Date: Mon, 5 Oct 2020 15:49:08 +0200 Subject: [PATCH 5/7] removed pointless space --- src/js/gsStorage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/gsStorage.js b/src/js/gsStorage.js index 5188bca0..5fe72098 100755 --- a/src/js/gsStorage.js +++ b/src/js/gsStorage.js @@ -65,7 +65,7 @@ var gsStorage = { defaults[gsStorage.NO_NAG] = false; defaults[gsStorage.WHITELIST] = ''; defaults[gsStorage.THEME] = 'light'; - defaults[gsStorage.TRACKING_OPT_OUT] = true + defaults[gsStorage.TRACKING_OPT_OUT] = true return defaults; }, From 24372528836a7f9fb55ba09b1c8b6c3a87dc89b1 Mon Sep 17 00:00:00 2001 From: thegreatsuspender Date: Mon, 5 Oct 2020 15:49:32 +0200 Subject: [PATCH 6/7] removed useless space --- src/js/gsStorage.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/js/gsStorage.js b/src/js/gsStorage.js index 5fe72098..c4ea98ae 100755 --- a/src/js/gsStorage.js +++ b/src/js/gsStorage.js @@ -26,7 +26,7 @@ const gsStorageSettings = { DISCARD_AFTER_SUSPEND: 'discardAfterSuspend', DISCARD_IN_PLACE_OF_SUSPEND: 'discardInPlaceOfSuspend', USE_ALT_SCREEN_CAPTURE_LIB: 'useAlternateScreenCaptureLib', - TRACKING_OPT_OUT: 'trackingOptOut' + TRACKING_OPT_OUT: 'trackingOptOut', }; var gsStorage = { @@ -65,7 +65,7 @@ var gsStorage = { defaults[gsStorage.NO_NAG] = false; defaults[gsStorage.WHITELIST] = ''; defaults[gsStorage.THEME] = 'light'; - defaults[gsStorage.TRACKING_OPT_OUT] = true + defaults[gsStorage.TRACKING_OPT_OUT] = true; return defaults; }, @@ -182,14 +182,14 @@ var gsStorage = { * I did this because I think the key is easier to interpret for someone * editing the managed storage manually. */ - checkManagedStorageAndOverride() { + checkManagedStorageAndOverride() { const settingsList = Object.keys(gsStorageSettings); chrome.storage.managed.get(settingsList, result => { const settings = gsStorage.getSettings(); Object.keys(result).forEach(key => { - if (key === "WHITELIST") { - settings[gsStorage[key]] = result[key].replace(/[\s\n]+/g, "\n"); + if (key === 'WHITELIST') { + settings[gsStorage[key]] = result[key].replace(/[\s\n]+/g, '\n'); } else { settings[gsStorage[key]] = result[key]; } @@ -459,5 +459,5 @@ var gsStorage = { * * @param option The option name, such as "gsWhitelist" (not "WHITELIST") */ - isOptionManaged: option => managedOptions.includes(option) + isOptionManaged: option => managedOptions.includes(option), }; From 02304dbb66f2ffad5b7731cd671d02c8dedc04c2 Mon Sep 17 00:00:00 2001 From: thegreatsuspender Date: Fri, 9 Oct 2020 12:20:21 +0200 Subject: [PATCH 7/7] setting default value to false --- src/js/gsStorage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/gsStorage.js b/src/js/gsStorage.js index c4ea98ae..64c1d4be 100755 --- a/src/js/gsStorage.js +++ b/src/js/gsStorage.js @@ -65,7 +65,7 @@ var gsStorage = { defaults[gsStorage.NO_NAG] = false; defaults[gsStorage.WHITELIST] = ''; defaults[gsStorage.THEME] = 'light'; - defaults[gsStorage.TRACKING_OPT_OUT] = true; + defaults[gsStorage.TRACKING_OPT_OUT] = false; return defaults; },