PHP code example of andreaselia / analytics

1. Go to this page and download the library: Download andreaselia/analytics library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

andreaselia / analytics example snippets


Route::middleware('analytics')->group(function () {
    // ...
});

// app/Http/Kernel.php

protected $middleware = [
    // ...
    \AndreasElia\Analytics\Http\Middleware\Analytics::class,
];

// bootstrap/app.php

->withMiddleware(function (Middleware $middleware) {
    $middleware->web(append: [
        \AndreasElia\Analytics\Http\Middleware\Analytics::class,
    ]);
})

> 'middleware' => [
>     'web',
>     'auth',
>     // 'can:viewAnalytics', // with Gate::define('viewAnalytics', fn ($user) => ...)
> ],
> 

'ignoreMethods' => [
    'POST',
],

'ignoredColumns' => [
    'source',
    'host',
],

use AndreasElia\Analytics\Models\PageView;

public function boot()
{
    PageView::resolveTimezoneUsing(function () {
        return request()->user()?->timezone;
    });
}

    protected function dashboards(): array
    {
        return [
            new \AndreasElia\Analytics\Nova\Dashboards\Analytics,
        ];
    }

    protected function cards(): array
    {
        return [
            new \AndreasElia\Analytics\Nova\Metrics\Devices,
            new \AndreasElia\Analytics\Nova\Metrics\PageViews,
            new \AndreasElia\Analytics\Nova\Metrics\UniqueUsers,
        ];
    }
bash
php artisan vendor:publish --provider="AndreasElia\Analytics\AnalyticsServiceProvider"
bash
php artisan migrate