Download the PHP package ohseesoftware/laravel-server-analytics without Composer
On this page you can find all versions of the php package ohseesoftware/laravel-server-analytics. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ohseesoftware/laravel-server-analytics
More information about ohseesoftware/laravel-server-analytics
Files in ohseesoftware/laravel-server-analytics
Package laravel-server-analytics
Short Description Server side analytics for your Laravel application or website.
License MIT
Homepage https://github.com/ohseesoftware/laravel-server-analytics
Informations about the package laravel-server-analytics
Laravel Analytics
Server side analytics for your Laravel application or website. No cookies, no tracking :)
Vision
There are a lot of choices out there when it comes to analytics for your web project. With the progress of GDPR, a focus on privacy has emerged. Consumers are now learning that they can be tracked across the web, and are not appreciative of this.
As you develop your next website or project, you may wish to add analytics so you can see how many pageviews, etc you're getting. You may not care to track how a specific visitor got to your website, or the actions they took once they were there. You just want some basic metrics on the activity on your web project.
You've come to the right place.
Goals
- [x] Handled entirely by the backend: this means no client-side JS to add to your site, which means no impact on performance for your users
- [x] Write operations should not impact request performance
- [x] Customizable: we'll track the main aspects of a request (path, status, params, duration, user, etc), but also allow you to attach extra data to a request (such as which entity in your database was accessed or metadata)
- [ ] Ships with a default dashboard to view your data: we'll give you a default dashboard (and seperate route) to view your data
- [ ] Accessible API: in addition to a default dashboard, we'll expose an API you can use to pull custom metrics out of your data
Installation
You can install the package via composer:
Publish the package (config, assets, etc):
Review the configuration file and make changes as necessary:
Run database migrations:
Usage
Basic Usage
For basic request tracking, there's no custom code you need to add to your application other than including the middleware:
If you want to only track a specific middleware group, add it to that group instead of the global $middleware
variable.
Tracking authenticated user
v3.0.0+
By default, the package will automatically track the authenticated user who made the request. This is stored directly in the analytics
table in the user_id
column.
The default migration assumes you users are stored in a users
table with a BIGINT
field type for the primary key. If your users are not stored like that, you should write your own migration. The package also assumes your User
model is located at App\User
. If yours is located in a difference namespace, you can update the user_model
key in the published config file.
When logging a request, the package will use this code to insert the user_id
into the analytics
table:
Excluding Routes
If you'd like to exclude specific routes (or wildcards) from being tracked, you can do so via the addRouteExclusions()
method:
Excluding Request Methods
If you'd like to exclude specific request methods from being tracked, you can do so via the addMethodExclusions()
method:
Excluding Requests From Bots
If you'd like to exclude requests from bots/crawlers, you can set the ignore_bot_requests
configuration value to true
.
We use the Crawl Detect package to detect bots/crawlers.
Request hooks
We provide took optional hooks that you can use to automatically associate extra data with your analytics records: addMetaHook
and addRelationHook
. Both hooks return an array of data that should be associated to the analytics record. You can add as many of each as you'd like throughout your request's lifecycle.
addMetaHook
example:
addRelationHook
example:
There's also helper methods available which call the above hooks for you:
Providing Custom Request Details
We provide sensible defaults for pulling details for the request. However, if you need to pull the details in a different manner, you can provide a custom implementation of the RequestDetails
class:
There's a config value, request_details_class
, which you can set to the FQN of your request details class. We will attempt to resolve that class out of the container when logging requests.
Querying Analytics Records
You can use the AnalyticsRepository
to query data out of the analytics tables. If you need to build a custom query, you can use the query()
method on the repository instance.
There's also a couple query scopes setup on the Analytics
model.
Filter Analytics records that are related to the a given model:
Filter Analytics records that have metadata with a given key:
Filter Analytics records that have a given metadata key/value pair:
Testing
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 [email protected] instead of using the issue tracker.
Credits
- Owen Conti
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.
All versions of laravel-server-analytics with dependencies
doctrine/dbal Version ^3.1
illuminate/bus Version >=8
illuminate/queue Version >=8
illuminate/support Version >=8
jaybizzle/crawler-detect Version ^1.2