{"id":16668331,"url":"https://github.com/andreaselia/laravel-analytics","last_synced_at":"2025-05-15T16:03:07.022Z","repository":{"id":44194550,"uuid":"325614199","full_name":"andreaselia/laravel-analytics","owner":"andreaselia","description":"Analytics for the Laravel framework.","archived":false,"fork":false,"pushed_at":"2025-03-02T10:22:14.000Z","size":344,"stargazers_count":188,"open_issues_count":1,"forks_count":29,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-05-08T08:47:01.450Z","etag":null,"topics":["analytics","dashboard","laravel","laravel-analytics","middleware","package","php","self-hosted"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andreaselia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["andreaselia"]}},"created_at":"2020-12-30T17:53:00.000Z","updated_at":"2025-05-07T10:25:21.000Z","dependencies_parsed_at":"2023-09-26T01:49:15.821Z","dependency_job_id":"87ab53a3-6248-4562-a5f5-1b307bafd8dd","html_url":"https://github.com/andreaselia/laravel-analytics","commit_stats":{"total_commits":136,"total_committers":12,"mean_commits":"11.333333333333334","dds":0.3970588235294118,"last_synced_commit":"6eb5be7aee7c18ffbf103c83dfdd7f6b27880099"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreaselia%2Flaravel-analytics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreaselia%2Flaravel-analytics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreaselia%2Flaravel-analytics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreaselia%2Flaravel-analytics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreaselia","download_url":"https://codeload.github.com/andreaselia/laravel-analytics/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254374399,"owners_count":22060609,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analytics","dashboard","laravel","laravel-analytics","middleware","package","php","self-hosted"],"created_at":"2024-10-12T11:24:34.796Z","updated_at":"2025-05-15T16:03:07.002Z","avatar_url":"https://github.com/andreaselia.png","language":"PHP","funding_links":["https://github.com/sponsors/andreaselia"],"categories":[],"sub_categories":[],"readme":"# Laravel Analytics\n\n[![Latest Stable Version](https://poser.pugx.org/andreaselia/analytics/v)](//packagist.org/packages/andreaselia/analytics)\n\nEasily collect page view analytics with a beautifully simple to use dashboard.\n\n![Laravel Analytics Dashboard](/screenshot.png?raw=true \"Laravel Analytics Dashboard\")\n\n## Installation\n\nInstall the package:\n\n```bash\ncomposer require andreaselia/analytics\n```\n\nPublish the config file and assets:\n\n```bash\nphp artisan vendor:publish --provider=\"AndreasElia\\Analytics\\AnalyticsServiceProvider\"\n```\n\nDon't forget to run the migrations:\n\n```bash\nphp artisan migrate\n```\n\nYou can add the page view middleware to a specific route group, e.g. `web.php` like so:\n\n```php\nRoute::middleware('analytics')-\u003egroup(function () {\n    // ...\n});\n```\n\nOr add the page view to all middlewares/on an application level like so:\n\n```php\n// app/Http/Kernel.php\n\nprotected $middleware = [\n    // ...\n    \\AndreasElia\\Analytics\\Http\\Middleware\\Analytics::class,\n];\n```\n\n## Configuration\n\n### Disabling tracking\n\nYou can disable tracking by setting the environment variable `ANALYTICS_ENABLED` or the `enabled` property in the `analytics.php` config file to `false`.\n\n### Excluding routes\n\nYou can exclude certain routes from being tracked by adding them to the `exclude` array in the `analytics.php` config file.\n\n### Ignore robots\n\nYou can ignore requests from robots by setting the `ignoreRobots` property in the `analytics.php` config file.\n\n### Ignore specific IP addresses\n\nYou can ignore requests from specific IP addresses by adding them to the `ignoreIps` array in the `analytics.php` config file.\n\n### Masking routes\n\nYou can mask certain routes from being tracked by adding them to the `mask` array in the `analytics.php` config file. \nThis is useful if you want to track the same route with different parameters, e.g. `/users/1` and `/users/2` will be tracked as `/users/∗︎`.\n\n### Ignoring certain HTTP verbs/methods\n\nYou can ignore the tracking of some methods by adding them to the `analytics.ignoreMethods` config option. For example, if you don't want to track `POST` requests, you can configure it like so:\n\n```php\n'ignoreMethods' =\u003e [\n    'POST',\n],\n```\n\n### Changing how session_id is determined\n\nBy default, `session_id` in the `page_views` table is filled with the session ID of the current request. However, in certain scenarios (for example, for API and other requests not using cookies), the session is unavailable.\n\nIn these cases, you can create a custom session ID provider: create a class that implements the `AndreasElia\\Analytics\\Contracts\\SessionProvider` interface and set its name as the `provider` option in the `analytics.php` config file. The configured class object is resolved from the container, therefore, dependency injection can be used via the `__constructor`. \n\nOne example of a custom way to generate the session ID in cookie-less environment is to hash IP address + User Agent + some other headers from the request.\n\nFeel free to take a look at `AndreasElia\\Analytics\\RequestSessionProvider` for an example of implementing the `SessionProvider` interface.\n\n### Changing how the timezone for \"today\" and \"yesterday\" is determined\n\nSince timestamps are stored using your application's timezone, you may get mixed results depending on when you check views for \"today\" and \"yesterday\" and your actual timezone. You can change the relative time for whatever \"now\" is by setting a callback in a service provider.\n\n```php\nuse AndreasElia\\Analytics\\Models\\PageView;\n\npublic function boot()\n{\n    PageView::resolveTimezoneUsing(function () {\n        return request()-\u003euser()?-\u003etimezone;\n    });\n}\n```\n\nYou can return a dynamic value like the example above, or a static value. If one isn't determined, it will just fall back to the `config('app.timezone')` value.\n\n## Laravel Nova\n\nThe package comes with a dashboard and metrics for Laravel Nova.\n\n### Dashboard\n\nYou can add the dashboard to Laravel Nova by adding `new \\AndreasElia\\Analytics\\Nova\\Dashboards\\Analytics` to `dashboards` array in your `NovaServiceProvider`:\n\n```php\n    protected function dashboards(): array\n    {\n        return [\n            new \\AndreasElia\\Analytics\\Nova\\Dashboards\\Analytics,\n        ];\n    }\n```\n\n### Metrics\n\nAlternatively, you can add the metrics to your own Laravel Nova dashboard by adding them to the `cards` array in your dashboard file.\n\n```php\n    protected function cards(): array\n    {\n        return [\n            new \\AndreasElia\\Analytics\\Nova\\Metrics\\Devices,\n            new \\AndreasElia\\Analytics\\Nova\\Metrics\\PageViews,\n            new \\AndreasElia\\Analytics\\Nova\\Metrics\\UniqueUsers,\n        ];\n    }\n```\n\n## Contributing\n\nYou're more than welcome to submit a pull request, or if you're not feeling up to it - create an issue so someone else can pick it up.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreaselia%2Flaravel-analytics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreaselia%2Flaravel-analytics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreaselia%2Flaravel-analytics/lists"}