Skip to content

Official Laravel integration for Pirsch Analytics.

License

Notifications You must be signed in to change notification settings

Autive/laravel-pirsch

 
 

Repository files navigation

Packagist Version Packagist Downloads

Pirsch for Laravel

This package is the official Laravel integration for Pirsch Analytics.

Installation

  1. Install this package:

    composer require pirsch-analytics/laravel-pirsch
  2. Add the Pirsch access token to your .env file. Leave it empty in non-production environments to disable tracking:

    1. Visit the Pirsch "Integration" settings page.

    2. Make sure the correct domain is selected in the top left corner of the page.

    3. Scroll down to the "Clients" section and press the "Add Client" button.

    4. Select "Access Key (write-only)" as type and enter a description.

    5. Press the "Create Client" button and copy the generated "Client secret".

    6. 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 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,
    ],

    // ...
];

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',
    ],
);

About

Official Laravel integration for Pirsch Analytics.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%