Laravel Package for Server-Side GA Event Tracking

Laravel Package for Server-Side GA Event Tracking

Analytics Event Tracking is a Laravel package by pascalbaljet to send Laravel events to Google Analytics from the server-side easily. This package works by fetching the GA client ID on the client-side (via a blade directive) and sending it to the backend for storage in the user’s session, so later events have access to the client ID when sending info to GA.

It integrates with Laravel’s event system, and you only need to implement the ShouldBroadcastToAnalytics interface to send your events to GA.

Here’s an example from the package author’s writeup about the package:

namespace App\Events;

use App\Order;
use TheIconic\Tracking\GoogleAnalytics\Analytics;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use ProtoneMedia\AnalyticsEventTracking\ShouldBroadcastToAnalytics;

class OrderWasPaid implements ShouldBroadcastToAnalytics
    use Dispatchable, SerializesModels;

    public $order;

    public function __construct(Order $order)
        $this->order = $order;

    // optional
    public function withAnalytics(Analytics $analytics)
        $analytics->setEventValue($this->order->sum_in_cents / 100);

    // optional
    public function broadcastAnalyticsActionAs(Analytics $analytics)
        return 'CustomEventAction';

The package’s main features include:

Learn More

Check out the author’s post Tracking events with Google Analytics and a new Laravel package for more details about the creation of this package.

You can learn more about this package, get full installation instructions, and view the source code on GitHub at pascalbaljetmedia/laravel-analytics-event-tracking.

Filed in: News
Laravel News Partners

Laravel Jobs

Senior Full Stack Engineer - Laravel
Laravel partner seeks Lead Developer
Kirschbaum Development Group
Senior Programmer **Immediate Opening** (send resume to
SBG Corp
Web Developer - Laravel
Grand Forks, North Dakota
Center for Rural Health
Senior Full-Stack Laravel Developer
Berlin, Germany


Join 31,000+ others and never miss out on new tips, tutorials, and more.