Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ node_modules

# Parcel build cache
.parcel-cache/

# dotenv
.env
27 changes: 26 additions & 1 deletion js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,37 @@ export const startElmApp = (mainModule) => {
app.ports.sendAnalyticsEvent.subscribe((event) => {
const { category, action, label, value, ...others } = JSON.parse(event);
console.debug({ category, action, label, value, others });
if (gtag) {
if (gtag) { // Google Analytics
const data = Object.assign({
"event_category": category,
"event_label": label
}, value ? { value } : {});
gtag("event", action, Object.assign({}, data, others));
}

// Send timer settings to my analytics on timer start.
if (`${import.meta.env.VITE_SURVEY_URL}` !== "" && action === "sync_timer_start") {
Comment on lines +55 to +56
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add user consent mechanism for data collection

The code collects user settings and host information without explicit user consent, which may violate privacy regulations (GDPR, CCPA).

Consider implementing:

  1. A consent management system
  2. Clear user notification about data collection
  3. Option to opt-out of analytics

const params = new URLSearchParams({
host: document.location.host,
fg: others.setting_fgColor || "",
bg: others.setting_bgColor || "",
ff: others.setting_fgFont || "",
init: others.setting_initial || "",
h: others.setting_show_hours || "",
p: others.setting_show_progress || "",
});

fetch(`${import.meta.env.VITE_SURVEY_URL}?${params.toString()}`).then((res) => {
if (res.ok) {
console.debug("Survey request sent.");
} else {
console.log("Survey request failed.");
}
}).catch((err) => {
console.log("Survey request failed.", err);
})
}
Comment on lines +67 to +76
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve error handling and URL validation

Several issues need attention:

  1. Console.log statements in production code
  2. No validation of VITE_SURVEY_URL
  3. Basic error handling
+    const surveyUrl = import.meta.env.VITE_SURVEY_URL;
+    if (!surveyUrl || !surveyUrl.startsWith('https://')) {
+      console.error('Invalid survey URL configuration');
+      return;
+    }
-    fetch(`${import.meta.env.VITE_SURVEY_URL}?${params.toString()}`).then((res) => {
+    fetch(`${surveyUrl}?${params.toString()}`).then((res) => {
       if (res.ok) {
-        console.debug("Survey request sent.");
+        // Success case - consider adding metrics instead of console logs
       } else {
-        console.log("Survey request failed.");
+        // Use proper error tracking service
+        throw new Error(`Survey request failed: ${res.status}`);
       }
     }).catch((err) => {
-      console.log("Survey request failed.", err);
+      // Use proper error tracking service
+      reportError('Survey request failed', err);
     })

});


}
Loading