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

Eloquent Viewable Laravel Package

cyrildewit/eloquent-viewable

Track page views on Eloquent models without external analytics. Record views (with optional cooldown), count totals or unique views, filter by period, order models by popularity, and ignore bots/crawlers. Stores each view as a DB record for flexible reporting.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Feature Development: Enables granular analytics for content-heavy applications (e.g., blogs, e-commerce product pages, or SaaS dashboards) without relying on third-party services like Google Analytics.
  • Roadmap Prioritization: Justifies investment in user engagement metrics (e.g., "Most Viewed Posts" leaderboards, trending content dashboards, or A/B testing for visibility).
  • Build vs. Buy: Avoids vendor lock-in (e.g., Mixpanel, Amplitude) and privacy concerns (self-hosted analytics). Reduces dependency on external APIs for core metrics.
  • Use Cases:
    • Content Platforms: Track article/blog post views to surface trending content or personalize recommendations.
    • E-commerce: Monitor product page views to optimize product positioning or retargeting campaigns.
    • SaaS: Measure feature adoption by tracking dashboard/views for key functionalities (e.g., "How many users viewed the billing page?").
    • Gamification: Award badges or rewards based on view counts (e.g., "Top 10 Most Viewed Community Posts").
    • SEO/Marketing: Identify high-traffic content for link-building or paid promotion strategies.

When to Consider This Package

Adopt This Package If:

  • You need self-hosted, lightweight analytics with fine-grained control over view tracking (e.g., time-based, unique, or cooldown-based metrics).
  • Your application uses Eloquent models and you want to avoid bloating your frontend with JavaScript-based analytics (e.g., Google Analytics).
  • You require customizable view tracking (e.g., ignoring bots, setting cooldowns, or storing visitor metadata).
  • Your team prefers open-source solutions over SaaS tools for compliance or cost reasons.
  • You’re building a content-driven platform (e.g., CMS, forum, or media site) where view counts are a core feature (e.g., leaderboards, recommendations).
  • You need real-time or near-real-time analytics without API latency (unlike third-party services).

Look Elsewhere If:

  • You need multi-dimensional analytics (e.g., funnel analysis, event tracking beyond views). Consider Laravel Scout + custom events or Mixpanel.
  • Your traffic volume is extremely high (e.g., millions of daily views), risking database bloat. Evaluate aggregation strategies (e.g., pre-computing counts via cron jobs) or time-series databases (e.g., InfluxDB).
  • You require user segmentation (e.g., tracking views by demographics). Use Google Analytics or Laravel + custom user tracking.
  • You’re building a public-facing website with strict privacy regulations (e.g., GDPR). Ensure compliance with data retention policies and user consent.
  • You need historical trend analysis with complex queries (e.g., cohort analysis). Consider dedicated analytics tools like Metabase or ClickHouse.
  • Your stack doesn’t use Laravel/Eloquent. For non-Laravel apps, evaluate JavaScript-based solutions (e.g., Plausible Analytics) or server-side logging (e.g., ELK Stack).

How to Pitch It (Stakeholders)

For Executives:

"Self-Hosted Analytics to Own Your Data and Boost Engagement"

  • Problem: Third-party analytics tools (e.g., Google Analytics) introduce latency, privacy risks, and vendor lock-in. We lack real-time visibility into how users interact with our core content.
  • Solution: Eloquent Viewable lets us track views natively in Laravel—no external APIs, no bloated frontend code. We can:
    • Surface trending content (e.g., "Most Viewed Posts" widgets) to drive engagement.
    • Optimize product positioning in e-commerce by tracking page views.
    • Measure feature adoption in SaaS without relying on Mixpanel.
  • ROI:
    • Cost savings: Eliminate SaaS analytics fees (e.g., $99+/month for Mixpanel).
    • Performance: Faster than client-side tracking (no API calls to external services).
    • Compliance: Full control over data retention and user privacy.
  • Risk Mitigation:
    • Database growth is managed via caching and cooldowns (e.g., ignore repeat views within 2 hours).
    • Can scale with aggregation (e.g., pre-compute counts via cron jobs).

For Engineers:

"Lightweight, Extensible View Tracking for Eloquent Models"

  • Why This?
    • No dependencies: Pure Laravel/Eloquent—no JavaScript or external APIs.
    • Flexible: Track views by time periods, unique users, or custom collections.
    • Optimized: Built-in caching, database indexes, and crawler detection.
    • Extensible: Override core classes (e.g., View, Visitor) or add custom macros.
  • Key Features:
    • Record views in controllers with one line: views($post)->record().
    • Query views with fluent syntax:
      views($post)->period(Period::pastWeek())->unique()->count();
      
    • Order models by views natively:
      Post::orderByViews()->get(); // Descending
      
    • Ignore bots automatically (configurable).
    • Cache results to reduce database load.
  • Integration:
    • 5-minute setup: Composer install + migration + trait addition to models.
    • Works with Laravel 6–13 and PHP 7.4+.
  • Performance Considerations:
    • Database: Add indexes to viewable_id and visitor columns for large datasets.
    • Caching: Use remember() for frequent queries (e.g., dashboard widgets).
    • Scaling: For high traffic, aggregate counts via cron or use read replicas.
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