← Labs

GA4 CLI

Google Analytics 4 from the command line.

OAuth2 authentication, custom reports, date comparisons, and flexible export formats. Retrieve GA4 data directly in your terminal.

View on NPM

Install

Install globally via npm:

npm install -g kanmi-ga4-cli

Or as part of the complete suite:

npm install -g kanmi-suite-cli

Features

OAuth2 Auth

Secure authentication with automatic token management.

Custom Reports

Any metric and dimension combination for analysis.

Date Comparisons

Compare periods with automatic calculations.

Export Formats

Table, JSON, Markdown, or CSV output.

Usage

Authentication

ga4-cli auth

List Properties

ga4-cli properties --format table

Generate Report

ga4-cli report \ --property "123456789" \ --metrics "sessions,pageviews,users" \ --dimensions "date" \ --date-range "last-7-days" \ --format json

Compare Periods

ga4-cli compare \ --property "123456789" \ --current "last-7-days" \ --previous "previous-7-days"

Top Events

ga4-cli top-events \ --property "123456789" \ --limit 10 \ --date-range "last-30-days"

Setup

Requires a Google Cloud Project with Analytics Data API enabled.

# Environment variables GA4_CREDENTIALS_PATH=/path/to/credentials.json GA4_DEFAULT_PROPERTY=123456789

Links

NPM · GitHub