fojlerabbirabib/laravel-spa-analytics
A Laravel package for adding SPA analytics to single-page applications, helping you track page views and user activity without full page reloads. Lightweight and easy to integrate into Laravel projects.
Architecture fit: The package fits Laravel applications that need first-party SPA analytics without introducing a separate analytics service. The v0.8.0 release improves architectural flexibility by allowing package tables to live on a dedicated database connection, which is useful for separating analytics workloads from transactional data. The folded migration strategy and guarded upgrade migration make the package easier to reason about across environments, especially for teams that have delayed upgrades. Inertia-aware page-view tracking is a meaningful fit for Laravel applications using Inertia as their SPA layer.
Integration feasibility: Integration is feasible for a standard Laravel deployment: publish config, publish migrations, run migrate, publish assets, and include the @spaAnalytics directive. The optional database connection requires an intentional setup step: re-publish migrations with --force because the connection is named in the migration files. The automatic cleanup of old update_analytics_* migration files reduces manual upgrade work, but teams should validate it in staging because it modifies application migration files outside vendor/. Published view customizations require a manual copy of src="{{ $scriptUrl }}" into client-script.blade.php.
Technical risk: Risk is moderate but manageable. The main upgrade risks are migration-related: teams must re-publish migrations, run migrate, and confirm that the automatic deletion of old migration files behaves as expected in their repository and deployment process. The new database connection option moves no data and must be set before the first migrate if desired, so late adoption may require a separate data migration plan. The browser cache fix depends on the web server or CDN keying cache on the query string and deploying the script before HTML; otherwise, stale script risk remains. Inertia prefetch tracking has documented limits: responses slower than five seconds may double-count a visit, and replaceState visits served from cache are still not counted. Because the package is pre-1.0, API and migration behavior may continue to evolve.
Key questions: What Laravel and PHP versions are supported? Which database engines are officially supported beyond the MySQL/MariaDB binary check mentioned? Does the automatic migration cleanup run safely in CI/CD and read-only filesystem environments? How should teams validate Inertia prefetch and back/forward tracking in staging? What is the retention and privacy posture for analytics data, especially if using a separate database connection? Is there an observability path for missed or duplicate page views? What is the recommended rollback procedure if the new update_analytics_tables_rev_2 migration or asset re-publish fails?
Stack fit: The package is a natural fit for Laravel applications already using Blade, Inertia, or a lightweight SPA front end. The new spa-analytics.database.connection option fits teams that want analytics tables isolated on a separate connection, provided they decide this before the first migrate. The ClientScript service being bindable in the container gives TPMs a reasonable extension point if custom asset URL behavior is needed.
Migration path: Upgrade from any prior version directly to v0.8.0 by re-publishing migrations and running migrate. The folded migrations replace the older create_* and update_* set with five final-shape create migrations and one guarded update_analytics_tables_rev_2 migration. Teams should confirm that the old update_analytics_* files are removed from database/migrations and that the migrations table remains intact. If the package views were published, copy the updated src="{{ $scriptUrl }}" line into the local client-script.blade.php. Re-publish the browser script with php artisan vendor:publish --tag=spa-analytics-assets --force.
Compatibility: The release is designed to upgrade from any version straight to v0.8.0. The new database connection key is optional and defaults to null, so existing behavior is preserved. Teams using published views must perform a manual view update. Teams relying on long-lived browser caches must verify CDN or web-server query-string cache behavior. Inertia applications should test prefetch, standard visits, and back/forward navigation after upgrading.
Sequencing: Recommended sequence: (1) decide whether to use a dedicated analytics database connection before migrating; (2) back up the application and database; (3) re-publish package migrations, using --force if adopting the new connection; (4) run migrate in staging and inspect cleanup behavior; (5) re-publish assets with --force; (6) update any published client-script.blade.php view; (7) deploy the updated script before or with the HTML that references it; (8) verify page-view counts for normal, Inertia, prefetch, and back/forward flows; (9) promote to production and monitor event volume and migration state.
Maintenance: Maintenance is relatively low for a Laravel package, but v0.8.0 introduces migration-file cleanup that should be understood by the team owning deployments. The spa-analytics:clean-migrations command and php artisan about output provide useful operational checks. The asset version hash reduces long-lived stale browser script issues, but only when the serving layer respects query-string cache keys.
Support: Support burden is mostly concentrated in upgrade coordination and frontend verification. Teams with customized published views need a documented step to copy the new $scriptUrl usage. Inertia prefetch behavior should be documented internally because the five-second server-side deduplication window and replaceState limitation are non-obvious. A TPM should assign an owner for analytics correctness checks after each package upgrade.
Scaling: The optional dedicated database connection is the main scaling lever in this release, allowing analytics writes, raw queries, and rollup transactions to be isolated from the primary application database. Scaling also depends on the database engine, indexing, and rollup behavior, which are not fully described in the release notes. Asset caching can be scaled aggressively if the deployment order and cache-key behavior are correct. Inertia prefetch tracking adds some server-side deduplication logic but should not materially change scaling characteristics.
Failure modes: Key failure modes include missed page views when Inertia prefetch requests are not handled correctly, duplicate counting when responses exceed the five-second deduplication window, stale browser scripts when CDN or web-server caching ignores query strings, and migration confusion if old files are restored from git or if the new migration is not published correctly. Automatic deletion of exact old migration filenames is safer than broad deletion, but it still modifies application files and should be tested in staging. The new database connection option moves no data, so enabling it after initial migration without planning can cause missing-table or split-data issues.
Ramp-up: Ramp-up is modest for a Laravel team: publish config, migrations, and assets; run migrate; update published views if needed; verify Inertia and prefetch tracking. TPMs should schedule a short staging validation, document the upgrade sequence, and confirm database connection strategy before the first migrate. Once installed, the package offers a low-overhead analytics layer with clear upgrade commands, but teams should treat v0.8.0 as pre-1.0 software and reserve time for compatibility checks on future releases.
How can I help you explore Laravel packages today?