wdev-rs/laravel-analytics

Collect page view data in your application without third party tracking
1,152 15
Install
composer require wdev-rs/laravel-analytics
Latest Version:0.2.3
PHP:^8.0
License:MIT
Last Updated:Apr 5, 2024
Links: GitHub  ·  Packagist
Maintainer: wdev-rs

Very short description of the package

Latest Version on Packagist Total Downloads GitHub Actions

This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors.

Installation

You can install the package via composer:

composer require wdev-rs/laravel-analytics

Install the vue-chartjs integration

npm install vue-chartjs@^4.0.0 chart.js

Publish the vendor files by running

php artisan vendor:publish --provider="WdevRs\LaravelAnalytics\LaravelAnalyticsServiceProvider"

Usage

Run migration

php artisan migrate

Add alias to middleware in app/Http/Kernel.php

    protected $routeMiddleware = [
        ...
        'analytics' => \WdevRs\LaravelAnalytics\Http\Middleware\Analytics::class,
        ...
    ];        

Add the analytics middleware to the routes you'd like to track


Route::middleware(['analytics'])->group(function () {
    Route::get('/', [PagesController::class,'index'])->name('pages.home');
});

Admin

Register the vue components to display analytics

Vue.component('page-views-per-days', require('./vendor/laravel-analytics/components/PageViewsPerDays.vue').default);
Vue.component('page-views-per-paths', require('./vendor/laravel-analytics/components/PageViewsPerPaths.vue').default);

Use the components in your dashboard or where you like :)

Pass the data from controller

        $pageViewRepository = app(PageViewRepository::class);
        $pageViewsPerDays = $pageViewRepository->getByDateGroupedByDays(Carbon::today()->subDays(28));
        $pageViewsPerPaths = $pageViewRepository->getByDateGroupedByPath(Carbon::today()->subDays(28));

        return view('admin.dashboard.index',
            [
                'pageViewsPerDays' => $pageViewsPerDays,
                'pageViewsPerPaths' => $pageViewsPerPaths
            ]);
<page-views-per-days :initial-data="{{json_encode($pageViewsPerDays)}}"/>
<page-views-per-paths :initial-data="{{json_encode($pageViewsPerPaths)}}"/>

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email daniel@wdev.rs instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.

Related Packages

wdev-rs/laravel-datagrid

Laravel integration for Grid.js server side processing

9,521 54
gabrieloliverio/laravel5-generators

Database metadata-based generators for Laravel 5

1
erirk/paypalpayment

laravel-paypalpayment is simple package help you process direct credit card paym...

0
doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

628,058,007 9,707
laravel/framework

The Laravel Framework.

576,155,700 34,907