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

Laravel package to retrieve Google Analytics data in your app. Provides simple methods to fetch visitors, page views, and most visited pages over a given period, returning results as Laravel Collections via an easy-to-use facade.

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.
  • Data-Driven Features: Enables rapid development of analytics-powered features like:
    • User engagement dashboards (e.g., "Top Pages," "Referrers").
    • A/B testing insights (e.g., comparing traffic sources, device types).
    • Automated alerts (e.g., "Traffic dropped 30% this week").
  • Roadmap Prioritization: Supports prioritizing features tied to user behavior (e.g., "Top 10% of pages drive 80% of traffic").
  • Monetization Strategies: Validates hypotheses for paid features (e.g., "Premium users spend 2x longer on page X").
  • Compliance/Reporting: Simplifies generation of GA4-compliant reports for stakeholders (e.g., "Monthly active users by country").

When to Consider This Package

  • Adopt if:

    • Your Laravel app relies on GA4 data for decision-making (e.g., marketing, product, or growth teams).
    • You need pre-built metrics (e.g., pageviews, user types, device breakdowns) without writing raw API calls.
    • Your team lacks Google Analytics API expertise but requires structured data access.
    • You want to cache responses (configurable) to reduce API costs and latency.
    • You’re using Laravel and want to leverage its ecosystem (e.g., Collections, Carbon).
  • Look elsewhere if:

    • You need real-time analytics (this package caches by default; GA4 API has a 24–48-hour delay for some metrics).
    • Your use case requires custom event tracking beyond standard GA4 metrics (consider raw API or a dedicated analytics tool).
    • You’re not using GA4 (this package is GA4-specific; Universal Analytics is deprecated).
    • You need multi-property aggregation (package focuses on a single property_id).
    • Your team prefers serverless or non-PHP solutions (e.g., Google’s official client libraries in Node.js/Python).

How to Pitch It (Stakeholders)

For Executives:

*"This package lets us tap into Google Analytics data without hiring a data engineer or building a custom API integration. For example, we can instantly answer questions like:

  • ‘Which pages are driving the most traffic?’Analytics::fetchMostVisitedPages()
  • ‘Are our marketing campaigns working?’Analytics::fetchTopReferrers()
  • ‘What devices are our users on?’Analytics::fetchTopBrowsers()

It’s secure (service account-based), cost-effective (caches responses), and scalable—all while reducing our backend team’s workload. We can use this to:

  • Accelerate feature prioritization (e.g., ‘Users spend 3x longer on X’).
  • Automate reports for stakeholders (e.g., monthly traffic trends).
  • Validate growth experiments (e.g., ‘Did the new CTA increase conversions?’).

Risk: Minimal—it’s a battle-tested open-source package with 3,000+ stars. ROI: Days saved on development vs. months of custom work."*


For Engineering:

*"This is a drop-in Laravel facade for GA4’s Data API. Key benefits:

  • No OAuth headaches: Uses service accounts (no user credentials needed).
  • Laravel-native: Returns Collection objects—integrates seamlessly with Eloquent, Blade, or queues.
  • Flexible queries: Need custom metrics? Use the get() method with GA4’s API schema.
  • Testable: Built-in faking for unit tests (Analytics::fake()).
  • Configurable caching: Reduces API calls (default: 24-hour cache).

Trade-offs:

  • Not real-time: GA4’s API has delays (24–48 hours for some metrics).
  • Single property: Configure one property_id per install (workaround: multiple Laravel instances or dynamic config).

Example workflow:

// Get top 5 pages for the last 30 days
$topPages = Analytics::fetchMostVisitedPages(Period::days(30))
    ->take(5)
    ->pluck('pageTitle', 'screenPageViews');

// Use in a dashboard or alert system
if ($topPages->first()['screenPageViews'] < 1000) {
    notify('Traffic alert: Top page views dropped!');
}

Setup time: ~1 hour (Google API setup + Laravel config). Maintenance: None—updates are handled via Composer."*

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.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony