PHP code example of fyrndly / laravel-matomo-tracker

1. Go to this page and download the library: Download fyrndly/laravel-matomo-tracker library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fyrndly / laravel-matomo-tracker example snippets


use FyrnDly\Matomo\Facades\Matomo;

// Track a Page View
Matomo::pageView('Home Page');

// Track a Goal
Matomo::goal(1, 50.0);

// Track Site Search
Matomo::search('search keyword', 'category', 10);

// Simple Event
Matomo::event('Category', 'Action', 'Simple Name');

// Event with Payload (Array/Object)
$data = [
    'user_type' => 'premium',
    'source' => 'referral',
    'step' => 3
];

Matomo::event('Onboarding', 'StepCompleted', $data);

use Livewire\Component;
use FyrnDly\Matomo\Traits\MatomoTrackView;

class Dashboard extends Component
{
    use MatomoTrackView;

    public $pageTitle = 'Main Dashboard'; // Automatically tracked as "Go to page Main Dashboard"
}

Matomo::setCustomDimension(1, 'Premium User')
    ->pageView('Dashboard');

Matomo::setUserId('custom-user-id')->pageView('Profile Page');

$rawTracker = Matomo::getRawTracker();
bash
php artisan vendor:publish --tag="matomo-config"