定制 aimeos/laravel-analytics-bridge 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

aimeos/laravel-analytics-bridge

Composer 安装命令:

composer require aimeos/laravel-analytics-bridge

包简介

Unified analytics bridge for Laravel

README 文档

README

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

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

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

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

Import the facade:

use Aimeos\AnalyticsBridge\Facades\Analytics;

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

$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

$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

$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

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

Returns something like:

  • "Indexed"
  • "Not found"
  • "Crawled"
  • "Discovered"

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:

<?php

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;
    }
}

Install your package using composer:

composer require yourorg/laravel-analytics-foobar

Register your driver in config/analytics-bridge.php, e.g.:

'drivers' => [
    'foobar' => [
        'url' => env('FOOBAR_URL'),
        // more required settings
    ]
],

Optimize

The google/apiclient package contains classes for all Google APIs (currently over 300) but only two (SearchConsole and WebIndex) are required. To install only the required ones, insert this into your composer.json at the correct places:

    "scripts": {
        "pre-autoload-dump": [
            "Google\\Task\\Composer::cleanup"
        ],
    },
    "extra": {
        "google/apiclient-services": [
            "SearchConsole"
        ]
    },

When you run composer update afterwards, this will remove the unused services. Take a look into the Google client README for details.

License

This package is released under the LGPL-2.1+ License.

aimeos/laravel-analytics-bridge 适用场景与选型建议

aimeos/laravel-analytics-bridge 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.11k 次下载、GitHub Stars 达 165, 最近一次更新时间为 2025 年 09 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 aimeos/laravel-analytics-bridge 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 aimeos/laravel-analytics-bridge 我们能提供哪些服务?
定制开发 / 二次开发

基于 aimeos/laravel-analytics-bridge 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.11k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 165
  • 点击次数: 11
  • 依赖项目数: 5
  • 推荐数: 0

GitHub 信息

  • Stars: 165
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-2.1
  • 更新时间: 2025-09-03