Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions src/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,36 @@ export function initAnalytics() {
});
}

function trackEvent(action, name) {
if (!enabled) return;
var trimmed = String(name).trim();
if (!trimmed) return;
paq().push([
"trackEvent",
"terminal",
action,
trimmed.length > 100 ? trimmed.slice(0, 100) : trimmed,
]);
}

// Only the commands a visitor actually types get here - the scripted intro
// calls runCommand() directly, and counting those would drown out the real
// signal of what people explore on their own.
export function trackCommand(line) {
if (!enabled) return;
var trimmed = String(line).trim();
if (!trimmed) return;
var name = trimmed.length > 100 ? trimmed.slice(0, 100) : trimmed;
paq().push(["trackEvent", "terminal", "command", name]);
trackEvent("command", line);
}

// Clicking a directory link runs the same cd/ls a visitor could have typed,
// but it's a separate action so the stats show which way people actually
// explore: whether the links are getting discovered at all, or everyone is
// typing. The clicked name, not the replayed hops, is what's recorded.
export function trackClick(name) {
trackEvent("click", name);
}

// Matomo's enableLinkTracking only sees real DOM anchors, and these "links"
// are terminal cells painted by xterm's link provider, so outbound clicks
// have to be reported by hand or they don't show up anywhere.
export function trackLink(url) {
trackEvent("outlink", url);
}
4 changes: 3 additions & 1 deletion src/terminal.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Terminal } from "@xterm/xterm";
import { FitAddon } from "@xterm/addon-fit";
import "@xterm/xterm/css/xterm.css";
import { initAnalytics, trackCommand } from "./analytics.js";
import { initAnalytics, trackCommand, trackClick, trackLink } from "./analytics.js";

initAnalytics();

Expand Down Expand Up @@ -249,8 +249,10 @@ term.registerLinkProvider({
},
activate: function () {
if (l.url) {
trackLink(l.url);
window.open(l.url, "_blank", "noopener,noreferrer");
} else if (!navigating) {
trackClick(l.name);
navigateTo(l.name, l.origin);
}
},
Expand Down