From 771ab8259844a908f0f22256a1ac90b3055fc47f Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 16 Sep 2020 10:29:21 +0100 Subject: [PATCH 1/4] Hide Analytics sections if piwik config is not provided --- src/Analytics.js | 8 +++- src/components/structures/MatrixChat.tsx | 4 +- .../tabs/user/SecurityUserSettingsTab.js | 38 ++++++++++--------- src/i18n/strings/en_EN.json | 6 +-- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/Analytics.js b/src/Analytics.js index 9966d0845e..135cc2eb7a 100644 --- a/src/Analytics.js +++ b/src/Analytics.js @@ -170,15 +170,19 @@ class Analytics { return !this.baseUrl; } + canEnable() { + const config = SdkConfig.get(); + return navigator.doNotTrack !== "1" && config && config.piwik && config.piwik.url && config.piwik.siteId; + } + /** * Enable Analytics if initialized but disabled * otherwise try and initalize, no-op if piwik config missing */ async enable() { if (!this.disabled) return; - + if (!this.canEnable()) return; const config = SdkConfig.get(); - if (!config || !config.piwik || !config.piwik.url || !config.piwik.siteId) return; this.baseUrl = new URL("piwik.php", config.piwik.url); // set constants diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index 4cdb58014e..9dfac86d63 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -1214,8 +1214,8 @@ export default class MatrixChat extends React.PureComponent { StorageManager.tryPersistStorage(); - if (SettingsStore.getValue("showCookieBar") && this.props.config.piwik && navigator.doNotTrack !== "1") { - showAnalyticsToast(this.props.config.piwik && this.props.config.piwik.policyUrl); + if (SettingsStore.getValue("showCookieBar") && Analytics.canEnable()) { + showAnalyticsToast(this.props.config.piwik?.policyUrl); } } diff --git a/src/components/views/settings/tabs/user/SecurityUserSettingsTab.js b/src/components/views/settings/tabs/user/SecurityUserSettingsTab.js index c25ac438e0..03093d2dca 100644 --- a/src/components/views/settings/tabs/user/SecurityUserSettingsTab.js +++ b/src/components/views/settings/tabs/user/SecurityUserSettingsTab.js @@ -329,6 +329,26 @@ export default class SecurityUserSettingsTab extends React.Component { ; } + let analyticsSection; + if (Analytics.canEnable()) { + analyticsSection =
+ {_t("Analytics")} +
+ {_t( + "%(brand)s collects anonymous analytics to allow us to improve the application.", + { brand }, + )} +   + {_t("Privacy is important to us, so we don't collect any personal or " + + "identifiable data for our analytics.")} + + {_t("Learn more about how we use analytics.")} + +
+ +
; + } + return (
{warning} @@ -358,23 +378,7 @@ export default class SecurityUserSettingsTab extends React.Component { {this._renderCurrentDeviceInfo()}
{_t("Privacy")}
-
- {_t("Analytics")} -
- {_t( - "%(brand)s collects anonymous analytics to allow us to improve the application.", - { brand }, - )} -   - {_t("Privacy is important to us, so we don't collect any personal or " + - "identifiable data for our analytics.")} - - {_t("Learn more about how we use analytics.")} - -
- -
+ { analyticsSection }
{_t("Advanced")}
{this._renderIgnoredUsers()} diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 4414077005..070cf7e597 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -912,13 +912,13 @@ "Message search": "Message search", "Cross-signing": "Cross-signing", "Your server admin has disabled end-to-end encryption by default in private rooms & Direct Messages.": "Your server admin has disabled end-to-end encryption by default in private rooms & Direct Messages.", + "%(brand)s collects anonymous analytics to allow us to improve the application.": "%(brand)s collects anonymous analytics to allow us to improve the application.", + "Privacy is important to us, so we don't collect any personal or identifiable data for our analytics.": "Privacy is important to us, so we don't collect any personal or identifiable data for our analytics.", + "Learn more about how we use analytics.": "Learn more about how we use analytics.", "Where you’re logged in": "Where you’re logged in", "Manage the names of and sign out of your sessions below or verify them in your User Profile.": "Manage the names of and sign out of your sessions below or verify them in your User Profile.", "A session's public name is visible to people you communicate with": "A session's public name is visible to people you communicate with", "Privacy": "Privacy", - "%(brand)s collects anonymous analytics to allow us to improve the application.": "%(brand)s collects anonymous analytics to allow us to improve the application.", - "Privacy is important to us, so we don't collect any personal or identifiable data for our analytics.": "Privacy is important to us, so we don't collect any personal or identifiable data for our analytics.", - "Learn more about how we use analytics.": "Learn more about how we use analytics.", "No media permissions": "No media permissions", "You may need to manually permit %(brand)s to access your microphone/webcam": "You may need to manually permit %(brand)s to access your microphone/webcam", "Missing media permissions, click the button below to request.": "Missing media permissions, click the button below to request.", From d9909864071985f884189aba751755b5ca7cb89f Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 16 Sep 2020 10:37:15 +0100 Subject: [PATCH 2/4] Also hide Privacy heading in settings and fix React Key warning --- .../views/settings/SecureBackupPanel.js | 8 ++-- .../tabs/user/SecurityUserSettingsTab.js | 38 ++++++++++--------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/components/views/settings/SecureBackupPanel.js b/src/components/views/settings/SecureBackupPanel.js index 7f0655d54a..c058e27de7 100644 --- a/src/components/views/settings/SecureBackupPanel.js +++ b/src/components/views/settings/SecureBackupPanel.js @@ -367,14 +367,14 @@ export default class SecureBackupPanel extends React.PureComponent { ; actions.push( - + {restoreButtonCaption} , ); if (!isSecureBackupRequired()) { actions.push( - + {_t("Delete Backup")} , ); @@ -388,7 +388,7 @@ export default class SecureBackupPanel extends React.PureComponent {

{_t("Back up your keys before signing out to avoid losing them.")}

; actions.push( - + {_t("Set up")} , ); @@ -396,7 +396,7 @@ export default class SecureBackupPanel extends React.PureComponent { if (secretStorageKeyInAccount) { actions.push( - + {_t("Reset")} , ); diff --git a/src/components/views/settings/tabs/user/SecurityUserSettingsTab.js b/src/components/views/settings/tabs/user/SecurityUserSettingsTab.js index 03093d2dca..0c49f108d6 100644 --- a/src/components/views/settings/tabs/user/SecurityUserSettingsTab.js +++ b/src/components/views/settings/tabs/user/SecurityUserSettingsTab.js @@ -329,24 +329,27 @@ export default class SecurityUserSettingsTab extends React.Component {
; } - let analyticsSection; + let privacySection; if (Analytics.canEnable()) { - analyticsSection =
- {_t("Analytics")} -
- {_t( - "%(brand)s collects anonymous analytics to allow us to improve the application.", - { brand }, - )} -   - {_t("Privacy is important to us, so we don't collect any personal or " + - "identifiable data for our analytics.")} - - {_t("Learn more about how we use analytics.")} - + privacySection = +
{_t("Privacy")}
+
+ {_t("Analytics")} +
+ {_t( + "%(brand)s collects anonymous analytics to allow us to improve the application.", + { brand }, + )} +   + {_t("Privacy is important to us, so we don't collect any personal or " + + "identifiable data for our analytics.")} + + {_t("Learn more about how we use analytics.")} + +
+
- -
; + ; } return ( @@ -377,8 +380,7 @@ export default class SecurityUserSettingsTab extends React.Component { {crossSigning} {this._renderCurrentDeviceInfo()}
-
{_t("Privacy")}
- { analyticsSection } + { privacySection }
{_t("Advanced")}
{this._renderIgnoredUsers()} From 93323febcba986cee7fbead49de882fd17b4c72b Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 16 Sep 2020 16:10:24 +0100 Subject: [PATCH 3/4] undo change --- src/components/views/settings/SecureBackupPanel.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/views/settings/SecureBackupPanel.js b/src/components/views/settings/SecureBackupPanel.js index c058e27de7..7f0655d54a 100644 --- a/src/components/views/settings/SecureBackupPanel.js +++ b/src/components/views/settings/SecureBackupPanel.js @@ -367,14 +367,14 @@ export default class SecureBackupPanel extends React.PureComponent { ; actions.push( - + {restoreButtonCaption} , ); if (!isSecureBackupRequired()) { actions.push( - + {_t("Delete Backup")} , ); @@ -388,7 +388,7 @@ export default class SecureBackupPanel extends React.PureComponent {

{_t("Back up your keys before signing out to avoid losing them.")}

; actions.push( - + {_t("Set up")} , ); @@ -396,7 +396,7 @@ export default class SecureBackupPanel extends React.PureComponent { if (secretStorageKeyInAccount) { actions.push( - + {_t("Reset")} , ); From 9be04f8a67790a6a849c213aa1a9b696f1a0fa59 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 16 Sep 2020 16:10:43 +0100 Subject: [PATCH 4/4] i18n --- src/i18n/strings/en_EN.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 070cf7e597..e8803ddc32 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -912,13 +912,13 @@ "Message search": "Message search", "Cross-signing": "Cross-signing", "Your server admin has disabled end-to-end encryption by default in private rooms & Direct Messages.": "Your server admin has disabled end-to-end encryption by default in private rooms & Direct Messages.", + "Privacy": "Privacy", "%(brand)s collects anonymous analytics to allow us to improve the application.": "%(brand)s collects anonymous analytics to allow us to improve the application.", "Privacy is important to us, so we don't collect any personal or identifiable data for our analytics.": "Privacy is important to us, so we don't collect any personal or identifiable data for our analytics.", "Learn more about how we use analytics.": "Learn more about how we use analytics.", "Where you’re logged in": "Where you’re logged in", "Manage the names of and sign out of your sessions below or verify them in your User Profile.": "Manage the names of and sign out of your sessions below or verify them in your User Profile.", "A session's public name is visible to people you communicate with": "A session's public name is visible to people you communicate with", - "Privacy": "Privacy", "No media permissions": "No media permissions", "You may need to manually permit %(brand)s to access your microphone/webcam": "You may need to manually permit %(brand)s to access your microphone/webcam", "Missing media permissions, click the button below to request.": "Missing media permissions, click the button below to request.",