PHP code example of aimeos / laravel-analytics-bridge

1. Go to this page and download the library: Download aimeos/laravel-analytics-bridge 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/ */

    

aimeos / laravel-analytics-bridge example snippets


return [
    'default' => env('ANALYTICS_DRIVER'),

    'drivers' => [
        'cloudflare' => [
            'siteTag' => env('CLOUDFLARE_SITETAG'),
            'token' => env('CLOUDFLARE_TOKEN'),
        ],
        'ga4' => [
            'propertyid' => env('GOOGLE_PROPERTYID'),
            'credentials' => json_decode(base64_decode(env('GOOGLE_AUTH', '')), true),
        ],
        'matomo' => [
            'url' => env('MATOMO_URL'),
            'token' => env('MATOMO_TOKEN'),
            'siteid' => env('MATOMO_SITEID'),
        ],
    ],

    'google' => [
        'auth' => json_decode(base64_decode(env('GOOGLE_AUTH', '')), true),
        'crux' => [
            'apikey' => env('CRUX_API_KEY'),
        ]
    ]
];

use Aimeos\AnalyticsBridge\Facades\Analytics;

$result = Analytics::stats('https://aimeos.org/features', 30);

// to limit the result set
$result = Analytics::types(['visits', 'referrers'])->stats('https://aimeos.org/features', 30);

[
    'views'     => [
        ['key' => '2025-08-01', 'value' => 123],
        ['key' => '2025-08-02', 'value' => 97],
        ...
    ],
    'visits'    => [
        ['key' => '2025-08-01', 'value' => 53],
        ['key' => '2025-08-02', 'value' => 40],
        ...
    ],
    'conversions' => [
        ['key' => '2025-08-01', 'value' => 15],
        ['key' => '2025-08-02', 'value' => 10],
        ...
    ],
    'durations' => [ // in seconds
        ['key' => '2025-08-01', 'value' => 75],
        ['key' => '2025-08-02', 'value' => 80],
        ...
    ],
    'countries' => [
        ['key' => 'Germany', 'value' => 321],
        ['key' => 'USA', 'value' => 244],
        ...
    ],
    'referrers' => [
        ['key' => 'Direct entry', 'value' => 243, 'rows' => []],
        ['key' => 'Website', 'value' => 199, 'rows' => [
            ['key' => 'https://aimeos.org/', 'value' => 321],
            ['key' => 'https://aimeos.org/Laravel', 'value' => 244],
            ...
        ]],
        ...
    ],
]

$data = Analytics::pagespeed('https://aimeos.org/features');

[
    ['key' => 'round_trip_time', 'value' => 150],
    ['key' => 'time_to_first_byte', 'value' => 700],
    ['key' => 'first_contentful_paint', 'value' => 1200],
    ['key' => 'largest_contentful_paint', 'value' => 1700],
    ['key' => 'interaction_to_next_paint', 'value' => 180],
    ['key' => 'cumulative_layout_shift', 'value' => 0.05],
    /*...*/
]

$data = Analytics::search('https://aimeos.org/features');

[
    'impressions' => [
        ['key' => '2025-08-01', 'value' => 123],
        ['key' => '2025-08-02', 'value' => 97],
        ...
    ],
    'clicks' => [
        ['key' => '2025-08-01', 'value' => 23],
        ['key' => '2025-08-02', 'value' => 14],
        ...
    ],
    'ctrs' => [ // click through rate (between 0 and 1)
        ['key' => '2025-08-01', 'value' => 0.194],
        ['key' => '2025-08-02', 'value' => 0.69],
        ...
    ],

$data = Analytics::queries('https://aimeos.org/features');

[
    ['key' => 'aimeos', 'impressions' => 1234, 'clicks' => 512, 'ctr' => 0.41, 'position' => 1.1],
    ['key' => 'laravel ecommerce', 'impressions' => 2486, 'clicks' => 299, 'ctr' => 0.11, 'position' => 1.9],
    ...

$data = Analytics::indexed('https://aimeos.org/features', 'en-US');



namespace Aimeos\AnalyticsBridge\Drivers;

use Aimeos\AnalyticsBridge\Contracts\Driver;

class Foobar implements Driver
{
    private array $types = ['views', 'visits', 'durations', 'conversions', 'countries', 'referrers'];

    public function __construct(array $config = [])
    {
        // $config from ./config/analytics-bridge.php
    }

    public function stats(string $path, int $days = 30): ?array
    {
        // limit by types if requested
        return [
            'views'     => [['key' => '2025-08-01', 'value' => 123], /*...*/],
            'visits'    => [['key' => '2025-08-01', 'value' => 123], /*...*/],
            'durations' => [['key' => '2025-08-01', 'value' => 123], /*...*/],
            'countries' => [['key' => 'Germany', 'value' => 321], /*...*/],
            'referrers' => [['key' => 'https://aimeos.org/', 'value' => 321], /*...*/],
        ];
    }

    public function types(array $types): Driver
    {
        $this->types = $types;
        return $this;
    }
}

'drivers' => [
    'foobar' => [
        'url' => env('FOOBAR_URL'),
        // more 
bash
php artisan vendor:publish --tag=config
bash
php -r 'echo base64_encode(file_get_contents("name-xxxxxxxxxxxx.json"));'