@vibiz/cli 0.3.24 → 0.3.25

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/dist/vibiz.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  formatUsd,
12
12
  mergeEnvFile,
13
13
  oneKeyMessage
14
- } from "./chunk-VV76BJPD.js";
14
+ } from "./chunk-XGUYBK6U.js";
15
15
 
16
16
  // packages/cli/src/main.ts
17
17
  import { spawn } from "node:child_process";
@@ -40,6 +40,20 @@ var VibizAppError = class extends Error {
40
40
  this.details = details;
41
41
  }
42
42
  };
43
+ function attribution() {
44
+ const w = globalThis.window;
45
+ try {
46
+ const got = w?.vibiz?.attribution?.();
47
+ if (got && typeof got === "object") return got;
48
+ const raw = globalThis.sessionStorage?.getItem("_vz_a");
49
+ if (!w || !raw) return null;
50
+ const a = JSON.parse(raw);
51
+ const page = globalThis.location?.pathname;
52
+ return { ...a, checkout_page: page ?? a.checkout_page ?? null };
53
+ } catch {
54
+ return null;
55
+ }
56
+ }
43
57
  var WEBHOOK_TOLERANCE_S = 300;
44
58
  var K = new Uint32Array([
45
59
  1116352408,
@@ -618,6 +632,11 @@ var VibizApp = class _VibizApp {
618
632
  }
619
633
  }
620
634
  };
