Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: track sign ups

thecodrrfc3a83f25ee4
diff --git a/apps/web/src/utils/analytics.js b/apps/web/src/utils/analytics.ts
similarity index 66%
rename from apps/web/src/utils/analytics.js
rename to apps/web/src/utils/analytics.ts
index 29f25f39c..ba0c52a84 100644
--- a/apps/web/src/utils/analytics.js
+++ b/apps/web/src/utils/analytics.ts
@@ -2,6 +2,20 @@ import Config from "./config";
import { getPlatform } from "./platform";
import { appVersion } from "./version";
+declare global {
+ interface Window {
+ umami?: {
+ trackEvent: (
+ value: string,
+ type: string,
+ url?: string,
+ websiteId?: string
+ ) => void;
+ trackView: (url: string, referrer?: string, websiteId?: string) => void;
+ };
+ }
+}
+
export function loadTrackerScript() {
if (Config.get("telemetry") === "false") return;
var script = document.createElement("script");
@@ -18,9 +32,15 @@ export function loadTrackerScript() {
script.onload = function () {
trackVisit();
};
- firstScriptElement.parentNode.insertBefore(script, firstScriptElement);
+ firstScriptElement.parentNode?.insertBefore(script, firstScriptElement);
}
+type TrackerEvent = {
+ name: string;
+ description: string;
+ type?: "event" | "view";
+};
+
export const ANALYTICS_EVENTS = {
version: {
name: "version",
@@ -53,22 +73,30 @@ export const ANALYTICS_EVENTS = {
name: "announcement:cta",
description: "Sent whenever you an announcement CTA is invoked.",
},
-};
+ accountCreated: {
+ name: "/account/created",
+ description: "Sent when you create an account.",
+ type: "view",
+ },
+} as const;
-export function trackEvent(event, eventMessage) {
+export function trackEvent(event: TrackerEvent, eventMessage?: string) {
if (Config.get("telemetry") === "false") return;
- if (window.umami) {
+ if (!window.umami) return;
+ if (event.type === "event" && eventMessage)
window.umami.trackEvent(eventMessage, event.name);
- }
+ else trackVisit(event.name);
}
-export function trackVisit() {
+export function trackVisit(url: string = "/") {
if (Config.get("telemetry") === "false") return;
- if (window.umami) {
- window.umami.trackView("/");
+ const platform = getPlatform();
+ if (!window.umami || !platform) return;
+
+ window.umami.trackView(url);
+ if (url === "/")
trackEvent(
ANALYTICS_EVENTS.version,
- `${appVersion.formatted}-${getPlatform().toLowerCase()}`
+ `${appVersion.formatted}-${platform.toLowerCase()}`
);
- }
}
diff --git a/apps/web/src/views/auth.tsx b/apps/web/src/views/auth.tsx
index 22fa4d741..c602930f8 100644
--- a/apps/web/src/views/auth.tsx
+++ b/apps/web/src/views/auth.tsx
@@ -24,6 +24,7 @@ import { isTesting } from "../utils/platform";
import { AuthenticatorType } from "../components/dialogs/multi-factor-dialog";
import { RequestError } from "notes-core/utils/http";
import { useTimer } from "../hooks/use-timer";
+import { ANALYTICS_EVENTS, trackEvent } from "../utils/analytics";
type LoginFormData = {
email: string;
@@ -276,6 +277,7 @@ function Signup(props: BaseAuthComponentProps<"signup">) {
}
await userstore.signup(form);
+ trackEvent(ANALYTICS_EVENTS.accountCreated);
openURL("/notes/#/welcome");
}}
>