Skip to content

Commit

Permalink
feat: testing simple analytics and fathom analytics for better privac…
Browse files Browse the repository at this point in the history
…y of the users (excalidraw#6529)

Co-authored-by: dwelle <[email protected]>
  • Loading branch information
maielo and dwelle authored Apr 27, 2023
1 parent 45a57d7 commit 6b0218b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 30 deletions.
45 changes: 20 additions & 25 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@
</script>
<% 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 -->
<% if (process.env.REACT_APP_GOOGLE_ANALYTICS_ID) { %>
<script
Expand All @@ -166,31 +174,6 @@
</script>
<% } %>
<!-- 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) -->
Expand Down Expand Up @@ -244,5 +227,17 @@
<h1 class="visually-hidden">Excalidraw</h1>
</header>
<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>
</html>
17 changes: 14 additions & 3 deletions src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
console.error("error during analytics", error);
Expand Down
4 changes: 2 additions & 2 deletions src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ interface Window {
EXCALIDRAW_EXPORT_SOURCE: string;
EXCALIDRAW_THROTTLE_RENDER: boolean | undefined;
gtag: Function;
_paq: any[];
_mtm: any[];
sa_event: Function;
fathom: { trackEvent: Function };
}

interface CanvasRenderingContext2D {
Expand Down

0 comments on commit 6b0218b

Please sign in to comment.