pirsch-analytics / laravel-pirsch
Official Laravel integration for Pirsch Analytics.
Fund package maintenance!
zepfietje
Installs: 24 574
Dependents: 1
Suggesters: 0
Security: 0
Stars: 41
Watchers: 2
Forks: 5
Open Issues: 1
Requires
- php: ^8.1
- illuminate/contracts: ^9.0|^10.0|^11.0
- illuminate/http: ^9.0|^10.0|^11.0
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- larastan/larastan: ^2.0.1
- laravel/pint: ^0.2.2
- nunomaduro/collision: ^6.0|^7.0|^8.0
- orchestra/testbench: ^7.0|^8.0|^9.0
- pestphp/pest-plugin-laravel: ^1.1|^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5|^10.0
- spatie/laravel-ray: ^1.26
README
Pirsch for Laravel
This package is the official Laravel integration for Pirsch Analytics.
Installation
-
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:-
Visit the Pirsch "Integration" settings page.
-
Make sure the correct domain is selected in the top left corner of the page.
-
Scroll down to the "Clients" section and press the "Add Client" button.
-
Select "Access Key (write-only)" as type and enter a description.
-
Press the "Create Client" button and copy the generated "Client secret".
-
Add the copied token to your
.env
file:# ... PIRSCH_TOKEN=pa_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-
Usage
Track pageviews
Automatically
This package comes with a TrackPageview
middleware that allows you to track pageviews automatically.
Apply the middleware to your web routes by appending it in the withMiddleware
method in your bootstrap/app.php
file:
->withMiddleware(function (Middleware $middleware) { $middleware->web(append: [ \Pirsch\Http\Middleware\TrackPageview::class, ]); })
Manually
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();
Track events
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', ], );