thumbgate 1.40.2 → 1.40.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/.well-known/mcp/server-card.json +1 -1
- package/README.md +2 -2
- package/adapters/claude/.mcp.json +3 -3
- package/adapters/forge/forge.yaml +3 -3
- package/adapters/future-agi/.mcp.json +1 -1
- package/adapters/future-agi/config.toml +1 -1
- package/adapters/future-agi/opencode.json +1 -1
- package/adapters/herdr/herdr-plugin.toml +2 -2
- package/adapters/mcp/server-stdio.js +4 -2
- package/adapters/opencode/opencode.json +1 -1
- package/config/github-about.json +1 -1
- package/config/post-deploy-marketing-pages.json +1 -1
- package/package.json +30 -7
- package/public/about.html +2 -2
- package/public/admin.html +329 -47
- package/public/case-studies.html +1 -0
- package/public/dashboard.html +7 -6
- package/public/diagnostic.html +15 -12
- package/public/index.html +210 -78
- package/public/install.html +9 -8
- package/public/js/connect-panel.js +437 -0
- package/public/numbers.html +2 -2
- package/public/preview.html +42 -0
- package/public/pricing.html +55 -10
- package/scripts/auto-promote-gates.js +16 -1
- package/scripts/billing.js +189 -4
- package/scripts/cap-hit-counter.js +47 -0
- package/scripts/checkout-human-gate.js +248 -0
- package/scripts/checkout-session-count.js +115 -0
- package/scripts/feedback-loop.js +8 -1
- package/scripts/first-block-upsell.js +187 -0
- package/scripts/gates-engine.js +37 -108
- package/scripts/human-feedback.js +42 -0
- package/scripts/ops-log.js +91 -0
- package/scripts/ops-report.js +174 -0
- package/scripts/owner-admin.js +373 -26
- package/scripts/owner-telemetry.js +142 -0
- package/scripts/rate-limiter.js +8 -2
- package/scripts/statusline-human-counts.js +132 -0
- package/scripts/statusline-links.js +13 -3
- package/scripts/statusline-local-stats.js +5 -3
- package/scripts/statusline.sh +31 -3
- package/scripts/telemetry-analytics.js +4 -0
- package/scripts/tool-contract-validator.js +13 -3
- package/scripts/tool-registry.js +1 -1
- package/scripts/utm-source-summary.js +88 -0
- package/server.json +2 -2
- package/src/api/server.js +613 -107
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// Status-line thumb counts: only feedback a person gave, only for the project
|
|
5
|
+
// the status line is rendered in. Prints {"up":N,"down":N,"label":"this project"}.
|
|
6
|
+
//
|
|
7
|
+
// Two stores can hold a project's thumbs: the project's own feedback dir, and the
|
|
8
|
+
// global ~/.thumbgate store, where MCP capture_feedback calls land because the MCP
|
|
9
|
+
// server does not run in the project directory. Global rows belong to this
|
|
10
|
+
// project when they carry its project key, or only scope.projectId equal to the
|
|
11
|
+
// project folder name.
|
|
12
|
+
const path = require('node:path');
|
|
13
|
+
const { readProjectRows } = require('./project-catalog');
|
|
14
|
+
const { resolveLocalProject, hash } = require('./project-identity');
|
|
15
|
+
const { resolveProjectDir, resolveFeedbackDir, getHomeDir } = require('./feedback-paths');
|
|
16
|
+
const { isCountedHumanFeedback, isLegacyMcpCapture } = require('./human-feedback');
|
|
17
|
+
|
|
18
|
+
function normalizeSignal(entry) {
|
|
19
|
+
const raw = String(entry.signal || entry.feedback || '').toLowerCase();
|
|
20
|
+
if (raw === 'positive' || raw === 'up' || raw === 'thumbs_up') return 'up';
|
|
21
|
+
if (raw === 'negative' || raw === 'down' || raw === 'thumbs_down') return 'down';
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// The agent records a thumb within seconds of the message that carried it.
|
|
26
|
+
const CORROBORATION_MS = 90 * 1000;
|
|
27
|
+
|
|
28
|
+
function rowTime(row) {
|
|
29
|
+
const at = Date.parse(row.timestamp || row.createdAt || '');
|
|
30
|
+
return Number.isFinite(at) ? at : null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function isScrapedHumanThumb(row) {
|
|
34
|
+
if (String(row.reviewOrigin || '').toLowerCase() !== 'human') return false;
|
|
35
|
+
const tags = Array.isArray(row.tags) ? row.tags : [];
|
|
36
|
+
return tags.includes('claude-history-sync');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function computeHumanCounts(options = {}) {
|
|
40
|
+
const env = options.env || process.env;
|
|
41
|
+
const cwd = options.cwd || process.cwd();
|
|
42
|
+
const projectDir = resolveProjectDir({ cwd, env });
|
|
43
|
+
const feedbackDir = resolveFeedbackDir({ projectDir, env });
|
|
44
|
+
const { projectKey } = resolveLocalProject(projectDir);
|
|
45
|
+
const projectName = path.basename(projectDir);
|
|
46
|
+
// readProjectRows maps a row that only names a project in scope.projectId to this legacy key.
|
|
47
|
+
const aliasKey = `legacy_${hash(projectName)}`;
|
|
48
|
+
const globalDir = path.join(getHomeDir({ env }), '.thumbgate');
|
|
49
|
+
|
|
50
|
+
const seen = new Set();
|
|
51
|
+
const mineRows = [];
|
|
52
|
+
const ownDir = path.resolve(feedbackDir);
|
|
53
|
+
for (const dir of new Set([ownDir, path.resolve(globalDir)])) {
|
|
54
|
+
// Rows written before project tracking carry no key. In the project's own
|
|
55
|
+
// feedback dir they are this project's; in the shared global store they are not.
|
|
56
|
+
const ownsUnassigned = dir === ownDir && dir !== path.resolve(globalDir);
|
|
57
|
+
for (const row of readProjectRows(dir, 'feedback-log.jsonl', {})) {
|
|
58
|
+
const mine = row.projectKey === projectKey || row.projectKey === aliasKey
|
|
59
|
+
|| (ownsUnassigned && row.projectKey === 'unassigned');
|
|
60
|
+
if (!mine) continue;
|
|
61
|
+
if (row.id) {
|
|
62
|
+
if (seen.has(row.id)) continue;
|
|
63
|
+
seen.add(row.id);
|
|
64
|
+
}
|
|
65
|
+
mineRows.push(row);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// A thumb the history sync scraped from the person's own message is evidence
|
|
70
|
+
// that the person gave one at that moment. An MCP capture that an older server
|
|
71
|
+
// labelled automated counts when such evidence sits next to it; without it the
|
|
72
|
+
// row is a lesson the agent logged on its own judgment.
|
|
73
|
+
const scraped = { up: [], down: [] };
|
|
74
|
+
for (const row of mineRows) {
|
|
75
|
+
const signal = normalizeSignal(row);
|
|
76
|
+
const at = rowTime(row);
|
|
77
|
+
if (signal && at !== null && isScrapedHumanThumb(row)) scraped[signal].push(at);
|
|
78
|
+
}
|
|
79
|
+
const corroborated = (row) => {
|
|
80
|
+
const signal = normalizeSignal(row);
|
|
81
|
+
const at = rowTime(row);
|
|
82
|
+
return Boolean(signal) && at !== null && scraped[signal].some((t) => Math.abs(t - at) <= CORROBORATION_MS);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
let up = 0;
|
|
86
|
+
let down = 0;
|
|
87
|
+
let latestDown = null;
|
|
88
|
+
for (const row of mineRows) {
|
|
89
|
+
if (!(isCountedHumanFeedback(row) || (isLegacyMcpCapture(row) && corroborated(row)))) continue;
|
|
90
|
+
const signal = normalizeSignal(row);
|
|
91
|
+
if (signal === 'up') up += 1;
|
|
92
|
+
if (signal === 'down') {
|
|
93
|
+
down += 1;
|
|
94
|
+
const at = rowTime(row);
|
|
95
|
+
if (at !== null && (!latestDown || at > latestDown.at)) latestDown = { at, row };
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return { up, down, label: 'this project', project: projectName, latestDown: describeLatestDown(latestDown) };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
102
|
+
|
|
103
|
+
// The reader's own clock, 12-hour: "Nov 19, 3:37 PM". Built by hand because
|
|
104
|
+
// toLocaleString puts a narrow no-break space before AM/PM on newer ICU builds.
|
|
105
|
+
function formatStamp(ms) {
|
|
106
|
+
const d = new Date(ms);
|
|
107
|
+
const hour = d.getHours() % 12 || 12;
|
|
108
|
+
const minute = String(d.getMinutes()).padStart(2, '0');
|
|
109
|
+
return `${MONTHS[d.getMonth()]} ${d.getDate()}, ${hour}:${minute} ${d.getHours() < 12 ? 'AM' : 'PM'}`;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function describeLatestDown(found) {
|
|
113
|
+
if (!found) return null;
|
|
114
|
+
const { at, row } = found;
|
|
115
|
+
const raw = String(row.whatWentWrong || row.whatToChange || row.context || '').replace(/\s+/g, ' ').trim();
|
|
116
|
+
return {
|
|
117
|
+
id: row.id || null,
|
|
118
|
+
timestamp: new Date(at).toISOString(),
|
|
119
|
+
label: `Latest mistake ${formatStamp(at)}`,
|
|
120
|
+
text: raw.length > 60 ? `${raw.slice(0, 57)}...` : raw,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === path.resolve(__filename)) {
|
|
125
|
+
try {
|
|
126
|
+
process.stdout.write(JSON.stringify(computeHumanCounts()));
|
|
127
|
+
} catch (_) {
|
|
128
|
+
process.exit(0);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
module.exports = { computeHumanCounts };
|
|
@@ -134,7 +134,11 @@ function buildLinkState({
|
|
|
134
134
|
booting,
|
|
135
135
|
origin,
|
|
136
136
|
canBootstrap,
|
|
137
|
+
projectDir,
|
|
137
138
|
}) {
|
|
139
|
+
// The thumb links carry the project so a click is recorded for the project the
|
|
140
|
+
// status line shows, not for whichever directory the local server started in.
|
|
141
|
+
const projectParam = projectDir ? `&projectDir=${encodeURIComponent(projectDir)}` : '';
|
|
138
142
|
if (ready) {
|
|
139
143
|
return {
|
|
140
144
|
state: 'ready',
|
|
@@ -144,8 +148,8 @@ function buildLinkState({
|
|
|
144
148
|
downLabel: '👎',
|
|
145
149
|
dashboardUrl: `${origin}/dashboard`,
|
|
146
150
|
lessonsUrl: `${origin}/lessons`,
|
|
147
|
-
upUrl: `${origin}/feedback/quick?signal=up`,
|
|
148
|
-
downUrl: `${origin}/feedback/quick?signal=down`,
|
|
151
|
+
upUrl: `${origin}/feedback/quick?signal=up${projectParam}`,
|
|
152
|
+
downUrl: `${origin}/feedback/quick?signal=down${projectParam}`,
|
|
149
153
|
};
|
|
150
154
|
}
|
|
151
155
|
|
|
@@ -194,7 +198,13 @@ async function getStatuslineLinks(options = {}) {
|
|
|
194
198
|
|
|
195
199
|
const ready = allowLocalBootstrap ? await probe(origin, options) : false;
|
|
196
200
|
if (ready) {
|
|
197
|
-
return buildLinkState({
|
|
201
|
+
return buildLinkState({
|
|
202
|
+
ready: true,
|
|
203
|
+
booting: false,
|
|
204
|
+
origin,
|
|
205
|
+
canBootstrap,
|
|
206
|
+
projectDir: resolveProjectDir({ env, cwd: options.cwd || process.cwd() }),
|
|
207
|
+
});
|
|
198
208
|
}
|
|
199
209
|
|
|
200
210
|
const state = readRuntimeState({ env, home: homeDir });
|
|
@@ -13,10 +13,12 @@ const { resolveProjectDir } = require('./feedback-paths');
|
|
|
13
13
|
try {
|
|
14
14
|
const projectDir = resolveProjectDir({ cwd: process.cwd(), env: process.env });
|
|
15
15
|
syncClaudeHistoryFeedback({ projectDir });
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
// The status line is per project by default. Global totals mix every repo's
|
|
17
|
+
// entries and are opt-in with THUMBGATE_STATUSLINE_SCOPE=global.
|
|
18
|
+
const scope = String(process.env.THUMBGATE_STATUSLINE_SCOPE || 'project').toLowerCase();
|
|
19
|
+
const stats = scope === 'global' && shouldAggregateFeedback({ env: process.env })
|
|
18
20
|
? computeAggregateFeedbackStats({ projectDir, env: process.env })
|
|
19
|
-
: analyzeFeedback(undefined, { humanOnly: true });
|
|
21
|
+
: analyzeFeedback(undefined, { humanOnly: true, strictHuman: true });
|
|
20
22
|
const payload = {
|
|
21
23
|
...normalizeStatsPayload(stats),
|
|
22
24
|
aggregate: stats.aggregate || { enabled: false },
|
package/scripts/statusline.sh
CHANGED
|
@@ -90,6 +90,25 @@ if [ "$UP" = "0" ] && [ "$DOWN" = "0" ] || [ $(( _NOW - ${CACHE_TS:-0} )) -gt 12
|
|
|
90
90
|
fi
|
|
91
91
|
fi
|
|
92
92
|
|
|
93
|
+
# Thumb counts shown on the line are human feedback for this project only. The
|
|
94
|
+
# caches above are global sums that include automated entries, so they feed
|
|
95
|
+
# lessons and trend, never the thumbs.
|
|
96
|
+
SCOPE_LABEL="this project"
|
|
97
|
+
LD_TS=""; LD_LABEL=""; LD_TEXT=""
|
|
98
|
+
_HUMAN_JSON="${_TEST_THUMBGATE_STATUSLINE_HUMAN_JSON:-$(node "${SCRIPT_DIR}/statusline-human-counts.js" 2>/dev/null)}"
|
|
99
|
+
if [ -n "$_HUMAN_JSON" ]; then
|
|
100
|
+
eval "$(echo "$_HUMAN_JSON" | jq -r '
|
|
101
|
+
@sh "UP=\(.up // 0)",
|
|
102
|
+
@sh "DOWN=\(.down // 0)",
|
|
103
|
+
@sh "SCOPE_LABEL=\(.label // "this project")",
|
|
104
|
+
@sh "LD_TS=\(.latestDown.timestamp // "")",
|
|
105
|
+
@sh "LD_LABEL=\(.latestDown.label // "")",
|
|
106
|
+
@sh "LD_TEXT=\(.latestDown.text // "")"
|
|
107
|
+
' 2>/dev/null)"
|
|
108
|
+
else
|
|
109
|
+
UP="0"; DOWN="0"
|
|
110
|
+
fi
|
|
111
|
+
|
|
93
112
|
# Background refresh from REST API when cache is stale (>120s)
|
|
94
113
|
if [ $(( _NOW - ${CACHE_TS:-0} )) -gt 120 ]; then
|
|
95
114
|
(
|
|
@@ -165,9 +184,18 @@ if [[ -n "$_LESSON_JSON" ]]; then
|
|
|
165
184
|
@sh "LESSON_TEXT=\(.text // "")",
|
|
166
185
|
@sh "LESSON_ID=\(.lessonId // "")",
|
|
167
186
|
@sh "LESSON_LABEL=\(.label // "")",
|
|
168
|
-
@sh "LESSON_LINK=\(.link // "")"
|
|
187
|
+
@sh "LESSON_LINK=\(.link // "")",
|
|
188
|
+
@sh "LESSON_CREATED=\(.createdAt // "")"
|
|
169
189
|
' 2>/dev/null)"
|
|
170
190
|
fi
|
|
191
|
+
# "Latest mistake" is the newest thumbs-down a person gave this project. The
|
|
192
|
+
# lesson store only fills when a lesson is inferred, so it can lag far behind;
|
|
193
|
+
# the thumb log is the fresher record. Both are ISO UTC, so a string compare orders them.
|
|
194
|
+
LESSON_CREATED="${LESSON_CREATED:-}"
|
|
195
|
+
if [[ -n "$LD_TS" ]] && [[ -z "$LESSON_CREATED" || ! "$LD_TS" < "$LESSON_CREATED" ]]; then
|
|
196
|
+
LESSON_LABEL="$LD_LABEL"; LESSON_TEXT="$LD_TEXT"
|
|
197
|
+
if [[ "$LD_TS" != "$LESSON_CREATED" ]]; then LESSON_ID=""; LESSON_LINK=""; fi
|
|
198
|
+
fi
|
|
171
199
|
|
|
172
200
|
# ── Colors ────────────────────────────────────────────────────────
|
|
173
201
|
G='\033[32m'; R='\033[31m'; M='\033[35m'; C='\033[36m'; D='\033[90m'; BD='\033[1m'; RST='\033[0m'
|
|
@@ -217,7 +245,7 @@ LINE=""
|
|
|
217
245
|
[[ -n "$WORK_ITEM_LABEL" ]] && LINE="${LINE:+${LINE} · }${WORK_ITEM_LABEL}"
|
|
218
246
|
LINE="${LINE:+${LINE} · }ThumbGate v${TG_VERSION} · ${TG_TIER}"
|
|
219
247
|
if [[ "$UP" = "0" && "$DOWN" = "0" ]]; then
|
|
220
|
-
LINE="${D}${LINE}${RST} · no feedback
|
|
248
|
+
LINE="${D}${LINE}${RST} · ${UP_LINK} ${DOWN_LINK} ${D}no human feedback ${SCOPE_LABEL}${RST}"
|
|
221
249
|
[[ -n "$PR_LABEL" ]] && LINE="${LINE} · ${D}${PR_LABEL}${RST}"
|
|
222
250
|
|
|
223
251
|
LINE="${LINE} · ${C}${DASHBOARD_LINK}${RST}"
|
|
@@ -225,7 +253,7 @@ if [[ "$UP" = "0" && "$DOWN" = "0" ]]; then
|
|
|
225
253
|
|
|
226
254
|
printf '%b\n' "$LINE"
|
|
227
255
|
else
|
|
228
|
-
LINE="${LINE} · ${G}${BD}${UP}${RST}${UP_LINK} ${R}${BD}${DOWN}${RST}${DOWN_LINK} ${
|
|
256
|
+
LINE="${LINE} · ${G}${BD}${UP}${RST}${UP_LINK} ${R}${BD}${DOWN}${RST}${DOWN_LINK} ${D}${SCOPE_LABEL}${RST}"
|
|
229
257
|
|
|
230
258
|
# Control Tower alerts (if any)
|
|
231
259
|
[[ "${SLO_V:-0}" -gt 0 ]] && LINE="${LINE} ${R}${SLO_V} SLO${RST}"
|
|
@@ -1789,6 +1789,7 @@ const appendTelemetryPing = appendTelemetryEvent;
|
|
|
1789
1789
|
|
|
1790
1790
|
module.exports = {
|
|
1791
1791
|
TELEMETRY_FILE_NAME,
|
|
1792
|
+
CHECKOUT_START_EVENT_TYPES,
|
|
1792
1793
|
sanitizeTelemetryPayload,
|
|
1793
1794
|
classifyTelemetryAudience,
|
|
1794
1795
|
headerHasPrivacyOptOut,
|
|
@@ -1800,4 +1801,7 @@ module.exports = {
|
|
|
1800
1801
|
getTelemetryAnalytics,
|
|
1801
1802
|
getTelemetrySummary,
|
|
1802
1803
|
inferTrafficChannel,
|
|
1804
|
+
isMarketingClickEvent,
|
|
1805
|
+
isCheckoutStartEvent,
|
|
1806
|
+
isDirectStripeBeacon,
|
|
1803
1807
|
};
|
|
@@ -119,13 +119,23 @@ function validatePropertyCount(schema, keys, path, errors) {
|
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
// Name the allowed values and any keys the caller sent that the schema does not define, so the
|
|
123
|
+
// caller can fix the next attempt from the error text alone (e.g. `feedback` sent for `signal`).
|
|
124
|
+
function missingParameterHint(schema, value, required) {
|
|
125
|
+
const properties = schema.properties || {};
|
|
126
|
+
const allowed = properties[required] && Array.isArray(properties[required].enum) ? properties[required].enum : null;
|
|
127
|
+
const unrecognized = Object.keys(value).filter((key) => !Object.hasOwn(properties, key));
|
|
128
|
+
let hint = allowed && allowed.length ? ` (allowed values: ${allowed.join(', ')})` : '';
|
|
129
|
+
if (unrecognized.length) hint += `. Received unrecognized: ${unrecognized.map((key) => `'${key}'`).join(', ')}.`;
|
|
130
|
+
return hint;
|
|
131
|
+
}
|
|
132
|
+
|
|
122
133
|
function validateRequiredProperties(schema, value, path, errors) {
|
|
123
134
|
for (const required of schema.required || []) {
|
|
124
135
|
if (value[required] === undefined || value[required] === null || value[required] === '') {
|
|
125
136
|
const requiredPath = joinPath(path, required);
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
: `Missing required parameter: '${required}'`);
|
|
137
|
+
const message = `Missing required parameter: '${required}'${missingParameterHint(schema, value, required)}`;
|
|
138
|
+
errors.push(path ? `Parameter '${path}': ${message}` : message);
|
|
129
139
|
if (path && requiredPath === path) break;
|
|
130
140
|
}
|
|
131
141
|
}
|
package/scripts/tool-registry.js
CHANGED
|
@@ -206,7 +206,7 @@ const MEMORY_SCOPE_SCHEMA = {
|
|
|
206
206
|
const TOOLS = [
|
|
207
207
|
destructiveTool({
|
|
208
208
|
name: 'capture_feedback',
|
|
209
|
-
description: 'Capture an up/down signal plus one line of why. Vague feedback is logged, then returned with a clarification prompt instead of memory promotion.',
|
|
209
|
+
description: 'Capture an up/down signal plus one line of why. Required: signal ("up" or "down"; not "feedback" or "rating"). Add context (one sentence) and, for "down", whatWentWrong and whatToChange. Example: {"signal":"down","context":"claimed deployed without a health check","whatToChange":"run curl on /health first"}. Vague feedback is logged, then returned with a clarification prompt instead of memory promotion.',
|
|
210
210
|
inputSchema: {
|
|
211
211
|
type: 'object',
|
|
212
212
|
required: ['signal'],
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Visits, installs and checkout starts grouped by utm_source, for the last 7 and
|
|
4
|
+
// 30 days. Read-only over the telemetry ledger; counts external traffic only.
|
|
5
|
+
|
|
6
|
+
const { loadTelemetryEvents, CHECKOUT_START_EVENT_TYPES } = require('./telemetry-analytics');
|
|
7
|
+
|
|
8
|
+
const WINDOW_DAYS = [7, 30];
|
|
9
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
10
|
+
|
|
11
|
+
function sourceKey(entry) {
|
|
12
|
+
const raw = entry.utmSource || entry.source;
|
|
13
|
+
const text = String(raw || '').trim().toLowerCase();
|
|
14
|
+
return text || 'unknown';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function emptyRow(source) {
|
|
18
|
+
return {
|
|
19
|
+
source,
|
|
20
|
+
visits: 0,
|
|
21
|
+
visitors: new Set(),
|
|
22
|
+
installIds: new Set(),
|
|
23
|
+
checkoutStarts: 0,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function summarizeWindow(events, days, nowMs) {
|
|
28
|
+
const sinceMs = nowMs - days * DAY_MS;
|
|
29
|
+
const rows = new Map();
|
|
30
|
+
const row = (source) => {
|
|
31
|
+
if (!rows.has(source)) rows.set(source, emptyRow(source));
|
|
32
|
+
return rows.get(source);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
for (const entry of events) {
|
|
36
|
+
if ((entry.audience || 'external') !== 'external') continue;
|
|
37
|
+
const at = Date.parse(entry.receivedAt || '');
|
|
38
|
+
if (!Number.isFinite(at) || at < sinceMs || at > nowMs) continue;
|
|
39
|
+
const client = entry.clientType || entry.client;
|
|
40
|
+
const type = entry.eventType || entry.event;
|
|
41
|
+
if (client === 'web' && type === 'landing_page_view') {
|
|
42
|
+
const r = row(sourceKey(entry));
|
|
43
|
+
r.visits += 1;
|
|
44
|
+
const visitor = entry.visitorId || entry.sessionId;
|
|
45
|
+
if (visitor) r.visitors.add(visitor);
|
|
46
|
+
} else if (client === 'web' && CHECKOUT_START_EVENT_TYPES.has(type)) {
|
|
47
|
+
row(sourceKey(entry)).checkoutStarts += 1;
|
|
48
|
+
} else if (client === 'cli' && entry.installId && entry.installId !== 'unknown') {
|
|
49
|
+
row(sourceKey(entry)).installIds.add(entry.installId);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const sources = [...rows.values()]
|
|
54
|
+
.map((r) => ({
|
|
55
|
+
source: r.source,
|
|
56
|
+
visits: r.visits,
|
|
57
|
+
visitors: r.visitors.size,
|
|
58
|
+
installs: r.installIds.size,
|
|
59
|
+
checkoutStarts: r.checkoutStarts,
|
|
60
|
+
}))
|
|
61
|
+
.sort((a, b) => b.visits - a.visits || a.source.localeCompare(b.source));
|
|
62
|
+
|
|
63
|
+
const allVisitors = new Set();
|
|
64
|
+
const allInstalls = new Set();
|
|
65
|
+
for (const r of rows.values()) {
|
|
66
|
+
for (const v of r.visitors) allVisitors.add(v);
|
|
67
|
+
for (const i of r.installIds) allInstalls.add(i);
|
|
68
|
+
}
|
|
69
|
+
const totals = {
|
|
70
|
+
visits: sources.reduce((n, s) => n + s.visits, 0),
|
|
71
|
+
visitors: allVisitors.size,
|
|
72
|
+
installs: allInstalls.size,
|
|
73
|
+
checkoutStarts: sources.reduce((n, s) => n + s.checkoutStarts, 0),
|
|
74
|
+
};
|
|
75
|
+
return { days, since: new Date(sinceMs).toISOString(), sources, totals };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function getUtmSourceSummary(feedbackDir, options = {}) {
|
|
79
|
+
const now = options.now instanceof Date ? options.now : new Date();
|
|
80
|
+
const events = loadTelemetryEvents(feedbackDir);
|
|
81
|
+
return {
|
|
82
|
+
asOf: now.toISOString(),
|
|
83
|
+
note: 'External traffic only. Installs are distinct CLI install ids; a CLI ping carries a source only when the install command passed one.',
|
|
84
|
+
windows: WINDOW_DAYS.map((days) => summarizeWindow(events, days, now.getTime())),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
module.exports = { getUtmSourceSummary, WINDOW_DAYS };
|
package/server.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"source": "github",
|
|
9
9
|
"url": "https://github.com/IgorGanapolsky/ThumbGate"
|
|
10
10
|
},
|
|
11
|
-
"version": "1.40.
|
|
11
|
+
"version": "1.40.5",
|
|
12
12
|
"packages": [
|
|
13
13
|
{
|
|
14
14
|
"registryType": "npm",
|
|
15
15
|
"registryBaseUrl": "https://registry.npmjs.org",
|
|
16
16
|
"identifier": "thumbgate",
|
|
17
|
-
"version": "1.40.
|
|
17
|
+
"version": "1.40.5",
|
|
18
18
|
"runtimeHint": "npx",
|
|
19
19
|
"runtimeArguments": [
|
|
20
20
|
{
|