PHPackages                             aimeos/laravel-analytics-bridge - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. aimeos/laravel-analytics-bridge

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

aimeos/laravel-analytics-bridge
===============================

Unified analytics bridge for Laravel

1.0.2(5mo ago)836022LGPL-2.1+PHPPHP ^8.2

Since Sep 17Pushed 5mo agoCompare

[ Source](https://github.com/aimeos/laravel-analytics-bridge)[ Packagist](https://packagist.org/packages/aimeos/laravel-analytics-bridge)[ RSS](/packages/aimeos-laravel-analytics-bridge/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (4)Used By (2)

Laravel Analytics Bridge
========================

[](#laravel-analytics-bridge)

A unified analytics bridge for Laravel providing a consistent API across multiple analytics providers such as Google Analytics, Matomo, and others.

Features
--------

[](#features)

- Unified API for multiple analytics services
- Drivers for Google Analytics, Matomo, and others
- Returns time series (per day) for page views, visits, visit duration
- Aggregates top countries and referrers
- Integrates PageSpeed Insights (CrUX real-user data) for Web Vitals
- Easily extendable with new drivers

Installation
------------

[](#installation)

Install the driver package you need:

```
# for Matomo
composer require aimeos/laravel-analytics-matomo
# for Google Analytics
composer require aimeos/laravel-analytics-google
# for Cloudflare Web Analytics
composer require aimeos/laravel-analytics-cloudflare
```

Configuration
-------------

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --tag=config
```

This creates the `./config/analytics-bridge.php` file:

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

Set your .env variables accordingly and don't forget to configure the `ANALYTICS_DRIVER` value using the name of the driver ("cloudflare", "google", or "matomo").

The value of `GOOGLE_AUTH` must be the string from the **Service Account JSON key file** encoded as base64. To do the encoding on the command line, use:

```
php -r 'echo base64_encode(file_get_contents("name-xxxxxxxxxxxx.json"));'
```

API Usage
---------

[](#api-usage)

Import the facade:

```
use Aimeos\AnalyticsBridge\Facades\Analytics;
```

### Page Statistics

[](#page-statistics)

Available are:

- views
- visits
- conversions
- durations
- countries
- referrers

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

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

It returns arrays with one entry per day, country or URL:

```
[
    '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],
            ...
        ]],
        ...
    ],
]
```

### PageSpeed Metrics

[](#pagespeed-metrics)

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

Returns:

```
[
    ['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],
    /*...*/
]
```

### Google Search Statistics

[](#google-search-statistics)

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

Returns:

```
[
    '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],
        ...
    ],
```

### Google Search Queries

[](#google-search-queries)

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

Returns:

```
[
    ['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],
    ...
```

### Google Index Status

[](#google-index-status)

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

Returns something like:

- "Indexed"
- "Not found"
- "Crawled"
- "Discovered"

Implemnt new Driver
-------------------

[](#implemnt-new-driver)

For a new analyics service (e.g. Foobar), create a new composer package, e.g. `yourorg/laravel-analytics-foobar`. Replace every occurrence of "yourorg" and "foobar" (in any case) with own vendor name and resp. the service name.

Use this `composer.json` as template:

```
{
  "name": "yourorg/laravel-analytics-foobar",
  "description": "Foobar driver for Laravel Analytics Bridge",
  "type": "library",
  "license": "LGPL-2.1+",
  "autoload": {
    "psr-4": {
      "Aimeos\\AnalyticsBridge\\Drivers\\": "src/"
    }
  },
  "require": {
    "php": "^8.1",
    "aimeos/laravel-analytics-bridge": "~1.0"
  }
}
```

Create a `./src/Foobar.php` file that implements fetching the data from the analytics service. The skeleton class is:

```
