@metricraven/cli 0.4.4 → 0.5.0
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/README.md +33 -7
- package/dist/api.js +1 -1
- package/dist/args.js +128 -6
- package/dist/commands.js +850 -25
- package/dist/completion.js +14 -8
- package/dist/format.js +14 -0
- package/dist/index.js +87 -12
- package/dist/range.js +15 -3
- package/package.json +1 -1
package/dist/completion.js
CHANGED
|
@@ -3,16 +3,18 @@ import { UsageError } from "./args.js";
|
|
|
3
3
|
/** The ad networks customers can choose (TikTok Ads is hidden until listed: core/ads.ts TIKTOK_ADS_LISTED). */
|
|
4
4
|
export const AD_PROVIDER_VALUES = ["all", "meta", "google"];
|
|
5
5
|
/** Shell completion scripts for `metricraven completion bash|zsh|fish`. */
|
|
6
|
-
const COMMANDS = ["login", "logout", "whoami", "account", "tokens", "payments", "use", "websites", "analytics", "realtime", "visitors", "funnels", "goals", "notes", "mentions", "ai-visibility", "alerts", "members", "bots", "proxy", "completion"];
|
|
6
|
+
const COMMANDS = ["login", "logout", "whoami", "account", "tokens", "events", "payments", "use", "websites", "analytics", "realtime", "visitors", "funnels", "segments", "goals", "notes", "mentions", "ai-visibility", "alerts", "members", "bots", "proxy", "completion"];
|
|
7
7
|
const SUB = {
|
|
8
8
|
websites: ["list", "create", "get", "update", "delete", "keys"],
|
|
9
9
|
account: ["get", "update"],
|
|
10
10
|
tokens: ["list", "create", "delete"],
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
events: ["list"],
|
|
12
|
+
payments: ["list", "delete"],
|
|
13
|
+
analytics: ["traffic", "breakdown", "revenue", "mrr", "conversions", "paths", "goal", "properties", "errors", "insights", "speed", "search", "crawlers", "ai-companies", "ads", "meta-ads"],
|
|
14
|
+
visitors: ["list", "get", "traits"],
|
|
15
|
+
funnels: ["list", "create", "update", "delete", "dropoff"],
|
|
16
|
+
segments: ["list", "create", "update", "delete"],
|
|
17
|
+
goals: ["list", "set", "reset", "colors", "definitions", "preview", "define", "undefine", "delete-events"],
|
|
16
18
|
notes: ["list", "add"],
|
|
17
19
|
mentions: ["list"],
|
|
18
20
|
alerts: ["list", "get", "create", "update", "delete", "history"],
|
|
@@ -21,12 +23,16 @@ const SUB = {
|
|
|
21
23
|
proxy: ["status", "enable", "check", "remove"],
|
|
22
24
|
completion: ["bash", "zsh", "fish"],
|
|
23
25
|
};
|
|
24
|
-
const FLAGS = ["--json", "--fields", "--site", "--token", "--verbose", "--help", "--version", "--period", "--from", "--to", "--timezone", "--filter", "--compare", "--sort", "--limit", "--offset", "--q", "--payment", "--name", "--domain", "--date", "--text", "--goal", "--trigger", "--subject", "--message", "--notify", "--recipients", "--enabled", "--disabled", "--yes", "--alert", "--platform", "--role", "--color", "--description", "--hidden", "--visible", "--company", "--scopes", "--sites", "--transaction", "--visitor", "--user", "--dry-run", "--page", "--page-contains", "--referrer", "--channel", "--source", "--utm-source", "--utm-medium", "--utm-campaign", "--country", "--device", "--browser", "--os", "--visits-gt", "--visits-lt", "--grace", "--provider", "--account", "--order", "--verified-only", "--datacenter"];
|
|
26
|
+
const FLAGS = ["--json", "--fields", "--site", "--token", "--verbose", "--help", "--version", "--period", "--from", "--to", "--timezone", "--filter", "--compare", "--sort", "--limit", "--offset", "--q", "--param", "--attribution", "--group", "--folder", "--include", "--drop-step", "--path", "--payment", "--name", "--domain", "--date", "--text", "--goal", "--trigger", "--subject", "--message", "--notify", "--recipients", "--enabled", "--disabled", "--yes", "--alert", "--platform", "--role", "--color", "--description", "--hidden", "--visible", "--company", "--scopes", "--sites", "--transaction", "--visitor", "--user", "--dry-run", "--page", "--page-contains", "--link", "--link-path", "--click", "--form", "--download", "--referrer", "--channel", "--source", "--utm-source", "--utm-medium", "--utm-campaign", "--country", "--device", "--browser", "--os", "--visits-gt", "--visits-lt", "--trait", "--key", "--visit-source", "--visit-channel", "--visit-campaign", "--visit-referrer", "--visit-entry-page", "--visit-page", "--visit-page-contains", "--visit-goal", "--visit", "--grace", "--provider", "--account", "--order", "--verified-only", "--datacenter", "--type", "--cursor", "--all", "--csv", "--step", "--continued", "--funnel", "--steps", "--start", "--end", "--who"];
|
|
25
27
|
/** Flags with a fixed set of values; completion offers them after the flag. */
|
|
26
28
|
export const FLAG_VALUES = {
|
|
27
29
|
"--provider": AD_PROVIDER_VALUES,
|
|
28
|
-
"--compare": ["previous", "year", "off"],
|
|
30
|
+
"--compare": ["previous", "weekdays", "year", "off"],
|
|
29
31
|
"--order": ["asc", "desc"],
|
|
32
|
+
"--attribution": ["first_touch", "viewed"],
|
|
33
|
+
"--group": ["page", "folder", "section"],
|
|
34
|
+
"--who": ["all", "paid", "unpaid"],
|
|
35
|
+
"--include": ["speed", "errors", "speed,errors"],
|
|
30
36
|
"--verified-only": ["on", "off"],
|
|
31
37
|
"--datacenter": ["on", "off"],
|
|
32
38
|
};
|
package/dist/format.js
CHANGED
|
@@ -81,3 +81,17 @@ export function truncate(s, max = 48) {
|
|
|
81
81
|
export function section(title, body) {
|
|
82
82
|
return `\n${bold(title)}\n${body}`;
|
|
83
83
|
}
|
|
84
|
+
export function csvLine(cells) {
|
|
85
|
+
return cells
|
|
86
|
+
.map((value) => {
|
|
87
|
+
if (value === null || value === undefined)
|
|
88
|
+
return "";
|
|
89
|
+
if (typeof value === "number")
|
|
90
|
+
return Number.isFinite(value) ? String(value) : "";
|
|
91
|
+
if (typeof value === "boolean")
|
|
92
|
+
return value ? "true" : "false";
|
|
93
|
+
const text = /^[=+\-@\t\r]/.test(value) ? `'${value}` : value;
|
|
94
|
+
return /[",\r\n]|^\s|\s$/.test(text) ? `"${text.replace(/"/g, '""')}"` : text;
|
|
95
|
+
})
|
|
96
|
+
.join(",");
|
|
97
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -38,16 +38,42 @@ Reports (default: last 30 days)
|
|
|
38
38
|
analytics traffic Visitors, pageviews, revenue, conversion, top sources
|
|
39
39
|
analytics breakdown <dim> Full table for a dimension: channel, referrer, page,
|
|
40
40
|
entryPage, utmSource, utmCampaign, country, city,
|
|
41
|
-
browser, os, device,
|
|
42
|
-
|
|
41
|
+
browser, os, device, language, screenSize,
|
|
42
|
+
exitPage, hostname, outbound, urlParam (with
|
|
43
|
+
--param <name>: analytics breakdown urlParam
|
|
44
|
+
--param plan), …
|
|
45
|
+
--sort visitors|pageviews|revenue|payingVisitors|
|
|
46
|
+
purchaseRate|name|exits|exitRate|avgTime|buyers,
|
|
47
|
+
--order desc|asc
|
|
48
|
+
page: --attribution first_touch|viewed (viewed:
|
|
49
|
+
every page buyers saw before paying),
|
|
50
|
+
--group folder [--folder /blog/]; page and entryPage:
|
|
51
|
+
--include speed (LCP and INP at the 75th percentile),
|
|
52
|
+
errors (visitors who hit a JavaScript error and didn't
|
|
53
|
+
pay), or speed,errors
|
|
43
54
|
analytics revenue Payments, renewals, refunds, LTV, revenue by channel
|
|
44
55
|
analytics mrr [unit] MRR over time: new, expansion, contraction, churn
|
|
45
56
|
(unit: day, week or month)
|
|
46
|
-
analytics conversions Goals and funnel steps
|
|
47
|
-
|
|
48
|
-
|
|
57
|
+
analytics conversions Goals and funnel steps, median time between steps;
|
|
58
|
+
--funnel <id> reports a saved funnel, --steps an
|
|
59
|
+
unsaved one
|
|
60
|
+
analytics paths Page sequences of payers and non-payers
|
|
61
|
+
--steps 2-7, --group page|section, --start /pricing,
|
|
62
|
+
--end /checkout, --who all|paid|unpaid
|
|
63
|
+
analytics goal <name> One goal in detail: per property value, people, how many
|
|
64
|
+
bought afterwards, purchase rate and revenue
|
|
65
|
+
analytics properties [<name>] Event property names on goal events (or one property's
|
|
66
|
+
values), with people counts; --goal <name> for one goal
|
|
67
|
+
analytics errors JavaScript errors grouped by message, with how many of
|
|
68
|
+
those visitors didn't pay: --path /checkout, or
|
|
69
|
+
--funnel <id>|--steps <list> --drop-step <n> (visitors
|
|
70
|
+
who didn't reach step n); --group <id>: one group
|
|
71
|
+
analytics insights What converts: sources, countries, channels, time to purchase
|
|
72
|
+
analytics speed Slow pages that lose buyers: slow vs fast visitors who paid,
|
|
73
|
+
buyers lost, LCP and INP (needs Page speed on)
|
|
49
74
|
analytics search Google Search Console queries
|
|
50
75
|
analytics crawlers AI crawlers and bots
|
|
76
|
+
analytics ai-companies Per AI company: pages crawled, visits, customers, revenue
|
|
51
77
|
analytics ads [level] Ad spend, revenue and ROAS for every connected network
|
|
52
78
|
(campaign, adgroup or ad; --provider all|meta|google;
|
|
53
79
|
--account <id>: one chosen ad account alone)
|
|
@@ -58,20 +84,57 @@ Reports (default: last 30 days)
|
|
|
58
84
|
search: --page, --page-contains, --goal, --referrer,
|
|
59
85
|
--channel, --source, --utm-source, --utm-medium,
|
|
60
86
|
--utm-campaign, --country, --device, --browser, --os,
|
|
61
|
-
--visits-gt <n>, --visits-lt <n> (visits in the period)
|
|
62
|
-
|
|
87
|
+
--visits-gt <n>, --visits-lt <n> (visits in the period);
|
|
88
|
+
same visit: one of --visit-source, --visit-channel,
|
|
89
|
+
--visit-campaign, --visit-referrer, --visit-entry-page
|
|
90
|
+
and/or one of --visit-page, --visit-page-contains,
|
|
91
|
+
--visit-goal (adds a Matched visit column);
|
|
92
|
+
--trait <key=value[,value]>: latest identify trait
|
|
93
|
+
visitors traits Revenue, customers and purchase rate per value of one
|
|
94
|
+
identify trait (--key <trait>; needs visitor details)
|
|
95
|
+
visitors get <visitor_id> One visitor's journey (needs visitor details access);
|
|
96
|
+
--visit <ISO time>: only the visit containing that time
|
|
63
97
|
funnels list Saved funnels
|
|
98
|
+
funnels create --name --steps Save a funnel (needs write access); steps: 1–8 of
|
|
99
|
+
visit, page:/path, page:=/path (exact), page:host/path,
|
|
100
|
+
event:goal_name, identify, payment
|
|
101
|
+
funnels update <funnel_id> [--name] [--steps]
|
|
102
|
+
funnels delete <funnel_id> Delete a funnel (asks first; --yes to skip)
|
|
103
|
+
funnels dropoff <id> --step N Who left after step N (--continued: who went on;
|
|
104
|
+
needs visitor details access); no ID: --steps
|
|
105
|
+
segments list Saved segments (needs visitor details access)
|
|
106
|
+
segments create --name --filter … Save a segment (needs write access)
|
|
107
|
+
segments update <segment_id> [--name] [--filter …] (filters replace all)
|
|
108
|
+
segments delete <segment_id> Delete a segment (asks first; --yes to skip)
|
|
64
109
|
goals list Goal display settings (name, colour, hidden)
|
|
65
110
|
goals set <goal> [--name <label>] [--color <hex|name>] [--description]
|
|
111
|
+
[--category conversion|engagement|none|default]
|
|
66
112
|
[--hidden | --visible] (needs write access, admin);
|
|
67
113
|
pass "" to clear a text field or colour
|
|
68
114
|
goals reset <goal> Back to the raw name, default colour, visible
|
|
69
115
|
goals colors Colours you can use
|
|
116
|
+
goals definitions Goals defined without code (page, link, button, form, file)
|
|
117
|
+
goals preview --page <path> | --link <site> [--link-path <path>] |
|
|
118
|
+
--click <text> | --form <id> | --download <file|.ext>:
|
|
119
|
+
visitors (and payers) it matched in the last 30 days
|
|
120
|
+
goals define <name> --page /pricing (* one part, ** any) | --link stripe.com
|
|
121
|
+
[--link-path /checkout/**] | --click "Start free trial" |
|
|
122
|
+
--form signup | --download .pdf (button, form and file
|
|
123
|
+
come from automatic events); previews, then asks (--yes)
|
|
124
|
+
goals undefine <name> Delete a goal defined without code; says what uses it
|
|
70
125
|
goals delete-events Delete goal events: --goal <name>, --visitor <id>,
|
|
71
126
|
--user <id>, --from/--to <day> (counts, then asks;
|
|
72
127
|
--yes to skip, --dry-run to only count; needs write)
|
|
73
128
|
payments delete Delete payments: --transaction <id>, --visitor <id>,
|
|
74
129
|
--user <id>, --from/--to <day> (same confirmation)
|
|
130
|
+
events list Raw pageviews and goal events, newest first (needs
|
|
131
|
+
visitor details access): --type pageview,event,
|
|
132
|
+
engagement, --goal <name>, --visitor, --user
|
|
133
|
+
payments list Raw payments with first-touch channel, source and
|
|
134
|
+
customer; refunds and trials flagged: --transaction,
|
|
135
|
+
--visitor, --user
|
|
136
|
+
Both: -n/--limit (1–1000), --cursor <next>, --all
|
|
137
|
+
(follow every page, up to 100,000 rows), --csv
|
|
75
138
|
notes list Chart notes in the period
|
|
76
139
|
notes add --text [--date] Add a chart note (needs write access)
|
|
77
140
|
mentions X and Reddit posts mentioning the website (Growth);
|
|
@@ -121,12 +184,22 @@ Period and filters
|
|
|
121
184
|
-p, --period <p> today, yesterday, 24h, 7d, 30d, 90d, 6m, 1y, wtd, mtd, all
|
|
122
185
|
--from, --to <date> Custom days, YYYY-MM-DD (inclusive)
|
|
123
186
|
-z, --timezone <zone> IANA zone for day boundaries, e.g. Europe/Madrid (default UTC)
|
|
124
|
-
--compare <c> Change figures against: previous (default),
|
|
125
|
-
(same
|
|
126
|
-
|
|
127
|
-
|
|
187
|
+
--compare <c> Change figures against: previous (default), weekdays
|
|
188
|
+
(same length, whole weeks earlier so Mondays match
|
|
189
|
+
Mondays), year (same period last year), a YYYY-MM-DD
|
|
190
|
+
start, or off (no comparison: no change column,
|
|
191
|
+
none in --json)
|
|
192
|
+
-f, --filter <dim:op:value> Repeatable. Ops: is, is_not, contains, not_contains,
|
|
193
|
+
starts_with, ends_with, regex, not_regex (quote
|
|
194
|
+
regexes: -f 'page:regex:^/blog/'); is_empty and
|
|
195
|
+
is_not_empty take no value: -f utmCampaign:is_empty;
|
|
128
196
|
gt, lt for visits. e.g. -f country:is:US
|
|
129
197
|
-f page:contains:/blog -f visits:gt:2
|
|
198
|
+
URL parameters name the parameter after a dot:
|
|
199
|
+
-f urlParam.plan:is:pro
|
|
200
|
+
Event properties name the property, and optionally
|
|
201
|
+
the goal after @ (names with : or @ can't be used):
|
|
202
|
+
-f prop.plan:is:growth -f prop.experiment@signup:is:B
|
|
130
203
|
Revenue also takes plan, currency, paymentType
|
|
131
204
|
(new|renewal), refund (none|partial|refunded) and
|
|
132
205
|
provider: -f plan:is:Pro -f paymentType:is:renewal
|
|
@@ -135,7 +208,9 @@ Period and filters
|
|
|
135
208
|
with is or is_not: -f model:is:claude
|
|
136
209
|
|
|
137
210
|
List options
|
|
138
|
-
--sort, --order asc|desc (breakdown),
|
|
211
|
+
--sort, --order asc|desc, --param <name> (breakdown), --attribution, --group, --folder
|
|
212
|
+
(breakdown page), --include errors (breakdown page), --path, --funnel, --steps,
|
|
213
|
+
--drop-step (analytics errors), -n/--limit, --offset, --q (search),
|
|
139
214
|
--payment all|paid|unpaid
|
|
140
215
|
|
|
141
216
|
Global
|
package/dist/range.js
CHANGED
|
@@ -116,18 +116,30 @@ export function calendarDate(date, timeZone = "UTC") {
|
|
|
116
116
|
return `${w.y}-${String(w.m).padStart(2, "0")}-${String(w.d).padStart(2, "0")}`;
|
|
117
117
|
}
|
|
118
118
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
119
|
+
* Whole weeks the "weekdays" comparison starts before the range (at least 1), matching
|
|
120
|
+
* @metricraven/core/compare: rounded up so it never overlaps; the hour absorbs 25-hour DST days.
|
|
121
|
+
*/
|
|
122
|
+
export function matchingWeeks(from, to) {
|
|
123
|
+
return Math.max(1, Math.ceil((to.getTime() - from.getTime() - 3_600_000) / (7 * DAY)));
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Start of the comparison window (`--compare`), matching @metricraven/core/compare: "weekdays" is
|
|
127
|
+
* the same weekday a whole number of weeks earlier (at least the range's length), "year" is the
|
|
128
|
+
* same calendar day a year earlier (29 Feb → 28 Feb), a YYYY-MM-DD is that day; all keep the
|
|
121
129
|
* range's time of day. "previous" (the default) and "off" return null. Undefined for bad input.
|
|
122
130
|
*/
|
|
123
|
-
export function compareStartFor(value, from, timeZone = "UTC") {
|
|
131
|
+
export function compareStartFor(value, from, timeZone = "UTC", to) {
|
|
124
132
|
if (value === "previous" || value === "off")
|
|
125
133
|
return null;
|
|
134
|
+
if (value === "weekdays" && !to)
|
|
135
|
+
return null;
|
|
126
136
|
const day = calendarDate(from, timeZone);
|
|
127
137
|
const [y, m, d] = day.split("-").map(Number);
|
|
128
138
|
let target;
|
|
129
139
|
if (value === "year")
|
|
130
140
|
target = { y: y - 1, m, d: Math.min(d, new Date(Date.UTC(y - 1, m, 0)).getUTCDate()) };
|
|
141
|
+
else if (value === "weekdays")
|
|
142
|
+
target = addDays({ y, m, d }, -7 * matchingWeeks(from, to));
|
|
131
143
|
else
|
|
132
144
|
target = parseDate(value);
|
|
133
145
|
if (!target)
|
package/package.json
CHANGED