Download the PHP package frnkly/laravel-keen without Composer
On this page you can find all versions of the php package frnkly/laravel-keen. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-keen
Laravel + Keen.io
Defer sending event data to Keen.io until after a request has been fulfilled–automatically and transparently.
This package provides a light wrapper around the Keen PHP client, as well as a middleware configured to defer sending event data to Keen until after each request has been fulfilled. That means that as the number of tracked events increase, the impact on request time remains virtually non-existent. For convenience, the middleware can also track every request automatically.
- Features
- Installation
- Configuration
- Getting started
- Automatic tracking of every request
- Data enrichment
- Using your own middleware
- Skipping requests
- Type-hinting
Features
- [x] Deferred event tracking :raised_hands:
- [x] Optional automatic tracking of every request
- [x] Support data enrichment out of the box
- [x] IP to Geo
- [x] User Agent
- [x] Referrer
- [x] Extensible middleware
- [x] Option to ignore specific HTTP status codes (e.g.
100
,302
, etc.)- [x] Or any request based on custom logic
- [ ] More to come!
Installation
Install the Laravel + Keen package using Composer:
$ composer require frnkly/laravel-keen
This will also install the Keen PHP client as a dependency.
Configuration
Your Keen project ID and keys should be defined in the config/services.php
configuration file, but will usually come from the
environment configuration:
And in your .env
file, you might add something like:
Getting started
Register the middleware globally in app/Http/Kernel.php
:
Or within a middleware group:
Thanks to package discovery
in Laravel 5.5, the service provider should already be available. It can
also be manually registered through the config/app.php
configuration file:
Automatic tracking of every request
Automatic tracking is enabled by default. You may disable this behaviour through the configuration file:
Data enrichment
To automatically add data enrichment to each request, use the following configuration options:
Each data enrichment object will appear in your Keen stream under the same
name as above (i.e. ip_to_geo
and ua_parser
).
Using your own middleware
The included middleware makes it simple to extend and gain more
granular control over the data that gets sent to Keen. You can create your own
middleware using Artisan
, and then have it extend
\Frnkly\LaravelKeen\Middleware
:
$ php artisan make:middleware TracksRequests
Inside the new middleware, override the protected method
buildRequestEventData
:
Remember to update your app/Http/Kernel.php
file to use your own middleware
class instead of the pre-configured one.
Skipping requests
Some response codes do not need to be tracked, such as redirects. You can configure a list of response codes to ignore in your middleware:
You may also override the shouldRun
method in the middleware:
Type-hinting
The LaravelKeen client can be type-hinted in the constructor of any class that is resolved by the container:
Controllers can also take advantage of method injection:
This project is licensed under the MIT license.
I'd love to hear your comments or questions about this project. If you have an idea on how to improve it, create an issue or get in touch.