google-analytics-cli 0.1.0rc1__py3-none-any.whl
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.
- ga_cli/__init__.py +8 -0
- ga_cli/api/__init__.py +0 -0
- ga_cli/api/client.py +142 -0
- ga_cli/auth/__init__.py +35 -0
- ga_cli/auth/credentials.py +126 -0
- ga_cli/auth/oauth.py +322 -0
- ga_cli/auth/service_account.py +155 -0
- ga_cli/commands/__init__.py +0 -0
- ga_cli/commands/access_bindings.py +254 -0
- ga_cli/commands/access_reports.py +201 -0
- ga_cli/commands/account_summaries.py +68 -0
- ga_cli/commands/accounts.py +297 -0
- ga_cli/commands/agent_cmd.py +776 -0
- ga_cli/commands/annotations.py +264 -0
- ga_cli/commands/audiences.py +223 -0
- ga_cli/commands/auth_cmd.py +205 -0
- ga_cli/commands/bigquery_links.py +309 -0
- ga_cli/commands/calculated_metrics.py +312 -0
- ga_cli/commands/channel_groups.py +223 -0
- ga_cli/commands/completions_cmd.py +55 -0
- ga_cli/commands/config_cmd.py +113 -0
- ga_cli/commands/custom_dimensions.py +272 -0
- ga_cli/commands/custom_metrics.py +305 -0
- ga_cli/commands/data_retention.py +153 -0
- ga_cli/commands/data_streams.py +277 -0
- ga_cli/commands/event_create_rules.py +250 -0
- ga_cli/commands/event_edit_rules.py +292 -0
- ga_cli/commands/firebase_links.py +142 -0
- ga_cli/commands/google_ads_links.py +225 -0
- ga_cli/commands/key_events.py +269 -0
- ga_cli/commands/mp_secrets.py +265 -0
- ga_cli/commands/properties.py +330 -0
- ga_cli/commands/property_settings.py +287 -0
- ga_cli/commands/reports.py +726 -0
- ga_cli/commands/upgrade_cmd.py +148 -0
- ga_cli/config/__init__.py +0 -0
- ga_cli/config/constants.py +61 -0
- ga_cli/config/store.py +115 -0
- ga_cli/main.py +110 -0
- ga_cli/utils/__init__.py +20 -0
- ga_cli/utils/describe.py +129 -0
- ga_cli/utils/dry_run.py +40 -0
- ga_cli/utils/errors.py +150 -0
- ga_cli/utils/output.py +209 -0
- ga_cli/utils/pagination.py +93 -0
- google_analytics_cli-0.1.0rc1.dist-info/METADATA +269 -0
- google_analytics_cli-0.1.0rc1.dist-info/RECORD +49 -0
- google_analytics_cli-0.1.0rc1.dist-info/WHEEL +4 -0
- google_analytics_cli-0.1.0rc1.dist-info/entry_points.txt +2 -0
|
@@ -0,0 +1,776 @@
|
|
|
1
|
+
"""Agent guide command: prints a concise reference for AI agents using the GA CLI."""
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
|
|
7
|
+
agent_app = typer.Typer(name="agent", help="AI agent utilities", no_args_is_help=True)
|
|
8
|
+
|
|
9
|
+
# ---------------------------------------------------------------------------
|
|
10
|
+
# Section content
|
|
11
|
+
# ---------------------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
_SECTION_OVERVIEW = r"""# GA CLI — AI Agent Quick Reference
|
|
14
|
+
|
|
15
|
+
## Prerequisites
|
|
16
|
+
GA CLI requires your own GCP OAuth credentials. Run `ga agent guide --section setup` for
|
|
17
|
+
step-by-step instructions on creating a GCP project and OAuth client.
|
|
18
|
+
|
|
19
|
+
## Setup
|
|
20
|
+
```bash
|
|
21
|
+
ga auth login # OAuth (interactive)
|
|
22
|
+
ga auth login --service-account /path/key.json # Service account (non-interactive)
|
|
23
|
+
ga config set default_account_id 123456789
|
|
24
|
+
ga config set default_property_id 987654321
|
|
25
|
+
ga config set output_format json # Recommended for agents
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Global Flags
|
|
29
|
+
| Flag | Effect |
|
|
30
|
+
|------|--------|
|
|
31
|
+
| `-o json` | Machine-readable output |
|
|
32
|
+
| `-o compact` | Minimal output |
|
|
33
|
+
| `--quiet` / `-q` | Suppress info/warnings (errors still shown) |
|
|
34
|
+
| `--no-color` | Disable colored output |
|
|
35
|
+
| `--yes` / `-y` | Skip confirmation prompts |
|
|
36
|
+
| `--describe` | Output full CLI schema as JSON (all commands, parameters, types) |
|
|
37
|
+
| `--dry-run` | Preview mutative requests without executing (on create/update/delete commands) |
|
|
38
|
+
|
|
39
|
+
## Resource Hierarchy
|
|
40
|
+
```
|
|
41
|
+
Account → Property → Data Stream (Web / Android / iOS)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Command Reference
|
|
45
|
+
|
|
46
|
+
### Auth
|
|
47
|
+
```bash
|
|
48
|
+
ga auth login [--service-account PATH]
|
|
49
|
+
ga auth logout
|
|
50
|
+
ga auth status [-o json]
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Config
|
|
54
|
+
```bash
|
|
55
|
+
ga config get [KEY]
|
|
56
|
+
ga config set KEY VALUE
|
|
57
|
+
ga config unset KEY
|
|
58
|
+
ga config setup # Interactive wizard
|
|
59
|
+
ga config reset
|
|
60
|
+
```
|
|
61
|
+
Keys: `default_account_id`, `default_property_id`, `output_format`
|
|
62
|
+
|
|
63
|
+
### Accounts
|
|
64
|
+
```bash
|
|
65
|
+
ga accounts list [-o json]
|
|
66
|
+
ga accounts get -a ACCOUNT_ID [-o json]
|
|
67
|
+
ga accounts update -a ACCOUNT_ID --name "Name"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Account Summaries
|
|
71
|
+
```bash
|
|
72
|
+
ga account-summaries list [-o json]
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Properties
|
|
76
|
+
```bash
|
|
77
|
+
ga properties list [-a ACCOUNT_ID] [-o json]
|
|
78
|
+
ga properties get [-p PROPERTY_ID] [-o json]
|
|
79
|
+
ga properties create -a ACCOUNT_ID --name "Name" [--timezone TZ] [--currency CODE]
|
|
80
|
+
ga properties update -p PROPERTY_ID [--name NAME] [--timezone TZ] [--currency CODE] [--industry CAT]
|
|
81
|
+
ga properties delete -p PROPERTY_ID --yes
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Custom Dimensions
|
|
85
|
+
```bash
|
|
86
|
+
ga custom-dimensions list [-p PROPERTY_ID] [-o json]
|
|
87
|
+
ga custom-dimensions get -p PROPERTY_ID -d DIMENSION_ID [-o json]
|
|
88
|
+
ga custom-dimensions create -p PROPERTY_ID --parameter-name NAME --display-name NAME --scope EVENT|USER|ITEM
|
|
89
|
+
ga custom-dimensions update -p PROPERTY_ID -d DIMENSION_ID [--display-name NAME] [--description TEXT]
|
|
90
|
+
ga custom-dimensions archive -p PROPERTY_ID -d DIMENSION_ID --yes
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Custom Metrics
|
|
94
|
+
```bash
|
|
95
|
+
ga custom-metrics list [-p PROPERTY_ID] [-o json]
|
|
96
|
+
ga custom-metrics get -p PROPERTY_ID -m METRIC_ID [-o json]
|
|
97
|
+
ga custom-metrics create -p PROPERTY_ID --parameter-name NAME --display-name NAME --scope EVENT --measurement-unit UNIT
|
|
98
|
+
ga custom-metrics update -p PROPERTY_ID -m METRIC_ID [--display-name NAME] [--measurement-unit UNIT]
|
|
99
|
+
ga custom-metrics archive -p PROPERTY_ID -m METRIC_ID --yes
|
|
100
|
+
```
|
|
101
|
+
Measurement units: `STANDARD`, `CURRENCY`, `FEET`, `METERS`, `KILOMETERS`, `MILES`, `MILLISECONDS`, `SECONDS`, `MINUTES`, `HOURS`
|
|
102
|
+
|
|
103
|
+
### Key Events
|
|
104
|
+
```bash
|
|
105
|
+
ga key-events list [-p PROPERTY_ID] [-o json]
|
|
106
|
+
ga key-events get -p PROPERTY_ID -k KEY_EVENT_ID [-o json]
|
|
107
|
+
ga key-events create -p PROPERTY_ID --event-name NAME [--counting-method ONCE_PER_EVENT|ONCE_PER_SESSION]
|
|
108
|
+
ga key-events update -p PROPERTY_ID -k KEY_EVENT_ID --counting-method METHOD
|
|
109
|
+
ga key-events delete -p PROPERTY_ID -k KEY_EVENT_ID --yes
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Data Streams
|
|
113
|
+
```bash
|
|
114
|
+
ga data-streams list [-p PROPERTY_ID] [-o json]
|
|
115
|
+
ga data-streams get -p PROPERTY_ID -s STREAM_ID [-o json]
|
|
116
|
+
ga data-streams create -p PROPERTY_ID --display-name "Name" [--type TYPE] [--url URL] [--bundle-id ID]
|
|
117
|
+
ga data-streams update -p PROPERTY_ID -s STREAM_ID [--display-name NAME]
|
|
118
|
+
ga data-streams delete -p PROPERTY_ID -s STREAM_ID --yes
|
|
119
|
+
```
|
|
120
|
+
Types: `WEB_DATA_STREAM` (requires `--url`), `ANDROID_APP_DATA_STREAM` / `IOS_APP_DATA_STREAM` (require `--bundle-id`)
|
|
121
|
+
|
|
122
|
+
### Measurement Protocol Secrets
|
|
123
|
+
```bash
|
|
124
|
+
ga mp-secrets list -p PROPERTY_ID -s STREAM_ID [-o json]
|
|
125
|
+
ga mp-secrets get -p PROPERTY_ID -s STREAM_ID --secret-id SECRET_ID [-o json]
|
|
126
|
+
ga mp-secrets create -p PROPERTY_ID -s STREAM_ID --display-name "Name" [-o json]
|
|
127
|
+
ga mp-secrets update -p PROPERTY_ID -s STREAM_ID --secret-id SECRET_ID [--display-name NAME]
|
|
128
|
+
ga mp-secrets delete -p PROPERTY_ID -s STREAM_ID --secret-id SECRET_ID --yes
|
|
129
|
+
```
|
|
130
|
+
Requires both `--property-id` and `--stream-id`. The API auto-generates the secret value on create.
|
|
131
|
+
|
|
132
|
+
### Google Ads Links
|
|
133
|
+
```bash
|
|
134
|
+
ga google-ads-links list [-p PROPERTY_ID] [-o json]
|
|
135
|
+
ga google-ads-links create -p PROPERTY_ID --customer-id ID [--no-ads-personalization]
|
|
136
|
+
ga google-ads-links update -p PROPERTY_ID --link-id ID [--ads-personalization|--no-ads-personalization]
|
|
137
|
+
ga google-ads-links delete -p PROPERTY_ID --link-id ID --yes
|
|
138
|
+
```
|
|
139
|
+
No `get` method — use `list` to view links.
|
|
140
|
+
|
|
141
|
+
### Firebase Links
|
|
142
|
+
```bash
|
|
143
|
+
ga firebase-links list [-p PROPERTY_ID] [-o json]
|
|
144
|
+
ga firebase-links create -p PROPERTY_ID --project "projects/FIREBASE_PROJECT"
|
|
145
|
+
ga firebase-links delete -p PROPERTY_ID --link-id ID --yes
|
|
146
|
+
```
|
|
147
|
+
No `get` or `update` methods. A property can have at most one Firebase link.
|
|
148
|
+
|
|
149
|
+
### Access Bindings (alpha)
|
|
150
|
+
```bash
|
|
151
|
+
ga access-bindings list (-a ACCOUNT_ID | -p PROPERTY_ID) [-o json]
|
|
152
|
+
ga access-bindings get (-a ACCOUNT_ID | -p PROPERTY_ID) -b BINDING_ID [-o json]
|
|
153
|
+
ga access-bindings create (-a ACCOUNT_ID | -p PROPERTY_ID) --user EMAIL --roles viewer,editor [-o json]
|
|
154
|
+
ga access-bindings update (-a ACCOUNT_ID | -p PROPERTY_ID) -b BINDING_ID --roles viewer [-o json]
|
|
155
|
+
ga access-bindings delete (-a ACCOUNT_ID | -p PROPERTY_ID) -b BINDING_ID --yes
|
|
156
|
+
```
|
|
157
|
+
Requires either `--account-id` or `--property-id` (not both). Roles: viewer, analyst, editor, admin, no-cost-data, no-revenue-data.
|
|
158
|
+
|
|
159
|
+
### Annotations (alpha)
|
|
160
|
+
```bash
|
|
161
|
+
ga annotations list [-p PROPERTY_ID] [-o json]
|
|
162
|
+
ga annotations get -p PROPERTY_ID -a ANNOTATION_ID [-o json]
|
|
163
|
+
ga annotations create -p PROPERTY_ID --title TEXT --annotation-date YYYY-MM-DD [--description TEXT] [--color COLOR]
|
|
164
|
+
ga annotations update -p PROPERTY_ID -a ANNOTATION_ID [--title TEXT] [--description TEXT] [--color COLOR]
|
|
165
|
+
ga annotations delete -p PROPERTY_ID -a ANNOTATION_ID --yes
|
|
166
|
+
```
|
|
167
|
+
Mark dates on reports with contextual notes (e.g., launches, campaigns).
|
|
168
|
+
|
|
169
|
+
### Audiences (alpha)
|
|
170
|
+
```bash
|
|
171
|
+
ga audiences list [-p PROPERTY_ID] [-o json]
|
|
172
|
+
ga audiences get -p PROPERTY_ID -a AUDIENCE_ID [-o json]
|
|
173
|
+
ga audiences create -p PROPERTY_ID --config audience.json [-o json]
|
|
174
|
+
ga audiences update -p PROPERTY_ID -a AUDIENCE_ID --config update.json [-o json]
|
|
175
|
+
ga audiences archive -p PROPERTY_ID -a AUDIENCE_ID --yes
|
|
176
|
+
```
|
|
177
|
+
Create/update use `--config` JSON file (complex filter clauses). Only `displayName`, `description`, and `eventTrigger` can be updated. Uses `archive` instead of `delete`.
|
|
178
|
+
|
|
179
|
+
### BigQuery Links (alpha)
|
|
180
|
+
```bash
|
|
181
|
+
ga bigquery-links list [-p PROPERTY_ID] [-o json]
|
|
182
|
+
ga bigquery-links get -p PROPERTY_ID -l LINK_ID [-o json]
|
|
183
|
+
ga bigquery-links create -p PROPERTY_ID --project PROJECT --dataset-location LOC [--daily-export] [--streaming-export] [--export-streams IDS] [--excluded-events EVENTS]
|
|
184
|
+
ga bigquery-links update -p PROPERTY_ID -l LINK_ID [--daily-export|--no-daily-export] [--streaming-export|--no-streaming-export] [--export-streams IDS] [--excluded-events EVENTS]
|
|
185
|
+
ga bigquery-links delete -p PROPERTY_ID -l LINK_ID --yes
|
|
186
|
+
```
|
|
187
|
+
`--project` and `--dataset-location` are immutable (set at creation only). `--export-streams` accepts comma-separated stream IDs; `--excluded-events` accepts comma-separated event names.
|
|
188
|
+
|
|
189
|
+
### Channel Groups (alpha)
|
|
190
|
+
```bash
|
|
191
|
+
ga channel-groups list [-p PROPERTY_ID] [-o json]
|
|
192
|
+
ga channel-groups get -p PROPERTY_ID -g GROUP_ID [-o json]
|
|
193
|
+
ga channel-groups create -p PROPERTY_ID --config channel_group.json [-o json]
|
|
194
|
+
ga channel-groups update -p PROPERTY_ID -g GROUP_ID --config update.json [-o json]
|
|
195
|
+
ga channel-groups delete -p PROPERTY_ID -g GROUP_ID --yes
|
|
196
|
+
```
|
|
197
|
+
Create/update use `--config` JSON file (complex grouping rules with filter expressions). Max 50 rules per group.
|
|
198
|
+
|
|
199
|
+
### Calculated Metrics (alpha)
|
|
200
|
+
```bash
|
|
201
|
+
ga calculated-metrics list [-p PROPERTY_ID] [-o json]
|
|
202
|
+
ga calculated-metrics get -p PROPERTY_ID -m METRIC_ID [-o json]
|
|
203
|
+
ga calculated-metrics create -p PROPERTY_ID --calculated-metric-id ID --display-name NAME --formula FORMULA --metric-unit UNIT [--description TEXT]
|
|
204
|
+
ga calculated-metrics update -p PROPERTY_ID -m METRIC_ID [--display-name NAME] [--formula FORMULA] [--metric-unit UNIT] [--description TEXT]
|
|
205
|
+
ga calculated-metrics delete -p PROPERTY_ID -m METRIC_ID --yes
|
|
206
|
+
```
|
|
207
|
+
Metric units: `STANDARD`, `CURRENCY`, `FEET`, `METERS`, `KILOMETERS`, `MILES`, `MILLISECONDS`, `SECONDS`, `MINUTES`, `HOURS`
|
|
208
|
+
|
|
209
|
+
### Event Create Rules (alpha)
|
|
210
|
+
```bash
|
|
211
|
+
ga event-create-rules list -p PROPERTY_ID -s STREAM_ID [-o json]
|
|
212
|
+
ga event-create-rules get -p PROPERTY_ID -s STREAM_ID -r RULE_ID [-o json]
|
|
213
|
+
ga event-create-rules create -p PROPERTY_ID -s STREAM_ID --config rule.json [-o json]
|
|
214
|
+
ga event-create-rules update -p PROPERTY_ID -s STREAM_ID -r RULE_ID --config update.json [-o json]
|
|
215
|
+
ga event-create-rules delete -p PROPERTY_ID -s STREAM_ID -r RULE_ID --yes
|
|
216
|
+
```
|
|
217
|
+
Requires both `--property-id` and `--stream-id`. Create/update use `--config` JSON with `destinationEvent`, `eventConditions`, `sourceCopyParameters`, and `parameterMutations`.
|
|
218
|
+
|
|
219
|
+
### Event Edit Rules (alpha)
|
|
220
|
+
```bash
|
|
221
|
+
ga event-edit-rules list -p PROPERTY_ID -s STREAM_ID [-o json]
|
|
222
|
+
ga event-edit-rules get -p PROPERTY_ID -s STREAM_ID -r RULE_ID [-o json]
|
|
223
|
+
ga event-edit-rules create -p PROPERTY_ID -s STREAM_ID --config rule.json [-o json]
|
|
224
|
+
ga event-edit-rules update -p PROPERTY_ID -s STREAM_ID -r RULE_ID --config update.json [-o json]
|
|
225
|
+
ga event-edit-rules delete -p PROPERTY_ID -s STREAM_ID -r RULE_ID --yes
|
|
226
|
+
ga event-edit-rules reorder -p PROPERTY_ID -s STREAM_ID --rule-ids r1,r2,r3
|
|
227
|
+
```
|
|
228
|
+
Requires both `--property-id` and `--stream-id`. Create/update use `--config` JSON with `displayName`, `eventConditions`, and `parameterMutations`. Reorder requires all rule IDs in desired processing order.
|
|
229
|
+
|
|
230
|
+
### Property Settings (alpha)
|
|
231
|
+
```bash
|
|
232
|
+
ga property-settings attribution [-p PROPERTY_ID] [--attribution-model MODEL] [--acquisition-lookback VAL] [--other-lookback VAL] [--ads-export-scope VAL] [-o json]
|
|
233
|
+
ga property-settings google-signals [-p PROPERTY_ID] [--state GOOGLE_SIGNALS_ENABLED|GOOGLE_SIGNALS_DISABLED] [-o json]
|
|
234
|
+
ga property-settings enhanced-measurement [-p PROPERTY_ID] -s STREAM_ID [--scrolls/--no-scrolls] [--outbound-clicks/--no-outbound-clicks] [...] [-o json]
|
|
235
|
+
```
|
|
236
|
+
Get/set hybrid: no update flags = GET, any update flag = PATCH. Enhanced measurement requires `--stream-id`.
|
|
237
|
+
|
|
238
|
+
### Reports
|
|
239
|
+
```bash
|
|
240
|
+
ga reports run [-p PROPERTY_ID] -m metrics -d dimensions --start-date DATE --end-date DATE [--limit N] [-o json]
|
|
241
|
+
ga reports pivot [-p PROPERTY_ID] -m metrics -d dimensions --pivot-field FIELD [--start-date DATE] [-o json]
|
|
242
|
+
ga reports check-compatibility [-p PROPERTY_ID] [-m metrics] [-d dimensions] [-o json]
|
|
243
|
+
ga reports metadata [-p PROPERTY_ID] [--type metrics|dimensions] [--search TEXT] [-o json]
|
|
244
|
+
ga reports realtime [-p PROPERTY_ID] [-m metrics] [-d dimensions] [--interval SECONDS]
|
|
245
|
+
```
|
|
246
|
+
Dates: `today`, `yesterday`, `7daysAgo`, `30daysAgo`, `90daysAgo`, or `YYYY-MM-DD`
|
|
247
|
+
|
|
248
|
+
### Upgrade
|
|
249
|
+
```bash
|
|
250
|
+
ga upgrade [--check] [--force]
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Completions
|
|
254
|
+
```bash
|
|
255
|
+
ga completions bash|zsh|fish
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Environment Variables
|
|
259
|
+
| Variable | Purpose |
|
|
260
|
+
|----------|---------|
|
|
261
|
+
| `GA_CLI_SERVICE_ACCOUNT` | Service account key path (non-interactive auth) |
|
|
262
|
+
| `GOOGLE_APPLICATION_CREDENTIALS` | GCP credential path (fallback) |
|
|
263
|
+
| `GA_CLI_CONFIG_DIR` | Override config directory |
|
|
264
|
+
| `NO_COLOR` | Disable colored output |
|
|
265
|
+
|
|
266
|
+
## Agent Workflow
|
|
267
|
+
Typical discover → act pattern:
|
|
268
|
+
```bash
|
|
269
|
+
# 0. Introspect: discover all commands, parameters, and types in one call
|
|
270
|
+
ga --describe | jq '.commands["ga properties create"]'
|
|
271
|
+
|
|
272
|
+
# 1. Discover: find the right IDs
|
|
273
|
+
ACCT=$(ga accounts list -o json | jq -r '.[0].name' | grep -o '[0-9]*$')
|
|
274
|
+
ga config set default_account_id "$ACCT"
|
|
275
|
+
|
|
276
|
+
PROP=$(ga properties list -o json | jq -r '.[0].name' | grep -o '[0-9]*$')
|
|
277
|
+
ga config set default_property_id "$PROP"
|
|
278
|
+
|
|
279
|
+
# 2. Preview: dry-run a mutation to verify parameters
|
|
280
|
+
ga properties create -a "$ACCT" --name "New Site" --timezone Europe/Berlin --dry-run
|
|
281
|
+
|
|
282
|
+
# 3. Act: run reports, create resources, etc.
|
|
283
|
+
ga reports run -m sessions,users -d date --start-date 7daysAgo -o json
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Extracting IDs from JSON output
|
|
287
|
+
```bash
|
|
288
|
+
# Account ID from account name "accounts/123456789"
|
|
289
|
+
ga accounts list -o json | jq -r '.[].name' | grep -o '[0-9]*$'
|
|
290
|
+
|
|
291
|
+
# Property ID
|
|
292
|
+
ga properties list -o json | jq -r '.[].name' | grep -o '[0-9]*$'
|
|
293
|
+
|
|
294
|
+
# Stream ID
|
|
295
|
+
ga data-streams list -o json | jq -r '.[].name' | grep -o '[0-9]*$'
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
## Agent Best Practices
|
|
299
|
+
- **Start with `ga --describe`** — discover every command, parameter, type, and flag in one JSON call; cache the result
|
|
300
|
+
- **Use `--dry-run` before mutations** — preview the exact API request before executing creates, updates, and deletes
|
|
301
|
+
- **Set defaults first** — eliminates repetitive `--account-id` / `--property-id` flags from every command
|
|
302
|
+
- **Always use `-o json`** — structured output is easier to parse than tables
|
|
303
|
+
- **Use `check-compatibility` before complex reports** — avoids API errors from incompatible metric/dimension combos
|
|
304
|
+
- **Use `metadata` to discover available metrics/dimensions** — `ga reports metadata -p ID --search revenue -o json`
|
|
305
|
+
- **Parallelize independent operations** — run creates/deletes concurrently with `&` and `wait`
|
|
306
|
+
- **Avoid interactive commands** — skip `ga config setup` and `ga reports build`; use explicit flags instead
|
|
307
|
+
|
|
308
|
+
## Troubleshooting
|
|
309
|
+
|
|
310
|
+
| Error | Cause | Fix |
|
|
311
|
+
|-------|-------|-----|
|
|
312
|
+
| "Not authenticated" | No valid credentials | `ga auth login` |
|
|
313
|
+
| "Missing required option: property_id" | No `--property-id` and no default | `ga config set default_property_id ID` |
|
|
314
|
+
| "HttpError 403: …permission" | Account lacks GA4 access | Verify account/property IDs and permissions |
|
|
315
|
+
| "--url is required for WEB_DATA_STREAM" | Missing URL for web stream | Add `--url "https://…"` |
|
|
316
|
+
| "--bundle-id is required for …APP…" | Missing bundle ID for app stream | Add `--bundle-id "com.example.app"` |
|
|
317
|
+
|
|
318
|
+
Debugging steps: `ga auth status -o json` → `ga config get` → `ga accounts list -o json` → `ga properties list -o json`
|
|
319
|
+
|
|
320
|
+
Use `ga agent guide --section SECTION` for details on: `setup`, `reports`, `admin`, `examples`
|
|
321
|
+
"""
|
|
322
|
+
|
|
323
|
+
_SECTION_REPORTS = r"""# Reports — Detailed Reference
|
|
324
|
+
|
|
325
|
+
## Common Metrics
|
|
326
|
+
| Metric | Description |
|
|
327
|
+
|--------|-------------|
|
|
328
|
+
| `sessions` | Total sessions |
|
|
329
|
+
| `users` | Total users |
|
|
330
|
+
| `newUsers` | New users |
|
|
331
|
+
| `screenPageViews` | Page/screen views |
|
|
332
|
+
| `eventCount` | Total events |
|
|
333
|
+
| `engagementRate` | Engaged sessions ratio |
|
|
334
|
+
| `averageSessionDuration` | Avg session duration (seconds) |
|
|
335
|
+
| `conversions` | Total conversions |
|
|
336
|
+
| `totalRevenue` | Total revenue |
|
|
337
|
+
| `activeUsers` | Active users (realtime only) |
|
|
338
|
+
|
|
339
|
+
## Common Dimensions
|
|
340
|
+
| Dimension | Description |
|
|
341
|
+
|-----------|-------------|
|
|
342
|
+
| `date` | Date (YYYYMMDD) |
|
|
343
|
+
| `country` | User country |
|
|
344
|
+
| `city` | User city |
|
|
345
|
+
| `deviceCategory` | desktop, mobile, tablet |
|
|
346
|
+
| `operatingSystem` | OS name |
|
|
347
|
+
| `browser` | Browser name |
|
|
348
|
+
| `sourceMedium` | Traffic source / medium |
|
|
349
|
+
| `sessionDefaultChannelGroup` | Channel grouping |
|
|
350
|
+
| `pagePath` | Page URL path |
|
|
351
|
+
| `pageTitle` | Page title |
|
|
352
|
+
|
|
353
|
+
## Pivot Reports
|
|
354
|
+
The `--pivot-field` must be one of the `--dimensions`. It becomes column headers in table output.
|
|
355
|
+
```bash
|
|
356
|
+
ga reports pivot -p 987654321 -m sessions,users -d country,deviceCategory --pivot-field deviceCategory --start-date 7daysAgo -o json
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
## Compatibility Check
|
|
360
|
+
Verify dimensions and metrics can be used together before running a report:
|
|
361
|
+
```bash
|
|
362
|
+
ga reports check-compatibility -p 987654321 -m sessions,conversions -d date,city -o json
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
## Real-Time Reports
|
|
366
|
+
Only support a subset of metrics (e.g., `activeUsers`). No date ranges.
|
|
367
|
+
```bash
|
|
368
|
+
ga reports realtime -p 987654321 -m activeUsers -d country -o json
|
|
369
|
+
ga reports realtime -p 987654321 --interval 10 # Poll every 10s
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
## Metadata
|
|
373
|
+
Browse available metrics and dimensions for a property:
|
|
374
|
+
```bash
|
|
375
|
+
ga reports metadata -p 987654321 -o json # All metrics and dimensions
|
|
376
|
+
ga reports metadata -p 987654321 --type metrics -o json # Only metrics
|
|
377
|
+
ga reports metadata -p 987654321 --search page -o json # Search by name
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
## Funnel Reports (v1alpha)
|
|
381
|
+
Run funnel analysis using a JSON config file with step definitions:
|
|
382
|
+
```bash
|
|
383
|
+
ga reports funnel -p 987654321 -c funnel_config.json -o json
|
|
384
|
+
ga reports funnel -p 987654321 -c funnel_config.json # Table output
|
|
385
|
+
```
|
|
386
|
+
- Config JSON is passed as the full request body (minus `property`)
|
|
387
|
+
- Must contain a `funnel` object with a non-empty `steps` array
|
|
388
|
+
- Date ranges go in the config JSON (no `--start-date`/`--end-date` flags)
|
|
389
|
+
- Table columns: Step Name, Active Users, Completion Rate, Abandonment Rate
|
|
390
|
+
|
|
391
|
+
**Note**: `ga reports build` requires interactive input — avoid in automation. Use `ga reports run` instead.
|
|
392
|
+
"""
|
|
393
|
+
|
|
394
|
+
_SECTION_ADMIN = r"""# Admin — Properties, Streams, Dimensions, Metrics, Key Events, Links & More
|
|
395
|
+
|
|
396
|
+
## Properties
|
|
397
|
+
```bash
|
|
398
|
+
ga properties list [-a ACCOUNT_ID] [-o json]
|
|
399
|
+
ga properties get [-p PROPERTY_ID] [-o json]
|
|
400
|
+
ga properties create -a ACCOUNT_ID --name "Name" [--timezone TZ] [--currency CODE]
|
|
401
|
+
ga properties update -p PROPERTY_ID [--name NAME] [--timezone TZ] [--currency CODE] [--industry CAT]
|
|
402
|
+
ga properties delete -p PROPERTY_ID --yes
|
|
403
|
+
ga properties quotas -p PROPERTY_ID [-o json]
|
|
404
|
+
```
|
|
405
|
+
- Updatable fields: `displayName`, `timeZone`, `currencyCode`, `industryCategory`
|
|
406
|
+
- `quotas` shows API quota usage (v1alpha Data API): Tokens Per Day/Hour, Concurrent Requests, etc.
|
|
407
|
+
|
|
408
|
+
## Custom Dimensions
|
|
409
|
+
```bash
|
|
410
|
+
ga custom-dimensions list [-p PROPERTY_ID] [-o json]
|
|
411
|
+
ga custom-dimensions get -p PROPERTY_ID -d DIMENSION_ID [-o json]
|
|
412
|
+
ga custom-dimensions create -p PROPERTY_ID --parameter-name NAME --display-name NAME --scope EVENT|USER|ITEM [--description TEXT]
|
|
413
|
+
ga custom-dimensions update -p PROPERTY_ID -d DIMENSION_ID [--display-name NAME] [--description TEXT]
|
|
414
|
+
ga custom-dimensions archive -p PROPERTY_ID -d DIMENSION_ID --yes
|
|
415
|
+
```
|
|
416
|
+
- Scopes: `EVENT`, `USER`, `ITEM`
|
|
417
|
+
- `parameterName` and `scope` cannot be changed after creation
|
|
418
|
+
|
|
419
|
+
## Custom Metrics
|
|
420
|
+
```bash
|
|
421
|
+
ga custom-metrics list [-p PROPERTY_ID] [-o json]
|
|
422
|
+
ga custom-metrics get -p PROPERTY_ID -m METRIC_ID [-o json]
|
|
423
|
+
ga custom-metrics create -p PROPERTY_ID --parameter-name NAME --display-name NAME --scope EVENT --measurement-unit UNIT
|
|
424
|
+
ga custom-metrics update -p PROPERTY_ID -m METRIC_ID [--display-name NAME] [--measurement-unit UNIT]
|
|
425
|
+
ga custom-metrics archive -p PROPERTY_ID -m METRIC_ID --yes
|
|
426
|
+
```
|
|
427
|
+
Measurement units: `STANDARD`, `CURRENCY`, `FEET`, `METERS`, `KILOMETERS`, `MILES`, `MILLISECONDS`, `SECONDS`, `MINUTES`, `HOURS`
|
|
428
|
+
|
|
429
|
+
## Key Events
|
|
430
|
+
Key events (formerly "conversions") mark significant user actions.
|
|
431
|
+
```bash
|
|
432
|
+
ga key-events list [-p PROPERTY_ID] [-o json]
|
|
433
|
+
ga key-events get -p PROPERTY_ID -k KEY_EVENT_ID [-o json]
|
|
434
|
+
ga key-events create -p PROPERTY_ID --event-name NAME [--counting-method ONCE_PER_EVENT|ONCE_PER_SESSION]
|
|
435
|
+
ga key-events update -p PROPERTY_ID -k KEY_EVENT_ID --counting-method METHOD
|
|
436
|
+
ga key-events delete -p PROPERTY_ID -k KEY_EVENT_ID --yes
|
|
437
|
+
```
|
|
438
|
+
Counting methods: `ONCE_PER_EVENT`, `ONCE_PER_SESSION`
|
|
439
|
+
|
|
440
|
+
## Data Streams
|
|
441
|
+
```bash
|
|
442
|
+
ga data-streams list [-p PROPERTY_ID] [-o json]
|
|
443
|
+
ga data-streams get -p PROPERTY_ID -s STREAM_ID [-o json]
|
|
444
|
+
ga data-streams create -p PROPERTY_ID --display-name "Name" [--type TYPE] [--url URL] [--bundle-id ID]
|
|
445
|
+
ga data-streams update -p PROPERTY_ID -s STREAM_ID [--display-name NAME]
|
|
446
|
+
ga data-streams delete -p PROPERTY_ID -s STREAM_ID --yes
|
|
447
|
+
```
|
|
448
|
+
| Type | Required Flag |
|
|
449
|
+
|------|--------------|
|
|
450
|
+
| `WEB_DATA_STREAM` (default) | `--url` |
|
|
451
|
+
| `ANDROID_APP_DATA_STREAM` | `--bundle-id` |
|
|
452
|
+
| `IOS_APP_DATA_STREAM` | `--bundle-id` |
|
|
453
|
+
|
|
454
|
+
## Measurement Protocol Secrets
|
|
455
|
+
Secrets for validating Measurement Protocol hits (server-side event collection).
|
|
456
|
+
```bash
|
|
457
|
+
ga mp-secrets list -p PROPERTY_ID -s STREAM_ID [-o json]
|
|
458
|
+
ga mp-secrets get -p PROPERTY_ID -s STREAM_ID --secret-id SECRET_ID [-o json]
|
|
459
|
+
ga mp-secrets create -p PROPERTY_ID -s STREAM_ID --display-name "Name" [-o json]
|
|
460
|
+
ga mp-secrets update -p PROPERTY_ID -s STREAM_ID --secret-id SECRET_ID [--display-name NAME]
|
|
461
|
+
ga mp-secrets delete -p PROPERTY_ID -s STREAM_ID --secret-id SECRET_ID --yes
|
|
462
|
+
```
|
|
463
|
+
- Nested under data streams: requires both `--property-id` and `--stream-id`
|
|
464
|
+
- Secret value is auto-generated by the API on create
|
|
465
|
+
- Only `displayName` can be updated
|
|
466
|
+
|
|
467
|
+
## Google Ads Links
|
|
468
|
+
```bash
|
|
469
|
+
ga google-ads-links list [-p PROPERTY_ID] [-o json]
|
|
470
|
+
ga google-ads-links create -p PROPERTY_ID --customer-id ID [--no-ads-personalization]
|
|
471
|
+
ga google-ads-links update -p PROPERTY_ID --link-id ID [--ads-personalization|--no-ads-personalization]
|
|
472
|
+
ga google-ads-links delete -p PROPERTY_ID --link-id ID --yes
|
|
473
|
+
```
|
|
474
|
+
- No `get` method — use `list` to see all links
|
|
475
|
+
- Only `adsPersonalizationEnabled` can be updated
|
|
476
|
+
|
|
477
|
+
## Firebase Links
|
|
478
|
+
```bash
|
|
479
|
+
ga firebase-links list [-p PROPERTY_ID] [-o json]
|
|
480
|
+
ga firebase-links create -p PROPERTY_ID --project "projects/FIREBASE_PROJECT"
|
|
481
|
+
ga firebase-links delete -p PROPERTY_ID --link-id ID --yes
|
|
482
|
+
```
|
|
483
|
+
- No `get` or `update` methods
|
|
484
|
+
- A property can have at most one Firebase link
|
|
485
|
+
|
|
486
|
+
## Access Bindings (alpha)
|
|
487
|
+
Manage user-role assignments at account or property level.
|
|
488
|
+
```bash
|
|
489
|
+
ga access-bindings list (-a ACCOUNT_ID | -p PROPERTY_ID) [-o json]
|
|
490
|
+
ga access-bindings get (-a ACCOUNT_ID | -p PROPERTY_ID) -b BINDING_ID [-o json]
|
|
491
|
+
ga access-bindings create (-a ACCOUNT_ID | -p PROPERTY_ID) --user EMAIL --roles viewer,editor [-o json]
|
|
492
|
+
ga access-bindings update (-a ACCOUNT_ID | -p PROPERTY_ID) -b BINDING_ID --roles viewer [-o json]
|
|
493
|
+
ga access-bindings delete (-a ACCOUNT_ID | -p PROPERTY_ID) -b BINDING_ID --yes
|
|
494
|
+
```
|
|
495
|
+
- Requires either `--account-id` (`-a`) or `--property-id` (`-p`), not both
|
|
496
|
+
- `--property-id` falls back to config default if not explicitly provided
|
|
497
|
+
- Valid roles: `viewer`, `analyst`, `editor`, `admin`, `no-cost-data`, `no-revenue-data`
|
|
498
|
+
- Short role names (e.g. `viewer`) are auto-prefixed to `predefinedRoles/viewer`
|
|
499
|
+
- Full role names (`predefinedRoles/viewer`) also accepted
|
|
500
|
+
- Uses v1alpha Admin API
|
|
501
|
+
|
|
502
|
+
## Annotations (alpha)
|
|
503
|
+
Annotations mark specific dates on GA4 reports with contextual notes.
|
|
504
|
+
```bash
|
|
505
|
+
ga annotations list [-p PROPERTY_ID] [-o json]
|
|
506
|
+
ga annotations get -p PROPERTY_ID -a ANNOTATION_ID [-o json]
|
|
507
|
+
ga annotations create -p PROPERTY_ID --title TEXT --annotation-date YYYY-MM-DD [--description TEXT] [--color COLOR]
|
|
508
|
+
ga annotations update -p PROPERTY_ID -a ANNOTATION_ID [--title TEXT] [--description TEXT] [--color COLOR]
|
|
509
|
+
ga annotations delete -p PROPERTY_ID -a ANNOTATION_ID --yes
|
|
510
|
+
```
|
|
511
|
+
- Updatable fields: `title`, `description`, `color`
|
|
512
|
+
- Uses v1alpha Admin API
|
|
513
|
+
|
|
514
|
+
## Audiences (alpha)
|
|
515
|
+
Define user segments for targeting and analysis.
|
|
516
|
+
```bash
|
|
517
|
+
ga audiences list [-p PROPERTY_ID] [-o json]
|
|
518
|
+
ga audiences get -p PROPERTY_ID -a AUDIENCE_ID [-o json]
|
|
519
|
+
ga audiences create -p PROPERTY_ID --config audience.json [-o json]
|
|
520
|
+
ga audiences update -p PROPERTY_ID -a AUDIENCE_ID --config update.json [-o json]
|
|
521
|
+
ga audiences archive -p PROPERTY_ID -a AUDIENCE_ID --yes
|
|
522
|
+
```
|
|
523
|
+
- Create/update use `--config` JSON file — audience filter clauses are deeply nested
|
|
524
|
+
- Only `displayName`, `description`, and `eventTrigger` can be updated after creation
|
|
525
|
+
- `membershipDurationDays` (max 540), `filterClauses`, and `exclusionDurationMode` are immutable
|
|
526
|
+
- Uses `archive` instead of `delete`
|
|
527
|
+
- Uses v1alpha Admin API
|
|
528
|
+
|
|
529
|
+
## BigQuery Links (alpha)
|
|
530
|
+
Link a GA4 property to a BigQuery project for data export.
|
|
531
|
+
```bash
|
|
532
|
+
ga bigquery-links list [-p PROPERTY_ID] [-o json]
|
|
533
|
+
ga bigquery-links get -p PROPERTY_ID -l LINK_ID [-o json]
|
|
534
|
+
ga bigquery-links create -p PROPERTY_ID --project PROJECT --dataset-location LOC [--daily-export] [--streaming-export] [--fresh-daily-export] [--include-advertising-id] [--export-streams IDS] [--excluded-events EVENTS]
|
|
535
|
+
ga bigquery-links update -p PROPERTY_ID -l LINK_ID [--daily-export|--no-daily-export] [--streaming-export|--no-streaming-export] [--fresh-daily-export|--no-fresh-daily-export] [--include-advertising-id|--no-include-advertising-id] [--export-streams IDS] [--excluded-events EVENTS]
|
|
536
|
+
ga bigquery-links delete -p PROPERTY_ID -l LINK_ID --yes
|
|
537
|
+
```
|
|
538
|
+
- `--project` and `--dataset-location` are immutable (set at creation only)
|
|
539
|
+
- `--export-streams` accepts comma-separated data stream IDs
|
|
540
|
+
- `--excluded-events` accepts comma-separated event names
|
|
541
|
+
- Uses v1alpha Admin API
|
|
542
|
+
|
|
543
|
+
## Channel Groups (alpha)
|
|
544
|
+
Custom channel groupings for categorizing traffic sources.
|
|
545
|
+
```bash
|
|
546
|
+
ga channel-groups list [-p PROPERTY_ID] [-o json]
|
|
547
|
+
ga channel-groups get -p PROPERTY_ID -g GROUP_ID [-o json]
|
|
548
|
+
ga channel-groups create -p PROPERTY_ID --config channel_group.json [-o json]
|
|
549
|
+
ga channel-groups update -p PROPERTY_ID -g GROUP_ID --config update.json [-o json]
|
|
550
|
+
ga channel-groups delete -p PROPERTY_ID -g GROUP_ID --yes
|
|
551
|
+
```
|
|
552
|
+
- Create/update use `--config` JSON file — grouping rules have nested filter expressions
|
|
553
|
+
- Maximum 50 grouping rules per channel group
|
|
554
|
+
- `displayName` (max 80 chars), `description`, `groupingRule`, and `primary` are updatable
|
|
555
|
+
- `systemDefined` channel groups (Google defaults) are read-only
|
|
556
|
+
- Uses v1alpha Admin API
|
|
557
|
+
|
|
558
|
+
## Calculated Metrics (alpha)
|
|
559
|
+
Derived metrics defined by a formula over existing metrics (e.g., revenue per user).
|
|
560
|
+
```bash
|
|
561
|
+
ga calculated-metrics list [-p PROPERTY_ID] [-o json]
|
|
562
|
+
ga calculated-metrics get -p PROPERTY_ID -m METRIC_ID [-o json]
|
|
563
|
+
ga calculated-metrics create -p PROPERTY_ID --calculated-metric-id ID --display-name NAME --formula FORMULA --metric-unit UNIT [--description TEXT]
|
|
564
|
+
ga calculated-metrics update -p PROPERTY_ID -m METRIC_ID [--display-name NAME] [--formula FORMULA] [--metric-unit UNIT] [--description TEXT]
|
|
565
|
+
ga calculated-metrics delete -p PROPERTY_ID -m METRIC_ID --yes
|
|
566
|
+
```
|
|
567
|
+
- Formula syntax uses `{{metricName}}` placeholders, e.g., `"{{totalRevenue}} / {{totalUsers}}"`
|
|
568
|
+
- Metric units: `STANDARD`, `CURRENCY`, `FEET`, `METERS`, `KILOMETERS`, `MILES`, `MILLISECONDS`, `SECONDS`, `MINUTES`, `HOURS`
|
|
569
|
+
- `calculatedMetricId` and `metricUnit` cannot be changed after creation
|
|
570
|
+
- Uses v1alpha Admin API
|
|
571
|
+
|
|
572
|
+
## Event Create Rules (alpha)
|
|
573
|
+
Create new events based on conditions matched against incoming events.
|
|
574
|
+
```bash
|
|
575
|
+
ga event-create-rules list -p PROPERTY_ID -s STREAM_ID [-o json]
|
|
576
|
+
ga event-create-rules get -p PROPERTY_ID -s STREAM_ID -r RULE_ID [-o json]
|
|
577
|
+
ga event-create-rules create -p PROPERTY_ID -s STREAM_ID --config rule.json [-o json]
|
|
578
|
+
ga event-create-rules update -p PROPERTY_ID -s STREAM_ID -r RULE_ID --config update.json [-o json]
|
|
579
|
+
ga event-create-rules delete -p PROPERTY_ID -s STREAM_ID -r RULE_ID --yes
|
|
580
|
+
```
|
|
581
|
+
- Requires both `--property-id` and `--stream-id` (nested under data streams)
|
|
582
|
+
- Create/update use `--config` JSON with: `destinationEvent`, `eventConditions` (1–10 conditions), `sourceCopyParameters`, `parameterMutations` (max 20)
|
|
583
|
+
- Condition comparison types: `EQUALS`, `CONTAINS`, `STARTS_WITH`, `ENDS_WITH`, `GREATER_THAN`, `LESS_THAN`, `REGULAR_EXPRESSION`, plus case-insensitive variants
|
|
584
|
+
- Uses v1alpha Admin API
|
|
585
|
+
|
|
586
|
+
## Event Edit Rules (alpha)
|
|
587
|
+
Modify existing events by mutating parameters based on matching conditions. Rules are applied in processing order.
|
|
588
|
+
```bash
|
|
589
|
+
ga event-edit-rules list -p PROPERTY_ID -s STREAM_ID [-o json]
|
|
590
|
+
ga event-edit-rules get -p PROPERTY_ID -s STREAM_ID -r RULE_ID [-o json]
|
|
591
|
+
ga event-edit-rules create -p PROPERTY_ID -s STREAM_ID --config rule.json [-o json]
|
|
592
|
+
ga event-edit-rules update -p PROPERTY_ID -s STREAM_ID -r RULE_ID --config update.json [-o json]
|
|
593
|
+
ga event-edit-rules delete -p PROPERTY_ID -s STREAM_ID -r RULE_ID --yes
|
|
594
|
+
ga event-edit-rules reorder -p PROPERTY_ID -s STREAM_ID --rule-ids r1,r2,r3
|
|
595
|
+
```
|
|
596
|
+
- Requires both `--property-id` and `--stream-id` (nested under data streams)
|
|
597
|
+
- Create/update use `--config` JSON with: `displayName` (max 255 chars), `eventConditions` (1–10 conditions), `parameterMutations` (max 20)
|
|
598
|
+
- Set `parameter` to `event_name` in a mutation to rename the event in place
|
|
599
|
+
- `reorder` requires all rule IDs in the desired processing order (comma-separated)
|
|
600
|
+
- `processingOrder` is output-only (set by the API, changed via `reorder`)
|
|
601
|
+
- Uses v1alpha Admin API
|
|
602
|
+
|
|
603
|
+
## Property Settings (alpha)
|
|
604
|
+
Get/set hybrid commands for property-level singleton settings. No update flags = GET current settings. Any update flag = PATCH and display result.
|
|
605
|
+
|
|
606
|
+
### Attribution Settings
|
|
607
|
+
```bash
|
|
608
|
+
ga property-settings attribution [-p PROPERTY_ID] [-o json]
|
|
609
|
+
ga property-settings attribution -p PROPERTY_ID --attribution-model PAID_AND_ORGANIC_CHANNELS_DATA_DRIVEN
|
|
610
|
+
ga property-settings attribution -p PROPERTY_ID --acquisition-lookback ACQUISITION_CONVERSION_EVENT_LOOKBACK_WINDOW_7_DAYS --other-lookback OTHER_CONVERSION_EVENT_LOOKBACK_WINDOW_60_DAYS
|
|
611
|
+
ga property-settings attribution -p PROPERTY_ID --ads-export-scope PAID_AND_ORGANIC_CHANNELS
|
|
612
|
+
```
|
|
613
|
+
- `--attribution-model`: `PAID_AND_ORGANIC_CHANNELS_DATA_DRIVEN`, `PAID_AND_ORGANIC_CHANNELS_LAST_CLICK`, `GOOGLE_PAID_CHANNELS_LAST_CLICK`
|
|
614
|
+
- `--acquisition-lookback`: `ACQUISITION_CONVERSION_EVENT_LOOKBACK_WINDOW_7_DAYS`, `ACQUISITION_CONVERSION_EVENT_LOOKBACK_WINDOW_30_DAYS`
|
|
615
|
+
- `--other-lookback`: `OTHER_CONVERSION_EVENT_LOOKBACK_WINDOW_30_DAYS`, `OTHER_CONVERSION_EVENT_LOOKBACK_WINDOW_60_DAYS`, `OTHER_CONVERSION_EVENT_LOOKBACK_WINDOW_90_DAYS`
|
|
616
|
+
- `--ads-export-scope`: `NOT_SELECTED_YET`, `PAID_AND_ORGANIC_CHANNELS`, `GOOGLE_PAID_CHANNELS`
|
|
617
|
+
|
|
618
|
+
### Google Signals Settings
|
|
619
|
+
```bash
|
|
620
|
+
ga property-settings google-signals [-p PROPERTY_ID] [-o json]
|
|
621
|
+
ga property-settings google-signals -p PROPERTY_ID --state GOOGLE_SIGNALS_ENABLED
|
|
622
|
+
```
|
|
623
|
+
- `--state`: `GOOGLE_SIGNALS_ENABLED`, `GOOGLE_SIGNALS_DISABLED`
|
|
624
|
+
- `consent` is output-only (Terms of Service acceptance status)
|
|
625
|
+
|
|
626
|
+
### Enhanced Measurement Settings
|
|
627
|
+
```bash
|
|
628
|
+
ga property-settings enhanced-measurement -p PROPERTY_ID -s STREAM_ID [-o json]
|
|
629
|
+
ga property-settings enhanced-measurement -p PROPERTY_ID -s STREAM_ID --no-scrolls --form-interactions
|
|
630
|
+
```
|
|
631
|
+
- Requires `--stream-id` (web data stream only)
|
|
632
|
+
- Boolean toggles: `--stream-enabled/--no-stream-enabled`, `--scrolls/--no-scrolls`, `--outbound-clicks/--no-outbound-clicks`, `--site-search/--no-site-search`, `--video-engagement/--no-video-engagement`, `--file-downloads/--no-file-downloads`, `--page-changes/--no-page-changes`, `--form-interactions/--no-form-interactions`
|
|
633
|
+
- String params: `--search-query-parameter`, `--uri-query-parameter`
|
|
634
|
+
- Uses v1alpha Admin API
|
|
635
|
+
"""
|
|
636
|
+
|
|
637
|
+
_SECTION_EXAMPLES = r"""# Complete Examples
|
|
638
|
+
|
|
639
|
+
## Audit a GA4 Account
|
|
640
|
+
```bash
|
|
641
|
+
ACCOUNT_ID=123456789
|
|
642
|
+
ga accounts get -a $ACCOUNT_ID -o json
|
|
643
|
+
PROPERTIES=$(ga properties list -a $ACCOUNT_ID -o json)
|
|
644
|
+
echo "$PROPERTIES" | jq -r '.[].name' | while read -r prop; do
|
|
645
|
+
PROP_ID=$(echo "$prop" | grep -o '[0-9]*$')
|
|
646
|
+
ga data-streams list -p "$PROP_ID" -o json
|
|
647
|
+
done
|
|
648
|
+
```
|
|
649
|
+
|
|
650
|
+
## Traffic Report (Last 30 Days)
|
|
651
|
+
```bash
|
|
652
|
+
P=987654321
|
|
653
|
+
ga reports run -p $P -m sessions,users,engagementRate -d sessionDefaultChannelGroup --start-date 30daysAgo -o json
|
|
654
|
+
ga reports run -p $P -m sessions,users -d deviceCategory --start-date 30daysAgo -o json
|
|
655
|
+
ga reports run -p $P -m screenPageViews,users -d pagePath --start-date 30daysAgo --limit 20 -o json
|
|
656
|
+
```
|
|
657
|
+
|
|
658
|
+
## Create Property with Streams
|
|
659
|
+
```bash
|
|
660
|
+
PROP=$(ga properties create -a 123456789 --name "New Site" --timezone "Europe/Berlin" --currency "EUR" -o json)
|
|
661
|
+
PROP_ID=$(echo "$PROP" | jq -r '.name' | grep -o '[0-9]*$')
|
|
662
|
+
ga data-streams create -p "$PROP_ID" --display-name "Web" --url "https://example.com" &
|
|
663
|
+
ga data-streams create -p "$PROP_ID" --display-name "Android" --type ANDROID_APP_DATA_STREAM --bundle-id "com.example.app" &
|
|
664
|
+
wait
|
|
665
|
+
```
|
|
666
|
+
"""
|
|
667
|
+
|
|
668
|
+
_SECTION_SETUP = r"""# Credential Setup — GCP OAuth Configuration
|
|
669
|
+
|
|
670
|
+
GA CLI requires your own Google Cloud Platform OAuth credentials. This guide walks
|
|
671
|
+
through creating them from scratch.
|
|
672
|
+
|
|
673
|
+
## Step 1: Create or Select a GCP Project
|
|
674
|
+
|
|
675
|
+
1. Go to the [Google Cloud Console](https://console.cloud.google.com/)
|
|
676
|
+
2. Create a new project (or select an existing one)
|
|
677
|
+
3. Note your project ID
|
|
678
|
+
|
|
679
|
+
## Step 2: Enable Required APIs
|
|
680
|
+
|
|
681
|
+
In the GCP Console, go to **APIs & Services > Library** and enable:
|
|
682
|
+
- **Google Analytics Admin API**
|
|
683
|
+
- **Google Analytics Data API**
|
|
684
|
+
|
|
685
|
+
Or via `gcloud`:
|
|
686
|
+
```bash
|
|
687
|
+
gcloud services enable analyticsadmin.googleapis.com analyticsdata.googleapis.com
|
|
688
|
+
```
|
|
689
|
+
|
|
690
|
+
## Step 3: Configure OAuth Consent Screen
|
|
691
|
+
|
|
692
|
+
1. Go to **APIs & Services > OAuth consent screen**
|
|
693
|
+
2. Choose **External** user type (or Internal if using Google Workspace)
|
|
694
|
+
3. Fill in the required fields (app name, user support email, developer contact)
|
|
695
|
+
4. No scopes need to be added manually — GA CLI requests them at login time
|
|
696
|
+
5. For personal use, leave the app in **Testing** mode — it works for the project owner
|
|
697
|
+
and up to 100 added test users without Google verification
|
|
698
|
+
|
|
699
|
+
## Step 4: Create OAuth Client ID
|
|
700
|
+
|
|
701
|
+
1. Go to **APIs & Services > Credentials**
|
|
702
|
+
2. Click **Create Credentials > OAuth client ID**
|
|
703
|
+
3. Choose **Desktop app** as the application type
|
|
704
|
+
4. Give it a name (e.g., "GA CLI")
|
|
705
|
+
5. Click **Create** and download the JSON file
|
|
706
|
+
|
|
707
|
+
## Step 5: Provide Credentials to GA CLI
|
|
708
|
+
|
|
709
|
+
**Option A** — Place the downloaded JSON file (recommended):
|
|
710
|
+
```bash
|
|
711
|
+
mkdir -p ~/.config/ga-cli
|
|
712
|
+
cp /path/to/downloaded/client_secret_*.json ~/.config/ga-cli/client_secret.json
|
|
713
|
+
```
|
|
714
|
+
|
|
715
|
+
**Option B** — Set environment variables:
|
|
716
|
+
```bash
|
|
717
|
+
export GA_CLI_CLIENT_ID="your-client-id.apps.googleusercontent.com"
|
|
718
|
+
export GA_CLI_CLIENT_SECRET="your-client-secret"
|
|
719
|
+
```
|
|
720
|
+
|
|
721
|
+
## Step 6: Authenticate
|
|
722
|
+
|
|
723
|
+
```bash
|
|
724
|
+
ga auth login
|
|
725
|
+
```
|
|
726
|
+
|
|
727
|
+
This opens your browser for Google OAuth consent and stores the token locally at
|
|
728
|
+
`~/.config/ga-cli/credentials.json`.
|
|
729
|
+
|
|
730
|
+
## Verification
|
|
731
|
+
|
|
732
|
+
```bash
|
|
733
|
+
ga auth status # Check authentication state
|
|
734
|
+
ga accounts list # Verify API access
|
|
735
|
+
```
|
|
736
|
+
|
|
737
|
+
## Notes
|
|
738
|
+
- **Testing mode** is sufficient for personal use — no Google verification needed
|
|
739
|
+
- For team use, publish the consent screen to **Production** within your GCP project
|
|
740
|
+
- Service account auth (`ga auth login --service-account /path/key.json`) does not
|
|
741
|
+
require OAuth credentials and works independently
|
|
742
|
+
"""
|
|
743
|
+
|
|
744
|
+
_SECTIONS = {
|
|
745
|
+
"setup": _SECTION_SETUP,
|
|
746
|
+
"reports": _SECTION_REPORTS,
|
|
747
|
+
"admin": _SECTION_ADMIN,
|
|
748
|
+
"examples": _SECTION_EXAMPLES,
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
VALID_SECTIONS = list(_SECTIONS.keys())
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
@agent_app.command("guide")
|
|
755
|
+
def guide(
|
|
756
|
+
section: Optional[str] = typer.Option(
|
|
757
|
+
None,
|
|
758
|
+
"--section",
|
|
759
|
+
"-s",
|
|
760
|
+
help=f"Show a specific section: {', '.join(VALID_SECTIONS)}",
|
|
761
|
+
),
|
|
762
|
+
):
|
|
763
|
+
"""Print a reference guide for AI agents using the GA CLI."""
|
|
764
|
+
if section is None:
|
|
765
|
+
print(_SECTION_OVERVIEW)
|
|
766
|
+
return
|
|
767
|
+
|
|
768
|
+
key = section.lower().strip()
|
|
769
|
+
if key not in _SECTIONS:
|
|
770
|
+
print(
|
|
771
|
+
f"Unknown section: '{section}'. "
|
|
772
|
+
f"Valid sections: {', '.join(VALID_SECTIONS)}"
|
|
773
|
+
)
|
|
774
|
+
raise typer.Exit(code=0)
|
|
775
|
+
|
|
776
|
+
print(_SECTIONS[key])
|