Skip to content

Collect page view data in your application without third party tracking

License

Notifications You must be signed in to change notification settings

wdev-rs/laravel-analytics

Repository files navigation

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.

About

Collect page view data in your application without third party tracking

Resources

License

Stars

Watchers

Forks

Packages

No packages published