635
+ /**
636
+ * Analytics helpers. `attribution()` runs in the browser (no key, no
637
+ * request): the tab's first-touch attribution, to send with a checkout.
638
+ */
639
+ analytics = { attribution };
621
640
  /**
622
641
  * A server-side event in the project's analytics, next to the browser's.
623
642
  * Never throws: analytics must not break the request that tracks it.
@@ -4165,6 +4184,11 @@ var HELP = `vibiz \u2014 website, database and sign-in for a new business, in on
4165
4184
  vibiz add <hosting|database|auth|email|analytics|replay|ai> add a resource to this project
4166
4185
  vibiz analytics [--period 24h|7d|30d] [--json] visitors, pages, sources, events
4167
4186
  vibiz analytics snippet the tag for a site hosted anywhere, and the domains it counts
4187
+ vibiz analytics visitors [--converted] [--source google.com|direct] [--landing /p] [--country ES]
4188
+ [--period 24h|7d|30d] [--goals Signup,Purchase] [--limit n] [--cursor c] [--json]
4189
+ visitor journeys: where each visitor (or buyer) came from, their path
4190
+ vibiz analytics visitor <visitor_id> [--day YYYY-MM-DD] [--json]
4191
+ one visitor's day: every page and event, replays, sales
4168
4192
  vibiz replays [--errors] [--rage] [--dead] [--path /x] [--period 7d] [--json]
4169
4193
  what went wrong for visitors, then sessions to watch
4170
4194
  vibiz replay <id> [--json] one session's signals and a link to watch it
@@ -5311,6 +5335,50 @@ function printAnalytics(io, r) {
5311
5335
  r.events.map((e) => [e.name, e.count])
5312
5336
  );
5313
5337
  }
5338
+ var fromLabel = (source) => source ?? "direct";
5339
+ function printJourneys(io, r) {
5340
+ const f = r.filters;
5341
+ const only = [
5342
+ f.converted && "converted",
5343
+ f.source && `from ${f.source}`,
5344
+ f.landing && `landing ${f.landing}`,
5345
+ f.country
5346
+ ].filter(Boolean);
5347
+ io.log(`Visitors, last ${r.period}${only.length ? ` (${only.join(", ")})` : ""}, newest first`);
5348
+ if (!r.data.length) io.log(" none");
5349
+ for (const j of r.data) {
5350
+ const sale = j.sales.length ? ` bought ${j.sales.map((p) => formatMinor(p.amount_cents, p.currency)).join(" + ")}` : j.converted ? " converted" : "";
5351
+ io.log(
5352
+ `
5353
+ ${j.started_at.slice(0, 16).replace("T", " ")} from ${fromLabel(j.source)} ${[j.country, j.device].filter(Boolean).join(" ")} ${clock(j.duration_ms)}${sale}`
5354
+ );
5355
+ io.log(` ${j.pages.map((p) => p.path).join(" \u2192 ")}`);
5356
+ if (j.custom_events.length)
5357
+ io.log(` events: ${j.custom_events.map((e) => e.name).join(", ")}`);
5358
+ io.log(` vibiz analytics visitor ${j.visitor_id} --day ${j.day}`);
5359
+ }
5360
+ if (r.next_cursor) io.log(`
5361
+ more: --cursor ${r.next_cursor}`);
5362
+ if (r.console_url) io.log(`
5363
+ ${r.console_url}`);
5364
+ }
5365
+ function printJourney(io, j) {
5366
+ io.log(
5367
+ `Visitor ${j.visitor_id} on ${j.day}: from ${fromLabel(j.source)}, landed on ${j.landing_page ?? "?"}`
5368
+ );
5369
+ io.log(
5370
+ ` ${[j.country, j.device].filter(Boolean).join(" \xB7 ")} ${j.pageviews} pages \xB7 ${j.events} events \xB7 ${clock(j.duration_ms)}${j.converted ? " \xB7 converted" : ""}`
5371
+ );
5372
+ for (const t of j.timeline) {
5373
+ const what = t.type === "pageview" ? t.path : `${t.name} (${t.path})`;
5374
+ const src = t.source ? ` \u2190 ${t.source}` : "";
5375
+ io.log(` ${t.at.slice(11, 19)} ${t.type === "pageview" ? " " : " \u2022 "}${what}${src}`);
5376
+ }
5377
+ for (const p of j.sales)
5378
+ io.log(` sale ${p.id}: ${formatMinor(p.amount_cents, p.currency)} (${p.environment})`);
5379
+ for (const r of j.replays) io.log(` replay ${r.id}: vibiz replay ${r.id}`);
5380
+ if (j.console_url) io.log(` ${j.console_url}`);
5381
+ }
5314
5382
  var clock = (ms2) => {
5315
5383
  const sec = Math.round(ms2 / 1e3);
5316
5384
  return `${Math.floor(sec / 60)}:${String(sec % 60).padStart(2, "0")}`;
@@ -5681,6 +5749,11 @@ async function runCli(argv2, io) {
5681
5749
  "max-pages": { type: "string" },
5682
5750
  action: { type: "string" },
5683
5751
  cursor: { type: "string" },
5752
+ // visitor journeys (vibiz analytics visitors | visitor <id>)
5753
+ day: { type: "string" },
5754
+ landing: { type: "string" },
5755
+ converted: { type: "boolean", default: false },
5756
+ goals: { type: "string" },
5684
5757
  page: { type: "boolean", default: false },
5685
5758
  code: { type: "boolean", default: false },
5686
5759
  db: { type: "boolean", default: false },
@@ -7250,6 +7323,35 @@ ${await oneKeyLines(vibiz2, id)}`);
7250
7323
  }
7251
7324
  const period = values.period ?? "7d";
7252
7325
  if (!["24h", "7d", "30d"].includes(period)) throw new Error("--period is 24h, 7d or 30d");
7326
+ if (positionals[0] === "visitors" || positionals[0] === "journeys") {
7327
+ const goals = values.goals?.split(",").map((g) => g.trim()).filter(Boolean);
7328
+ const list2 = await (await io.client()).analytics.visitors(await io.project(), {
7329
+ period,
7330
+ ...values.source ? { source: values.source } : {},
7331
+ ...values.landing ? { landing: values.landing } : {},
7332
+ ...values.country ? { country: values.country } : {},
7333
+ ...values.converted ? { converted: true } : {},
7334
+ ...goals?.length ? { goals } : {},
7335
+ ...values.limit ? { limit: Number(values.limit) } : {},
7336
+ ...values.cursor ? { cursor: values.cursor } : {}
7337
+ });
7338
+ if (values.json) io.log(JSON.stringify(list2, null, 2));
7339
+ else printJourneys(io, list2);
7340
+ return;
7341
+ }
7342
+ if (positionals[0] === "visitor") {
7343
+ const id = positionals[1];
7344
+ if (!id)
7345
+ throw new Error(
7346
+ "Which visitor? vibiz analytics visitor <visitor_id> --day YYYY-MM-DD (ids are in vibiz analytics visitors)"
7347
+ );
7348
+ const j = await (await io.client()).analytics.visitor(await io.project(), id, {
7349
+ ...values.day ? { day: values.day } : {}
7350
+ });
7351
+ if (values.json) io.log(JSON.stringify(j, null, 2));
7352
+ else printJourney(io, j);
7353
+ return;
7354
+ }
7253
7355
  const report = await (await io.client()).analytics.get(await io.project(), { period });
7254
7356
  if (values.json) io.log(JSON.stringify(report, null, 2));
7255
7357
  else printAnalytics(io, report);
@@ -7988,7 +8090,7 @@ Store the key now: it is not shown again.`
7988
8090
  return;
7989
8091
  }
7990
8092
  case "docs": {
7991
- const { DOC_TOPICS, DOCS } = await import("./src-M73GYB5U.js");
8093
+ const { DOC_TOPICS, DOCS } = await import("./src-FCM467GZ.js");
7992
8094
  const topic = positionals[0];
7993
8095
  if (!topic || !DOC_TOPICS.includes(topic)) {
7994
8096
  for (const t of DOC_TOPICS) io.log(` vibiz docs ${t.padEnd(13)} ${DOCS[t].title}`);
@@ -8013,7 +8115,7 @@ ${DOCS[topic].body}`);
8013
8115
  if (positionals[0])
8014
8116
  throw new Error('usage: vibiz mcp (serve over stdio) | vibiz mcp add --clients "<client>"');
8015
8117
  io.local();
8016
- const { serveStdio } = await import("./src-M73GYB5U.js");
8118
+ const { serveStdio } = await import("./src-FCM467GZ.js");
8017
8119
  await serveStdio({ version: cliVersion() });
8018
8120
  return;
8019
8121
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibiz/cli",
3
- "version": "0.3.24",
3
+ "version": "0.3.25",
4
4
  "description": "The thelastapi CLI and MCP server: website, database, sign-in, email and AI for a new business, from your terminal or your AI agent.",
5
5
  "keywords": [
6
6
  "vibiz",