فهرست منبع

feat: testing simple analytics and fathom analytics for better privacy of the users (#6529)

Co-authored-by: dwelle <[email protected]>
Milos Vetesnik 2 سال پیش
والد
کامیت
6b0218b012
3فایلهای تغییر یافته به همراه36 افزوده شده و 30 حذف شده
  1. 20 25
      public/index.html
  2. 14 3
      src/analytics.ts
  3. 2 2
      src/global.d.ts

+ 20 - 25
public/index.html

@@ -150,6 +150,14 @@
     </script>
     </script>
     <% if (process.env.REACT_APP_DISABLE_TRACKING !== 'true') { %>
     <% if (process.env.REACT_APP_DISABLE_TRACKING !== 'true') { %>
 
 
+    <!-- Fathom - privacy-friendly analytics -->
+    <script
+      src="https://cdn.usefathom.com/script.js"
+      data-site="VMSBUEYA"
+      defer
+    ></script>
+    <!-- / Fathom -->
+
     <!-- LEGACY GOOGLE ANALYTICS -->
     <!-- LEGACY GOOGLE ANALYTICS -->
     <% if (process.env.REACT_APP_GOOGLE_ANALYTICS_ID) { %>
     <% if (process.env.REACT_APP_GOOGLE_ANALYTICS_ID) { %>
     <script
     <script
@@ -166,31 +174,6 @@
     </script>
     </script>
     <% } %>
     <% } %>
     <!-- end LEGACY GOOGLE ANALYTICS -->
     <!-- end LEGACY GOOGLE ANALYTICS -->
-
-    <!-- Matomo -->
-    <% if (process.env.REACT_APP_MATOMO_URL &&
-    process.env.REACT_APP_MATOMO_SITE_ID &&
-    process.env.REACT_APP_CDN_MATOMO_TRACKER_URL) { %>
-    <script>
-      var _paq = (window._paq = window._paq || []);
-      /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
-      _paq.push(["trackPageView"]);
-      _paq.push(["enableLinkTracking"]);
-      (function () {
-        var u = "%REACT_APP_MATOMO_URL%";
-        _paq.push(["setTrackerUrl", u + "matomo.php"]);
-        _paq.push(["setSiteId", "%REACT_APP_MATOMO_SITE_ID%"]);
-        var d = document,
-          g = d.createElement("script"),
-          s = d.getElementsByTagName("script")[0];
-        g.async = true;
-        g.src = "%REACT_APP_CDN_MATOMO_TRACKER_URL%";
-        s.parentNode.insertBefore(g, s);
-      })();
-    </script>
-    <% } %>
-    <!-- end Matomo analytics -->
-
     <% } %>
     <% } %>
 
 
     <!-- FIXME: remove this when we update CRA (fix SW caching) -->
     <!-- FIXME: remove this when we update CRA (fix SW caching) -->
@@ -244,5 +227,17 @@
       <h1 class="visually-hidden">Excalidraw</h1>
       <h1 class="visually-hidden">Excalidraw</h1>
     </header>
     </header>
     <div id="root"></div>
     <div id="root"></div>
+    <!-- 100% privacy friendly analytics -->
+    <script
+      async
+      defer
+      src="https://scripts.simpleanalyticscdn.com/latest.js"
+    ></script>
+    <noscript
+      ><img
+        src="https://queue.simpleanalyticscdn.com/noscript.gif"
+        alt=""
+        referrerpolicy="no-referrer-when-downgrade"
+    /></noscript>
   </body>
   </body>
 </html>
 </html>

+ 14 - 3
src/analytics.ts

@@ -20,9 +20,20 @@ export const trackEvent = (
       });
       });
     }
     }
 
 
-    // MATOMO event tracking _paq must be same as the one in index.html
-    if (window._paq) {
-      window._paq.push(["trackEvent", category, action, label, value]);
+    if (window.sa_event) {
+      window.sa_event(action, {
+        category,
+        label,
+        value,
+      });
+    }
+
+    if (window.fathom) {
+      window.fathom.trackEvent(action, {
+        category,
+        label,
+        value,
+      });
     }
     }
   } catch (error) {
   } catch (error) {
     console.error("error during analytics", error);
     console.error("error during analytics", error);

+ 2 - 2
src/global.d.ts

@@ -18,8 +18,8 @@ interface Window {
   EXCALIDRAW_EXPORT_SOURCE: string;
   EXCALIDRAW_EXPORT_SOURCE: string;
   EXCALIDRAW_THROTTLE_RENDER: boolean | undefined;
   EXCALIDRAW_THROTTLE_RENDER: boolean | undefined;
   gtag: Function;
   gtag: Function;
-  _paq: any[];
-  _mtm: any[];
+  sa_event: Function;
+  fathom: { trackEvent: Function };
 }
 }
 
 
 interface CanvasRenderingContext2D {
 interface CanvasRenderingContext2D {