Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Metrics Ga4 Laravel Package

jeffersongoncalves/laravel-metrics-ga4

Laravel package for pulling Google Analytics 4 metrics into your app, making it easy to query GA4 data and surface reports or dashboard stats without writing boilerplate API code.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Build vs. buy for analytics plumbing. The reusable work here is auth and transport (locally-signed JWT, cached access tokens) plus a vocabulary layer that maps product-language metrics (visitors, visits, pageviews, bounce_rate, visit_duration) onto GA4's metric names. That is exactly the undifferentiated code a team would otherwise hand-roll and maintain across GA4 API version changes — a strong argument for adopting rather than building.
  • Roadmap: in-product analytics surfaces. The facade's shape telegraphs the intended use cases — timeseries and breakdown for trend charts, pages/sources/countries/browsers/devices for standard report tabs, realtimeVisitors for a live-now widget, runReport as the escape hatch for anything custom. If the roadmap includes an internal dashboard, admin reporting, or "audience" panels, this package shortens the estimate to roughly UI work plus query design.
  • Scope boundary: data access, not presentation. This ships no views, no caching layer for reports, no scheduled exports, and no charting. Any roadmap item implying a dashboard still carries full front-end and query-cost design work; the package de-risks the bottom of the stack, not the top.
  • Single-property assumption is a product constraint. Configuration comes from GA4_PROPERTY_ID and GA4_SERVICE_ACCOUNT_JSON and is persisted through spatie/laravel-settings, which reads as one property per application instance. For a multi-tenant SaaS where each customer connects their own GA4 property, plan for per-tenant settings, credential isolation, and a connection/verification flow — that is net-new work this release does not cover.
  • Operational decisions get easier. RateLimitException and AuthenticationException are separately catchable, which makes quota-aware backoff, alerting, and graceful degradation (stale cache vs. error state) explicit product decisions rather than incidental code paths.
  • Security posture is a decision input, not a detail. Encrypted service-account key storage via spatie/laravel-settings adds a dependency and a key-rotation/secret-management obligation. Worth confirming with security before it becomes a launch blocker.
  • Data-quality expectations must be set with stakeholders. GA4 reporting is subject to sampling, thresholding, and data-freshness lag; the package faithfully returns what the API returns. Product should not commit to "exact" or "real-time-accurate" numbers in customer-facing copy without validating against a known-good source.

When to Consider This Package

Adopt when most of the following hold:

  • GA4 is already the system of record for web analytics and nobody wants to migrate off it.
  • The need is server-side reporting inside a Laravel app — admin dashboards, customer-facing stats, scheduled digest emails, live-visitor indicators.
  • The application needs a small, stable set of standard questions (traffic over time, top pages, acquisition sources, geo/device/browser splits) rather than arbitrary GA4 exploration.
  • The stack is PHP 8.2+ on Laravel 11, 12, or 13, and spatie/laravel-settings is acceptable as a dependency.
  • The team wants typed failure modes so quota and credential problems degrade gracefully instead of throwing opaque errors.
  • You value a 1.0.0 semver commitment from a small surface area over a broader but less stable integration.

Look elsewhere — or budget for extra build — when:

  • You need event-level or raw data (BigQuery export, ETL into a warehouse, custom attribution modeling). This is an aggregation client; it will not serve that.
  • You need the GA4 Admin API (creating properties, managing data streams, audiences) or client-side tagging. Out of scope here.
  • You require per-tenant property isolation as a first-class feature; the env-seeded single-property model will need rework.
  • The environment is PHP < 8.2 or Laravel ≤ 10, or the project cannot take a settings-package dependency.
  • You need vendor-neutral analytics (self-hosted, privacy-first, or multi-source) — the metric-name mapping is deliberately GA4-shaped and would become a leaky abstraction.
  • You need heavy reporting volume; GA4 API quotas, not this package, will be the binding constraint, and you should model caching strategy before committing to customer-facing SLAs.

How to Pitch It (Stakeholders)

For executives: A small, focused integration that lets our Laravel application pull Google Analytics 4 numbers directly — traffic trends, top pages, acquisition sources, geography, device and browser splits, and a live-visitor count — without us building or maintaining the authentication and API plumbing ourselves. It replaces custom code with a supported dependency at 1.0.0, which means we get the analytics capability faster and carry less long-term maintenance risk. Cost is effectively our engineering time; the GA4 Data API itself is free, though subject to Google's rate limits.

For engineering: ~10 lines of surface area: a GA4 facade with report-shaped methods, a product-metric vocabulary mapped to GA4 metrics, runReport as the raw escape hatch, and three typed exceptions including a distinct RateLimitException for quota handling. Auth is self-contained — JWT signed locally with OpenSSL, access tokens cached, service-account key encrypted at rest via spatie/laravel-settings and seeded from GA4_PROPERTY_ID / GA4_SERVICE_ACCOUNT_JSON. Constraints to design around: one property per instance (multi-tenancy is our work), no report caching or scheduling (ours to add), PHP 8.2+ and Laravel 11–13 only. Treat the service-account key as a production secret with a rotation plan from day one.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
mehedimi/laravel-amp-mail
happones/laravel-vue-i18n-generator
jwerd/inertia-table
siberfx/flysystem-wasabi
hollyit/token-replace
ippanelcom/laravel-sdk
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel