Commands to interact with Google Analytics 4 (GA4) using the Analytics Data API
This package provides aux4 command wrappers for the Google Analytics Data API (GA4). It covers running standard reports with dimensions, metrics, and date ranges, querying realtime data, and discovering available dimensions and metrics for a property.
Authentication is handled by community/google-auth, which stores a single OAuth2 token shared by every aux4 Google package.
aux4 aux4 pkger install community/google-analytics
This package requires:
brew install jqapt install jqAuthenticate once with community/google-auth. The scopes are resolved from the installed Google service packages, so no --scopes flag is needed:
aux4 google auth login
This package requests https://www.googleapis.com/auth/analytics.readonly, which is enough for every command it exposes. Because that scope is already read-only, aux4 google auth login --readonly true requests exactly the same thing.
Check the current state at any time:
aux4 google auth status
Run a report for the last 7 days:
aux4 google analytics report 123456789 --startDate 7daysAgo --endDate today
Check realtime active users:
aux4 google analytics realtime 123456789
Discover available dimensions and metrics:
aux4 google analytics metadata 123456789
Run a report with default dimensions (date) and metrics (sessions, activeUsers):
aux4 google analytics report 123456789 --startDate 7daysAgo --endDate today
Specify custom dimensions and metrics:
aux4 google analytics report 123456789 --startDate 30daysAgo --endDate today --dimensions date,country --metrics sessions,screenPageViews --limit 100
Dates can be absolute (YYYY-MM-DD) or relative (today, yesterday, 7daysAgo, 30daysAgo, 90daysAgo, 365daysAgo).
date, dateHour — time-based groupingcountry, city, region — geographypagePath, pageTitle, landingPage — contentsessionSource, sessionMedium, sessionCampaignName — traffic sourcedeviceCategory, browser, operatingSystem — technologysessions, activeUsers, newUsers — audiencescreenPageViews, averageSessionDuration, bounceRate — engagementconversions, totalRevenue — conversionsUse aux4 google analytics metadata <propertyId> to see all available options.
Check current active users:
aux4 google analytics realtime 123456789
Active users by country:
aux4 google analytics realtime 123456789 --metrics activeUsers --dimensions country
Active users by page:
aux4 google analytics realtime 123456789 --metrics activeUsers,screenPageViews --dimensions unifiedScreenName
List all available dimensions and metrics for a property:
aux4 google analytics metadata 123456789
Filter to just dimension names:
aux4 google analytics metadata 123456789 | aux4 json get --path '$.dimensions' | aux4 2table --table apiName,uiName
Your GA4 property ID is a numeric identifier found in Google Analytics:
AUX4_GOOGLE_TOKEN_FILE — where the shared Google OAuth token lives. Defaults to ~/.aux4.config/.oauth/google.json, the same location aux4 google auth login writes to, so it normally needs no setting.For the optional integration test group, set GA4_PROPERTY_ID to your GA4 property ID.
MIT — See LICENSE for details.