How it works

The scheduled job authenticates with Google, requests a GA4 report for yesterday, formats the result, and sends the message through the Telegram Bot API.

The package uses the same GA4 property ID you see in Google Analytics Admin. Each configured site can point to a different GA4 property.

Recommended access model

Use a Google Cloud service account for your own websites and internal reports. Add the service account to each GA4 property with Viewer access only.

Use OAuth later only if you are building a SaaS where customers connect their own Google Analytics accounts.

Typical report sections

  • Daily totals for users, sessions, views, and events.
  • Previous-day percentage changes.
  • Countries and traffic sources.
  • Top pages and custom event counts.
  • A short note that GA4 data can lag, so the report uses yesterday's completed data.

Setup checklist

  1. Enable the Google Analytics Data API in Google Cloud.
  2. Create a service account and JSON key.
  3. Grant Viewer access in the target GA4 property.
  4. Store GOOGLE_CLIENT_EMAIL, GOOGLE_PRIVATE_KEY, GA4_PROPERTY_ID, TELEGRAM_BOT_TOKEN, and TELEGRAM_CHAT_ID as secrets.
  5. Run the report with dryRun before sending a real Telegram message.