From ccc4d739c97465e981eb73dca981e356b01f6eaf Mon Sep 17 00:00:00 2001 From: dubsector Date: Sat, 1 Aug 2026 23:52:01 -0400 Subject: [PATCH] Track clicked links, not just typed commands Clicking a directory link runs a command the visitor never typed, so it was invisible in the stats - the only tracked path was the Enter key. Directory links now send a click event and external ones an outlink event, both under the existing terminal category, so the two ways of exploring stay distinguishable. --- src/analytics.js | 33 ++++++++++++++++++++++++++++----- src/terminal.js | 4 +++- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/analytics.js b/src/analytics.js index e124d1a..ccca908 100644 --- a/src/analytics.js +++ b/src/analytics.js @@ -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); } diff --git a/src/terminal.js b/src/terminal.js index 5a4f4ab..ca792c2 100644 --- a/src/terminal.js +++ b/src/terminal.js @@ -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(); @@ -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); } },