Weave Code
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 Analytics Laravel Package

spatie/laravel-analytics

Fetch Google Analytics data in Laravel via a simple facade. Query visitors, pageviews, most visited pages and more for a given period, returning Collections. Easy install, configurable credentials, and ready-to-use methods for common reports.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Build vs. Buy: Eliminates the need to build custom Google Analytics (GA4) integration from scratch, reducing development time and maintenance overhead.
  • Roadmap Alignment: Enables rapid delivery of analytics-driven features (e.g., dashboards, A/B testing insights, or user segmentation) without blocking on backend work.
  • Use Cases:
    • Product Analytics: Track feature adoption, user engagement, and conversion funnels (e.g., fetchVisitorsAndPageViews for cohort analysis).
    • Marketing Insights: Identify top-performing traffic sources (fetchTopReferrers) or geographies (fetchTopCountries) to optimize campaigns.
    • Technical Debt: Replace legacy ad-hoc GA queries with a standardized, cacheable API layer.
    • Data-Driven Decisions: Power real-time or scheduled reports (e.g., weekly traffic trends) via Laravel’s scheduling system.
  • Monetization: Justify premium features (e.g., "Enterprise Analytics") by leveraging GA4’s granularity without exposing raw API keys.

When to Consider This Package

  • Adopt if:
    • Your Laravel app relies on GA4 (not Universal Analytics) and needs structured, programmatic access to metrics.
    • You lack in-house expertise in Google’s Analytics Data API but require custom queries (e.g., filtering by event parameters).
    • You want to cache responses (configurable via cache_lifetime_in_minutes) to reduce API costs and latency.
    • Your team prioritizes developer velocity over full control (e.g., no need for real-time streaming or BigQuery exports).
  • Look elsewhere if:
    • You need Universal Analytics support (this package is GA4-only).
    • Your use case requires advanced filtering (e.g., complex SQL-like queries) beyond what FilterExpression supports.
    • You’re already using a dedicated analytics platform (e.g., Mixpanel, Amplitude) and only need lightweight GA4 integration.
    • Your app has high-scale traffic (>100K daily sessions), requiring custom pagination or batching logic not covered by the offset/maxResults params.
    • You need historical data migration tools or cross-property analysis (this package is single-property focused).

How to Pitch It (Stakeholders)

For Executives: "This package lets us tap into Google Analytics 4 data directly from our Laravel backend—no more manual exports or third-party tools. We can automate reports (e.g., weekly traffic trends), power personalized user experiences (e.g., ‘Top pages for returning users’), and reduce costs by caching API responses. It’s a 3-month time-saver compared to building this in-house, with minimal ongoing maintenance. For ~$0 upfront (MIT license), we get enterprise-grade analytics integration."

For Engineers: *"Spatie’s package abstracts the Google Analytics Data API into Laravel-friendly methods (e.g., fetchMostVisitedPages() returns a Collection). Key benefits:

  • Zero API boilerplate: Handles OAuth, caching, and pagination under the hood.
  • Flexible queries: Need custom metrics? Use the get() method with GA4’s API schema.
  • Testable: Built-in faking for unit tests (Analytics::fake()).
  • Secure: Credentials are stored locally (not in .env) and never committed to Git. Tradeoff: Limited to GA4; if you hit scale limits, we can extend it with custom logic."*

For Data Teams: *"This gives product teams self-service access to GA4 data without relying on us. For example:

  • Marketing: Pull top referrers (fetchTopReferrers) to optimize ad spend.
  • Product: Track feature usage via custom events (e.g., filter by eventName=‘checkout_start’).
  • Support: Identify user drop-off pages with fetchMostVisitedPages. We’ll document common queries in our internal wiki to standardize usage."
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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai