A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
fix: analytics not working on desktop app
thecodrr3a8d25a240ee
diff --git a/apps/web/public/index.html b/apps/web/public/index.htmlindex 218a2000d..798588c2c 100644--- a/apps/web/public/index.html+++ b/apps/web/public/index.html@@ -199,14 +199,5 @@box-sizing: content-box;"></div>- <script- async- defer- data-website-id="f16c07d9-c77b-4781-bfbd-f58e95640002"- src="https://analytics.streetwriters.co/umami.js"- data-domains="app.notesnook.com"- data-auto-track="false"- data-do-not-track="true"- ></script></body></html>diff --git a/apps/web/src/components/banner/index.js b/apps/web/src/components/banner/index.jsindex 5a8a52dc5..a0fa927d5 100644--- a/apps/web/src/components/banner/index.js+++ b/apps/web/src/components/banner/index.js@@ -1,9 +1,10 @@import React, { useMemo } from "react";import { Flex, Text } from "rebass";+import { getPlatform } from "../../utils/platform";function Banner() {const link = useMemo(() => {- const os = getOS();+ const os = getPlatform();if (os === "Android")return "https://play.google.com/store/apps/details?id=com.streetwriters.notesnook";if (os === "iOS")@@ -20,26 +21,3 @@ function Banner() {);}export default Banner;--function getOS() {- var userAgent = window.navigator.userAgent,- platform = window.navigator.platform,- macosPlatforms = ["Macintosh", "MacIntel", "MacPPC", "Mac68K"],- windowsPlatforms = ["Win32", "Win64", "Windows", "WinCE"],- iosPlatforms = ["iPhone", "iPad", "iPod"],- os = null;-- if (macosPlatforms.indexOf(platform) !== -1) {- os = "Mac OS";- } else if (iosPlatforms.indexOf(platform) !== -1) {- os = "iOS";- } else if (windowsPlatforms.indexOf(platform) !== -1) {- os = "Windows";- } else if (/Android/.test(userAgent)) {- os = "Android";- } else if (!os && /Linux/.test(platform)) {- os = "Linux";- }-- return os;-}diff --git a/apps/web/src/index.js b/apps/web/src/index.jsindex 9b5e28b8b..18073bb15 100644--- a/apps/web/src/index.js+++ b/apps/web/src/index.js@@ -2,18 +2,19 @@ import React from "react";import { initializeDatabase } from "./common/db";import "./index.css";import * as serviceWorker from "./serviceWorkerRegistration";-import { trackVisit } from "./utils/analytics";+import { loadTrackerScript } from "./utils/analytics";if (process.env.NODE_ENV === "production") {+ loadTrackerScript();console.log = () => {};}initializeDatabase().then(() => {import("react-dom").then(({ render }) => {import("./App").then(({ default: App }) => {- render(<App />, document.getElementById("root"), () => {+ render(<App />, document.getElementById("root"), async () => {document.getElementById("splash").remove();- trackVisit();+import("react-modal").then(({ default: Modal }) => {Modal.setAppElement("#root");});diff --git a/apps/web/src/utils/analytics.js b/apps/web/src/utils/analytics.jsindex f6adb5925..7dd60e87e 100644--- a/apps/web/src/utils/analytics.js+++ b/apps/web/src/utils/analytics.js@@ -1,6 +1,25 @@import Config from "./config";+import { getPlatform } from "./platform";import { getAppVersion } from "./useVersion";+export function loadTrackerScript() {+ if (Config.get("telemetry") === "false") return;+ var script = document.createElement("script");+ script.src = "https://analytics.streetwriters.co/umami.js";+ script.async = true;+ script.dataset.websiteId = "f16c07d9-c77b-4781-bfbd-f58e95640002";++ if (process.env.REACT_APP_PLATFORM !== "desktop")+ script.dataset.domains = "app.notesnook.com";+ script.dataset.autoTrack = "false";+ script.dataset.doNotTrack = "true";+ var firstScriptElement = document.getElementsByTagName("script")[0];+ script.onload = function () {+ trackVisit();+ };+ firstScriptElement.parentNode.insertBefore(script, firstScriptElement);+}+export function trackEvent(eventName, eventType) {if (Config.get("telemetry") === "false") return;if (window.umami) {@@ -11,7 +30,9 @@ export function trackEvent(eventName, eventType) {export function trackVisit() {if (Config.get("telemetry") === "false") return;if (window.umami) {- window.umami.trackView("/");- trackEvent(getAppVersion().formatted, "version");+ trackEvent(+ `${getAppVersion().formatted}-${getPlatform().toLowerCase()}`,+ "version"+ );}}diff --git a/apps/web/src/utils/platform.js b/apps/web/src/utils/platform.jsnew file mode 100644index 000000000..cb713075f--- /dev/null+++ b/apps/web/src/utils/platform.js@@ -0,0 +1,22 @@+export function getPlatform() {+ var userAgent = window.navigator.userAgent,+ platform = window.navigator.platform,+ macosPlatforms = ["Macintosh", "MacIntel", "MacPPC", "Mac68K"],+ windowsPlatforms = ["Win32", "Win64", "Windows", "WinCE"],+ iosPlatforms = ["iPhone", "iPad", "iPod"],+ os = null;++ if (macosPlatforms.indexOf(platform) !== -1) {+ os = "Mac OS";+ } else if (iosPlatforms.indexOf(platform) !== -1) {+ os = "iOS";+ } else if (windowsPlatforms.indexOf(platform) !== -1) {+ os = "Windows";+ } else if (/Android/.test(userAgent)) {+ os = "Android";+ } else if (!os && /Linux/.test(platform)) {+ os = "Linux";+ }++ return os;+}