mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
chore: Add tracking for hyperlinks (#4703)
* chore: Add tracking for hyperlinks * update * fix * remove * tweak * disable ga logging in dev again * add logging for hyperlink `edit` & support for tracking in manager * event label tweaks * fix tests & make more typesafe Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
parent
e203203993
commit
21e9fcb2f5
8 changed files with 68 additions and 13 deletions
|
@ -10,6 +10,31 @@ import {
|
|||
import { ExcalidrawElement } from "../element/types";
|
||||
import { AppClassProperties, AppState } from "../types";
|
||||
import { MODES } from "../constants";
|
||||
import { trackEvent } from "../analytics";
|
||||
|
||||
const trackAction = (
|
||||
action: Action,
|
||||
source: "ui" | "keyboard" | "api",
|
||||
value: any,
|
||||
) => {
|
||||
if (action.trackEvent !== false) {
|
||||
try {
|
||||
if (action.trackEvent === true) {
|
||||
trackEvent(
|
||||
action.name,
|
||||
source,
|
||||
typeof value === "number" || typeof value === "string"
|
||||
? String(value)
|
||||
: undefined,
|
||||
);
|
||||
} else {
|
||||
action.trackEvent?.(action, source, value);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("error while logging action:", error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export class ActionManager implements ActionsManagerInterface {
|
||||
actions = {} as ActionsManagerInterface["actions"];
|
||||
|
@ -65,9 +90,12 @@ export class ActionManager implements ActionsManagerInterface {
|
|||
),
|
||||
);
|
||||
|
||||
if (data.length === 0) {
|
||||
if (data.length !== 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const action = data[0];
|
||||
|
||||
const { viewModeEnabled } = this.getAppState();
|
||||
if (viewModeEnabled) {
|
||||
if (!Object.values(MODES).includes(data[0].name)) {
|
||||
|
@ -75,6 +103,8 @@ export class ActionManager implements ActionsManagerInterface {
|
|||
}
|
||||
}
|
||||
|
||||
trackAction(action, "keyboard", null);
|
||||
|
||||
event.preventDefault();
|
||||
this.updater(
|
||||
data[0].perform(
|
||||
|
@ -96,6 +126,7 @@ export class ActionManager implements ActionsManagerInterface {
|
|||
this.app,
|
||||
),
|
||||
);
|
||||
trackAction(action, "api", null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -122,6 +153,8 @@ export class ActionManager implements ActionsManagerInterface {
|
|||
this.app,
|
||||
),
|
||||
);
|
||||
|
||||
trackAction(action, "ui", formState);
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue