google-analytics-cli 0.1.0rc1__tar.gz

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.
Files changed (97) hide show
  1. google_analytics_cli-0.1.0rc1/.github/workflows/ci.yml +30 -0
  2. google_analytics_cli-0.1.0rc1/.github/workflows/release.yml +75 -0
  3. google_analytics_cli-0.1.0rc1/.gitignore +30 -0
  4. google_analytics_cli-0.1.0rc1/.python-version +1 -0
  5. google_analytics_cli-0.1.0rc1/PKG-INFO +269 -0
  6. google_analytics_cli-0.1.0rc1/README.md +238 -0
  7. google_analytics_cli-0.1.0rc1/install.sh +53 -0
  8. google_analytics_cli-0.1.0rc1/pyproject.toml +65 -0
  9. google_analytics_cli-0.1.0rc1/src/ga_cli/__init__.py +8 -0
  10. google_analytics_cli-0.1.0rc1/src/ga_cli/api/__init__.py +0 -0
  11. google_analytics_cli-0.1.0rc1/src/ga_cli/api/client.py +142 -0
  12. google_analytics_cli-0.1.0rc1/src/ga_cli/auth/__init__.py +35 -0
  13. google_analytics_cli-0.1.0rc1/src/ga_cli/auth/credentials.py +126 -0
  14. google_analytics_cli-0.1.0rc1/src/ga_cli/auth/oauth.py +322 -0
  15. google_analytics_cli-0.1.0rc1/src/ga_cli/auth/service_account.py +155 -0
  16. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/__init__.py +0 -0
  17. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/access_bindings.py +254 -0
  18. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/access_reports.py +201 -0
  19. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/account_summaries.py +68 -0
  20. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/accounts.py +297 -0
  21. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/agent_cmd.py +776 -0
  22. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/annotations.py +264 -0
  23. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/audiences.py +223 -0
  24. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/auth_cmd.py +205 -0
  25. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/bigquery_links.py +309 -0
  26. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/calculated_metrics.py +312 -0
  27. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/channel_groups.py +223 -0
  28. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/completions_cmd.py +55 -0
  29. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/config_cmd.py +113 -0
  30. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/custom_dimensions.py +272 -0
  31. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/custom_metrics.py +305 -0
  32. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/data_retention.py +153 -0
  33. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/data_streams.py +277 -0
  34. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/event_create_rules.py +250 -0
  35. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/event_edit_rules.py +292 -0
  36. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/firebase_links.py +142 -0
  37. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/google_ads_links.py +225 -0
  38. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/key_events.py +269 -0
  39. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/mp_secrets.py +265 -0
  40. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/properties.py +330 -0
  41. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/property_settings.py +287 -0
  42. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/reports.py +726 -0
  43. google_analytics_cli-0.1.0rc1/src/ga_cli/commands/upgrade_cmd.py +148 -0
  44. google_analytics_cli-0.1.0rc1/src/ga_cli/config/__init__.py +0 -0
  45. google_analytics_cli-0.1.0rc1/src/ga_cli/config/constants.py +61 -0
  46. google_analytics_cli-0.1.0rc1/src/ga_cli/config/store.py +115 -0
  47. google_analytics_cli-0.1.0rc1/src/ga_cli/main.py +110 -0
  48. google_analytics_cli-0.1.0rc1/src/ga_cli/utils/__init__.py +20 -0
  49. google_analytics_cli-0.1.0rc1/src/ga_cli/utils/describe.py +129 -0
  50. google_analytics_cli-0.1.0rc1/src/ga_cli/utils/dry_run.py +40 -0
  51. google_analytics_cli-0.1.0rc1/src/ga_cli/utils/errors.py +150 -0
  52. google_analytics_cli-0.1.0rc1/src/ga_cli/utils/output.py +209 -0
  53. google_analytics_cli-0.1.0rc1/src/ga_cli/utils/pagination.py +93 -0
  54. google_analytics_cli-0.1.0rc1/tests/__init__.py +0 -0
  55. google_analytics_cli-0.1.0rc1/tests/conftest.py +24 -0
  56. google_analytics_cli-0.1.0rc1/tests/test_access_bindings.py +520 -0
  57. google_analytics_cli-0.1.0rc1/tests/test_access_reports.py +223 -0
  58. google_analytics_cli-0.1.0rc1/tests/test_account_summaries.py +131 -0
  59. google_analytics_cli-0.1.0rc1/tests/test_accounts.py +570 -0
  60. google_analytics_cli-0.1.0rc1/tests/test_agent_cmd.py +154 -0
  61. google_analytics_cli-0.1.0rc1/tests/test_annotations.py +491 -0
  62. google_analytics_cli-0.1.0rc1/tests/test_api_client.py +137 -0
  63. google_analytics_cli-0.1.0rc1/tests/test_audiences.py +508 -0
  64. google_analytics_cli-0.1.0rc1/tests/test_auth_cmd.py +158 -0
  65. google_analytics_cli-0.1.0rc1/tests/test_bigquery_links.py +515 -0
  66. google_analytics_cli-0.1.0rc1/tests/test_calculated_metrics.py +551 -0
  67. google_analytics_cli-0.1.0rc1/tests/test_channel_groups.py +496 -0
  68. google_analytics_cli-0.1.0rc1/tests/test_completions_cmd.py +68 -0
  69. google_analytics_cli-0.1.0rc1/tests/test_config_cmd.py +140 -0
  70. google_analytics_cli-0.1.0rc1/tests/test_credentials.py +126 -0
  71. google_analytics_cli-0.1.0rc1/tests/test_custom_dimensions.py +525 -0
  72. google_analytics_cli-0.1.0rc1/tests/test_custom_metrics.py +519 -0
  73. google_analytics_cli-0.1.0rc1/tests/test_data_retention.py +224 -0
  74. google_analytics_cli-0.1.0rc1/tests/test_data_streams.py +465 -0
  75. google_analytics_cli-0.1.0rc1/tests/test_describe.py +209 -0
  76. google_analytics_cli-0.1.0rc1/tests/test_dry_run.py +723 -0
  77. google_analytics_cli-0.1.0rc1/tests/test_errors.py +332 -0
  78. google_analytics_cli-0.1.0rc1/tests/test_event_create_rules.py +540 -0
  79. google_analytics_cli-0.1.0rc1/tests/test_event_edit_rules.py +612 -0
  80. google_analytics_cli-0.1.0rc1/tests/test_firebase_links.py +248 -0
  81. google_analytics_cli-0.1.0rc1/tests/test_google_ads_links.py +346 -0
  82. google_analytics_cli-0.1.0rc1/tests/test_install_script.sh +35 -0
  83. google_analytics_cli-0.1.0rc1/tests/test_key_events.py +447 -0
  84. google_analytics_cli-0.1.0rc1/tests/test_mp_secrets.py +421 -0
  85. google_analytics_cli-0.1.0rc1/tests/test_output.py +193 -0
  86. google_analytics_cli-0.1.0rc1/tests/test_pagination.py +161 -0
  87. google_analytics_cli-0.1.0rc1/tests/test_properties.py +539 -0
  88. google_analytics_cli-0.1.0rc1/tests/test_property_settings.py +451 -0
  89. google_analytics_cli-0.1.0rc1/tests/test_quiet_nocolor.py +148 -0
  90. google_analytics_cli-0.1.0rc1/tests/test_reports.py +730 -0
  91. google_analytics_cli-0.1.0rc1/tests/test_reports_batch.py +200 -0
  92. google_analytics_cli-0.1.0rc1/tests/test_reports_funnel.py +212 -0
  93. google_analytics_cli-0.1.0rc1/tests/test_reports_pivot.py +226 -0
  94. google_analytics_cli-0.1.0rc1/tests/test_service_account.py +86 -0
  95. google_analytics_cli-0.1.0rc1/tests/test_upgrade_cmd.py +230 -0
  96. google_analytics_cli-0.1.0rc1/tests/test_version.py +31 -0
  97. google_analytics_cli-0.1.0rc1/uv.lock +811 -0
@@ -0,0 +1,30 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+ pull_request:
7
+ branches: [master]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.10", "3.12", "3.13"]
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+
18
+ - name: Install uv
19
+ uses: astral-sh/setup-uv@v5
20
+ with:
21
+ python-version: ${{ matrix.python-version }}
22
+
23
+ - name: Install dependencies
24
+ run: uv sync
25
+
26
+ - name: Lint
27
+ run: uv run ruff check src/ tests/
28
+
29
+ - name: Run tests
30
+ run: uv run pytest
@@ -0,0 +1,75 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags: ["v*"]
6
+
7
+ jobs:
8
+ test:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+ - name: Install uv
13
+ uses: astral-sh/setup-uv@v5
14
+ - name: Install dependencies
15
+ run: uv sync
16
+ - name: Lint
17
+ run: uv run ruff check src/ tests/
18
+ - name: Run tests
19
+ run: uv run pytest
20
+
21
+ build:
22
+ needs: test
23
+ runs-on: ubuntu-latest
24
+ steps:
25
+ - uses: actions/checkout@v4
26
+
27
+ - name: Install uv
28
+ uses: astral-sh/setup-uv@v5
29
+
30
+ - name: Build
31
+ run: uv build
32
+
33
+ - name: Upload dist artifacts
34
+ uses: actions/upload-artifact@v4
35
+ with:
36
+ name: dist
37
+ path: dist/
38
+
39
+ publish-testpypi:
40
+ needs: build
41
+ runs-on: ubuntu-latest
42
+ environment: testpypi
43
+ permissions:
44
+ id-token: write
45
+ steps:
46
+ - name: Download dist artifacts
47
+ uses: actions/download-artifact@v4
48
+ with:
49
+ name: dist
50
+ path: dist/
51
+
52
+ - name: Install uv
53
+ uses: astral-sh/setup-uv@v5
54
+
55
+ - name: Publish to TestPyPI
56
+ run: uv publish --publish-url https://test.pypi.org/legacy/
57
+
58
+ publish-pypi:
59
+ needs: publish-testpypi
60
+ runs-on: ubuntu-latest
61
+ environment: pypi
62
+ permissions:
63
+ id-token: write
64
+ steps:
65
+ - name: Download dist artifacts
66
+ uses: actions/download-artifact@v4
67
+ with:
68
+ name: dist
69
+ path: dist/
70
+
71
+ - name: Install uv
72
+ uses: astral-sh/setup-uv@v5
73
+
74
+ - name: Publish to PyPI
75
+ run: uv publish
@@ -0,0 +1,30 @@
1
+ # OAuth credentials
2
+ client_secret.json
3
+ test-service-account.json
4
+
5
+ # Python
6
+ __pycache__/
7
+ *.py[cod]
8
+ *.egg-info/
9
+ dist/
10
+ build/
11
+ .pytest_cache/
12
+ .ruff_cache/
13
+
14
+ # Virtual environment
15
+ .venv/
16
+
17
+ # IDE
18
+ .idea/
19
+ .vscode/
20
+ *.swp
21
+
22
+ # OS
23
+ .DS_Store
24
+
25
+ # Claude
26
+ CLAUDE.md
27
+ .claude/*
28
+
29
+ # Archive
30
+ archive/
@@ -0,0 +1 @@
1
+ 3.12
@@ -0,0 +1,269 @@
1
+ Metadata-Version: 2.4
2
+ Name: google-analytics-cli
3
+ Version: 0.1.0rc1
4
+ Summary: Command-line interface for Google Analytics 4
5
+ Project-URL: Homepage, https://github.com/daidalytics/google-analytics-cli
6
+ Project-URL: Repository, https://github.com/daidalytics/google-analytics-cli
7
+ Project-URL: Issues, https://github.com/daidalytics/google-analytics-cli/issues
8
+ Author: Gunnar Griese
9
+ License: MIT
10
+ Keywords: analytics,cli,ga4,google-analytics
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Internet :: WWW/HTTP
21
+ Requires-Python: >=3.10
22
+ Requires-Dist: google-api-python-client>=2.0
23
+ Requires-Dist: google-auth-oauthlib>=1.0
24
+ Requires-Dist: google-auth>=2.0
25
+ Requires-Dist: packaging>=23.0
26
+ Requires-Dist: platformdirs>=4.0
27
+ Requires-Dist: questionary>=2.0
28
+ Requires-Dist: rich>=13.0
29
+ Requires-Dist: typer[all]>=0.9.0
30
+ Description-Content-Type: text/markdown
31
+
32
+ # GA CLI
33
+
34
+ Command-line interface for Google Analytics 4.
35
+
36
+ Manage GA4 accounts, properties, data streams, and run reports — all from your terminal.
37
+
38
+ ## Features
39
+
40
+ - **Authentication** — OAuth 2.0 (browser-based) and service account support
41
+ - **Account management** — List, inspect, and update GA4 accounts
42
+ - **Property management** — List, create, inspect, update, and delete GA4 properties
43
+ - **Data stream management** — List, create, inspect, update, and delete web, Android, and iOS data streams
44
+ - **Custom dimensions & metrics** — List, create, update, and archive custom definitions
45
+ - **Key events** — List, create, update, and delete key events (conversions)
46
+ - **Reporting** — Run custom reports, pivot reports, real-time reports with live polling, check compatibility, and build reports interactively
47
+ - **Flexible output** — Table (default), JSON, and compact output formats
48
+ - **Self-update** — Check for and install updates via `ga upgrade`
49
+ - **Schema introspection** — `ga --describe` outputs JSON Schema for all commands (agent/MCP-ready)
50
+ - **Shell completions** — Generate completion scripts for bash, zsh, and fish
51
+ - **Interactive setup** — Guided configuration wizard via `ga config setup`
52
+
53
+ ## Installation
54
+
55
+ ### From PyPI (recommended)
56
+
57
+ ```bash
58
+ # pipx (recommended for CLI tools — isolated env)
59
+ pipx install google-analytics-cli
60
+
61
+ # uv
62
+ uv tool install google-analytics-cli
63
+
64
+ # pip
65
+ pip install google-analytics-cli
66
+ ```
67
+
68
+ ### Quick install (script)
69
+
70
+ ```bash
71
+ curl -fsSL https://raw.githubusercontent.com/daidalytics/google-analytics-cli/master/install.sh | bash
72
+ ```
73
+
74
+ ### From GitHub
75
+
76
+ ```bash
77
+ # With uv
78
+ uv pip install git+https://github.com/daidalytics/google-analytics-cli.git
79
+
80
+ # With pip
81
+ pip install git+https://github.com/daidalytics/google-analytics-cli.git
82
+ ```
83
+
84
+ ### From source
85
+
86
+ ```bash
87
+ git clone https://github.com/daidalytics/google-analytics-cli.git
88
+ cd google-analytics-cli
89
+ uv sync
90
+ uv run ga --help
91
+ ```
92
+
93
+ ### One-off execution (no install)
94
+
95
+ ```bash
96
+ uvx --from git+https://github.com/daidalytics/google-analytics-cli.git ga --help
97
+ ```
98
+
99
+ ## Quick Start
100
+
101
+ ```bash
102
+ # 1. Authenticate
103
+ ga auth login
104
+
105
+ # 2. List your accounts
106
+ ga accounts list
107
+
108
+ # 3. List properties for an account
109
+ ga properties list --account-id 123456789
110
+
111
+ # 4. Run a report
112
+ ga reports run --property-id 987654321 \
113
+ --metrics sessions,totalUsers \
114
+ --dimensions date \
115
+ --start-date 7daysAgo
116
+ ```
117
+
118
+ ## Setup
119
+
120
+ ### 1. Create OAuth credentials
121
+
122
+ Create an OAuth 2.0 Client ID in the [Google Cloud Console](https://console.cloud.google.com/apis/credentials):
123
+
124
+ 1. Go to **APIs & Services > Credentials**
125
+ 2. Click **Create Credentials > OAuth client ID**
126
+ 3. Choose **Desktop app** as the application type
127
+ 4. Download the JSON file
128
+
129
+ Make sure the following APIs are enabled in your GCP project:
130
+ - Google Analytics Admin API
131
+ - Google Analytics Data API
132
+
133
+ ### 2. Configure client credentials
134
+
135
+ Copy the downloaded `client_secret.json` to the GA CLI config directory:
136
+
137
+ ```bash
138
+ mkdir -p ~/.config/ga-cli
139
+ cp /path/to/client_secret.json ~/.config/ga-cli/client_secret.json
140
+ ```
141
+
142
+ Alternatively, set environment variables:
143
+
144
+ ```bash
145
+ export GA_CLI_CLIENT_ID="your-client-id"
146
+ export GA_CLI_CLIENT_SECRET="your-client-secret"
147
+ ```
148
+
149
+ ### 3. Authenticate
150
+
151
+ ```bash
152
+ ga auth login
153
+ ```
154
+
155
+ This opens your browser for Google OAuth consent and stores the token locally at `~/.config/ga-cli/credentials.json`.
156
+
157
+ #### Service account (alternative)
158
+
159
+ ```bash
160
+ ga auth login --service-account /path/to/key.json
161
+ ```
162
+
163
+ Or set an environment variable:
164
+
165
+ ```bash
166
+ export GA_CLI_SERVICE_ACCOUNT="/path/to/key.json"
167
+ ```
168
+
169
+ ## Command Reference
170
+
171
+ | Command | Subcommands | Description |
172
+ |---------|-------------|-------------|
173
+ | `ga auth` | `login`, `logout`, `status` | Manage authentication |
174
+ | `ga config` | `setup`, `get`, `set`, `unset`, `path`, `reset` | Manage CLI configuration |
175
+ | `ga accounts` | `list`, `get`, `update` | List, inspect, and update GA4 accounts |
176
+ | `ga account-summaries` | `list` | Quick overview of all accounts and properties |
177
+ | `ga properties` | `list`, `get`, `create`, `update`, `delete` | Manage GA4 properties |
178
+ | `ga custom-dimensions` | `list`, `get`, `create`, `update`, `archive` | Manage custom dimensions |
179
+ | `ga custom-metrics` | `list`, `get`, `create`, `update`, `archive` | Manage custom metrics |
180
+ | `ga data-streams` | `list`, `get`, `create`, `update`, `delete` | Manage data streams |
181
+ | `ga key-events` | `list`, `get`, `create`, `update`, `delete` | Manage key events (conversions) |
182
+ | `ga reports` | `run`, `pivot`, `check-compatibility`, `metadata`, `realtime`, `build` | Run and build reports |
183
+ | `ga upgrade` | `--check`, `--force` | Check for and install updates |
184
+ | `ga completions` | `bash`, `zsh`, `fish` | Generate shell completion scripts |
185
+
186
+ Use `ga <command> --help` for detailed usage of any command, or `ga --describe` for the full CLI schema as JSON.
187
+
188
+ ### Output formats
189
+
190
+ All read commands support `--output` (`-o`) to control output format:
191
+
192
+ ```bash
193
+ ga accounts list --output json # JSON output
194
+ ga accounts list --output table # Table output (default)
195
+ ga accounts list --output compact # Minimal ID + name output
196
+ ```
197
+
198
+ ## Global Options
199
+
200
+ ```
201
+ --help, -h Show help
202
+ --version, -v Show version
203
+ --quiet, -q Suppress non-essential output
204
+ --no-color Disable colored output
205
+ --describe Show full CLI schema as JSON (for agents and tooling)
206
+ ```
207
+
208
+ ## Shell Completions
209
+
210
+ ```bash
211
+ ga completions bash > ~/.bash_completion.d/ga
212
+ ga completions zsh > ~/.zsh/completions/_ga
213
+ ga completions fish > ~/.config/fish/completions/ga.fish
214
+ ```
215
+
216
+ ## Environment Variables
217
+
218
+ | Variable | Description |
219
+ |----------|-------------|
220
+ | `GA_CLI_SERVICE_ACCOUNT` | Path to service account key file |
221
+ | `GOOGLE_APPLICATION_CREDENTIALS` | Standard GCP credential path (fallback) |
222
+ | `GA_CLI_CONFIG_DIR` | Override config directory |
223
+ | `GA_CLI_CLIENT_ID` | OAuth client ID (alternative to client_secret.json) |
224
+ | `GA_CLI_CLIENT_SECRET` | OAuth client secret (alternative to client_secret.json) |
225
+ | `NO_COLOR` | Disable colored output |
226
+
227
+ ## CI/CD Integration
228
+
229
+ ```yaml
230
+ jobs:
231
+ ga-report:
232
+ runs-on: ubuntu-latest
233
+ steps:
234
+ - name: Install GA CLI
235
+ run: pip install google-analytics-cli
236
+
237
+ - name: Export daily report
238
+ run: |
239
+ echo '${{ secrets.GA_SERVICE_ACCOUNT_KEY }}' > /tmp/sa-key.json
240
+ ga auth login --service-account /tmp/sa-key.json
241
+ ga reports run -p ${{ vars.GA_PROPERTY_ID }} \
242
+ --metrics sessions,users --dimensions date \
243
+ --start-date 7daysAgo -o json > report.json
244
+ rm /tmp/sa-key.json
245
+ ```
246
+
247
+ ## Privacy
248
+
249
+ GA CLI stores authentication credentials locally on your machine. No data is sent to any third party — all communication is directly between your machine and Google's APIs.
250
+
251
+ ## Development
252
+
253
+ ```bash
254
+ # Install with dev dependencies
255
+ uv sync
256
+
257
+ # Run the CLI
258
+ uv run ga --help
259
+
260
+ # Run tests
261
+ uv run pytest
262
+
263
+ # Lint
264
+ uv run ruff check src/ tests/
265
+ ```
266
+
267
+ ## License
268
+
269
+ MIT
@@ -0,0 +1,238 @@
1
+ # GA CLI
2
+
3
+ Command-line interface for Google Analytics 4.
4
+
5
+ Manage GA4 accounts, properties, data streams, and run reports — all from your terminal.
6
+
7
+ ## Features
8
+
9
+ - **Authentication** — OAuth 2.0 (browser-based) and service account support
10
+ - **Account management** — List, inspect, and update GA4 accounts
11
+ - **Property management** — List, create, inspect, update, and delete GA4 properties
12
+ - **Data stream management** — List, create, inspect, update, and delete web, Android, and iOS data streams
13
+ - **Custom dimensions & metrics** — List, create, update, and archive custom definitions
14
+ - **Key events** — List, create, update, and delete key events (conversions)
15
+ - **Reporting** — Run custom reports, pivot reports, real-time reports with live polling, check compatibility, and build reports interactively
16
+ - **Flexible output** — Table (default), JSON, and compact output formats
17
+ - **Self-update** — Check for and install updates via `ga upgrade`
18
+ - **Schema introspection** — `ga --describe` outputs JSON Schema for all commands (agent/MCP-ready)
19
+ - **Shell completions** — Generate completion scripts for bash, zsh, and fish
20
+ - **Interactive setup** — Guided configuration wizard via `ga config setup`
21
+
22
+ ## Installation
23
+
24
+ ### From PyPI (recommended)
25
+
26
+ ```bash
27
+ # pipx (recommended for CLI tools — isolated env)
28
+ pipx install google-analytics-cli
29
+
30
+ # uv
31
+ uv tool install google-analytics-cli
32
+
33
+ # pip
34
+ pip install google-analytics-cli
35
+ ```
36
+
37
+ ### Quick install (script)
38
+
39
+ ```bash
40
+ curl -fsSL https://raw.githubusercontent.com/daidalytics/google-analytics-cli/master/install.sh | bash
41
+ ```
42
+
43
+ ### From GitHub
44
+
45
+ ```bash
46
+ # With uv
47
+ uv pip install git+https://github.com/daidalytics/google-analytics-cli.git
48
+
49
+ # With pip
50
+ pip install git+https://github.com/daidalytics/google-analytics-cli.git
51
+ ```
52
+
53
+ ### From source
54
+
55
+ ```bash
56
+ git clone https://github.com/daidalytics/google-analytics-cli.git
57
+ cd google-analytics-cli
58
+ uv sync
59
+ uv run ga --help
60
+ ```
61
+
62
+ ### One-off execution (no install)
63
+
64
+ ```bash
65
+ uvx --from git+https://github.com/daidalytics/google-analytics-cli.git ga --help
66
+ ```
67
+
68
+ ## Quick Start
69
+
70
+ ```bash
71
+ # 1. Authenticate
72
+ ga auth login
73
+
74
+ # 2. List your accounts
75
+ ga accounts list
76
+
77
+ # 3. List properties for an account
78
+ ga properties list --account-id 123456789
79
+
80
+ # 4. Run a report
81
+ ga reports run --property-id 987654321 \
82
+ --metrics sessions,totalUsers \
83
+ --dimensions date \
84
+ --start-date 7daysAgo
85
+ ```
86
+
87
+ ## Setup
88
+
89
+ ### 1. Create OAuth credentials
90
+
91
+ Create an OAuth 2.0 Client ID in the [Google Cloud Console](https://console.cloud.google.com/apis/credentials):
92
+
93
+ 1. Go to **APIs & Services > Credentials**
94
+ 2. Click **Create Credentials > OAuth client ID**
95
+ 3. Choose **Desktop app** as the application type
96
+ 4. Download the JSON file
97
+
98
+ Make sure the following APIs are enabled in your GCP project:
99
+ - Google Analytics Admin API
100
+ - Google Analytics Data API
101
+
102
+ ### 2. Configure client credentials
103
+
104
+ Copy the downloaded `client_secret.json` to the GA CLI config directory:
105
+
106
+ ```bash
107
+ mkdir -p ~/.config/ga-cli
108
+ cp /path/to/client_secret.json ~/.config/ga-cli/client_secret.json
109
+ ```
110
+
111
+ Alternatively, set environment variables:
112
+
113
+ ```bash
114
+ export GA_CLI_CLIENT_ID="your-client-id"
115
+ export GA_CLI_CLIENT_SECRET="your-client-secret"
116
+ ```
117
+
118
+ ### 3. Authenticate
119
+
120
+ ```bash
121
+ ga auth login
122
+ ```
123
+
124
+ This opens your browser for Google OAuth consent and stores the token locally at `~/.config/ga-cli/credentials.json`.
125
+
126
+ #### Service account (alternative)
127
+
128
+ ```bash
129
+ ga auth login --service-account /path/to/key.json
130
+ ```
131
+
132
+ Or set an environment variable:
133
+
134
+ ```bash
135
+ export GA_CLI_SERVICE_ACCOUNT="/path/to/key.json"
136
+ ```
137
+
138
+ ## Command Reference
139
+
140
+ | Command | Subcommands | Description |
141
+ |---------|-------------|-------------|
142
+ | `ga auth` | `login`, `logout`, `status` | Manage authentication |
143
+ | `ga config` | `setup`, `get`, `set`, `unset`, `path`, `reset` | Manage CLI configuration |
144
+ | `ga accounts` | `list`, `get`, `update` | List, inspect, and update GA4 accounts |
145
+ | `ga account-summaries` | `list` | Quick overview of all accounts and properties |
146
+ | `ga properties` | `list`, `get`, `create`, `update`, `delete` | Manage GA4 properties |
147
+ | `ga custom-dimensions` | `list`, `get`, `create`, `update`, `archive` | Manage custom dimensions |
148
+ | `ga custom-metrics` | `list`, `get`, `create`, `update`, `archive` | Manage custom metrics |
149
+ | `ga data-streams` | `list`, `get`, `create`, `update`, `delete` | Manage data streams |
150
+ | `ga key-events` | `list`, `get`, `create`, `update`, `delete` | Manage key events (conversions) |
151
+ | `ga reports` | `run`, `pivot`, `check-compatibility`, `metadata`, `realtime`, `build` | Run and build reports |
152
+ | `ga upgrade` | `--check`, `--force` | Check for and install updates |
153
+ | `ga completions` | `bash`, `zsh`, `fish` | Generate shell completion scripts |
154
+
155
+ Use `ga <command> --help` for detailed usage of any command, or `ga --describe` for the full CLI schema as JSON.
156
+
157
+ ### Output formats
158
+
159
+ All read commands support `--output` (`-o`) to control output format:
160
+
161
+ ```bash
162
+ ga accounts list --output json # JSON output
163
+ ga accounts list --output table # Table output (default)
164
+ ga accounts list --output compact # Minimal ID + name output
165
+ ```
166
+
167
+ ## Global Options
168
+
169
+ ```
170
+ --help, -h Show help
171
+ --version, -v Show version
172
+ --quiet, -q Suppress non-essential output
173
+ --no-color Disable colored output
174
+ --describe Show full CLI schema as JSON (for agents and tooling)
175
+ ```
176
+
177
+ ## Shell Completions
178
+
179
+ ```bash
180
+ ga completions bash > ~/.bash_completion.d/ga
181
+ ga completions zsh > ~/.zsh/completions/_ga
182
+ ga completions fish > ~/.config/fish/completions/ga.fish
183
+ ```
184
+
185
+ ## Environment Variables
186
+
187
+ | Variable | Description |
188
+ |----------|-------------|
189
+ | `GA_CLI_SERVICE_ACCOUNT` | Path to service account key file |
190
+ | `GOOGLE_APPLICATION_CREDENTIALS` | Standard GCP credential path (fallback) |
191
+ | `GA_CLI_CONFIG_DIR` | Override config directory |
192
+ | `GA_CLI_CLIENT_ID` | OAuth client ID (alternative to client_secret.json) |
193
+ | `GA_CLI_CLIENT_SECRET` | OAuth client secret (alternative to client_secret.json) |
194
+ | `NO_COLOR` | Disable colored output |
195
+
196
+ ## CI/CD Integration
197
+
198
+ ```yaml
199
+ jobs:
200
+ ga-report:
201
+ runs-on: ubuntu-latest
202
+ steps:
203
+ - name: Install GA CLI
204
+ run: pip install google-analytics-cli
205
+
206
+ - name: Export daily report
207
+ run: |
208
+ echo '${{ secrets.GA_SERVICE_ACCOUNT_KEY }}' > /tmp/sa-key.json
209
+ ga auth login --service-account /tmp/sa-key.json
210
+ ga reports run -p ${{ vars.GA_PROPERTY_ID }} \
211
+ --metrics sessions,users --dimensions date \
212
+ --start-date 7daysAgo -o json > report.json
213
+ rm /tmp/sa-key.json
214
+ ```
215
+
216
+ ## Privacy
217
+
218
+ GA CLI stores authentication credentials locally on your machine. No data is sent to any third party — all communication is directly between your machine and Google's APIs.
219
+
220
+ ## Development
221
+
222
+ ```bash
223
+ # Install with dev dependencies
224
+ uv sync
225
+
226
+ # Run the CLI
227
+ uv run ga --help
228
+
229
+ # Run tests
230
+ uv run pytest
231
+
232
+ # Lint
233
+ uv run ruff check src/ tests/
234
+ ```
235
+
236
+ ## License
237
+
238
+ MIT
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ PACKAGE="ga-cli"
5
+
6
+ echo "Installing ${PACKAGE}..."
7
+
8
+ # 1. Detect platform
9
+ OS="$(uname -s)"
10
+ case "${OS}" in
11
+ Linux|Darwin) ;;
12
+ *)
13
+ echo "Error: Unsupported platform '${OS}'. Only Linux and macOS are supported." >&2
14
+ exit 1
15
+ ;;
16
+ esac
17
+
18
+ # 2. Find installer and install
19
+ if command -v pipx &>/dev/null; then
20
+ echo "Using pipx..."
21
+ pipx install "${PACKAGE}"
22
+ elif command -v uv &>/dev/null; then
23
+ echo "Using uv..."
24
+ uv tool install "${PACKAGE}"
25
+ elif command -v pip &>/dev/null; then
26
+ echo "Using pip..."
27
+ pip install "${PACKAGE}"
28
+ elif command -v pip3 &>/dev/null; then
29
+ echo "Using pip3..."
30
+ pip3 install "${PACKAGE}"
31
+ else
32
+ echo "Error: No package installer found. Install pipx, uv, or pip first." >&2
33
+ echo " pipx: https://pypa.github.io/pipx/" >&2
34
+ echo " uv: https://docs.astral.sh/uv/" >&2
35
+ echo " pip: https://pip.pypa.io/" >&2
36
+ exit 1
37
+ fi
38
+
39
+ # 3. Verify installation
40
+ if command -v ga &>/dev/null; then
41
+ echo ""
42
+ echo "Successfully installed $(ga --version)"
43
+ echo ""
44
+ echo "Get started:"
45
+ echo " ga auth login # Authenticate with Google"
46
+ echo " ga accounts list # List your GA4 accounts"
47
+ echo " ga --help # See all commands"
48
+ else
49
+ echo ""
50
+ echo "Warning: 'ga' command not found in PATH." >&2
51
+ echo "You may need to restart your shell or add the install location to PATH." >&2
52
+ exit 1
53
+ fi