This package is the official Laravel integration for Pirsch Analytics.
- Install this package:
composer require pirsch-analytics/laravel-pirsch
- Add the Pirsch access token to your
.env
file. Leave it empty in non-production environments to disable tracking:# ... PIRSCH_TOKEN=pa_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
This package comes with a TrackPageview
middleware that allows you to track pageviews automatically.
Apply the middleware to your web routes by adding it to the web
key of the $middlewareGroups
property in your app/Http/Kernel.php
class:
protected $middlewareGroups = [
'web' => [
// ...
\Pirsch\Http\Middleware\TrackPageview::class,
],
// ...
];
If you want to manually track pageviews instead, you can use the Pirsch::track()
method.
Calling this method without any arguments will track a pageview for the current HTTP request:
use Pirsch\Facades\Pirsch;
Pirsch::track();
Pirsch allows you to track custom events in order to measure additional information.
You can use the Pirsch::track()
method with a name and optional metadata to track an event:
use Pirsch\Facades\Pirsch;
Pirsch::track(
name: 'Button clicked',
meta: [
'Label' => 'Get started',
],
);