tda/laravel-analytics-v4 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

tda/laravel-analytics-v4

最新稳定版本:v1.0.0

Composer 安装命令:

composer require tda/laravel-analytics-v4

包简介

GA4 integration for laravel 8

README 文档

README

This package offers integration to GA4 properties with some out of the box methods. Inspired by Spatie integration for GA3 and originally forked from MyOutDeskLLC. Requires Laravel 8+.

Installation

You can install the package via composer:

composer require tda/laravel-analytics-v4

You can publish the config file with:

php artisan vendor:publish --tag="analytics-v4-config"

This is the contents of the published config file:

return [
    'property_id' => env('ANALYTICS_PROPERTY_ID', 'XXXXXXXXX'),
    'service_account_credentials_json' => storage_path('app/analytics/service-account-credentials.json'),
    // This data is passed into the built-in cache mechanism for google's CredentialWrapper
    'cache' => [
        'enableCaching' => env('ANALYTICS_CACHE',false),
        'authCache' => null,
        'authCacheOptions' => [
            'lifetime' => env('ANALYTICS_CACHE_LIFETIME', 60), // you may want to set this higher
            'prefix' => env('ANALYTICS_CACHE_PREFIX', 'analytics_'),
        ]
    ]
];

Usage

Inside Laravel:

use Tda\LaravelAnalyticsV4\Period;
use Tda\LaravelAnalyticsV4\PrebuiltRunConfigurations;

$client = App::make('laravel-analytics-v4');
$lastMonth = Period::months(1);
$results = $client->runReport(PrebuiltRunConfigurations::getMostVisitedPages($lastMonth));

You may configure your own report configuration, or use a pre-built report:

// Use this on the laravel side to get it from the container
$analytics = App::make('laravel-analytics-v4');

// Prepare a filter
$filter = new StringFilter();
$filter->setDimension('country')->exactlyMatches('United States');

// Prepare a report
$reportConfig = (new RunReportConfiguration())
                ->setStartDate('2022-09-01')
                ->setEndDate('2022-09-30')
                ->addDimensions(['country', 'landingPage', 'date'])
                ->addMetric('sessions')
                ->addFilter($filter);

$analytics->convertResponseToArray()->runReport($reportConfig);

Yay, results:

  [
    "dimensions" => [
      "country" => "United States",
      "landingPage" => "/",
      "date" => "20220903",
    ],
    "metrics" => [
      "sessions" => "113",
    ],
  ],
  [
    "dimensions" => [
      "country" => "United States",
      "landingPage" => "/services/",
      "date" => "20220902",
    ],
    "metrics" => [
      "sessions" => "110",
    ],
  ],

Or Using Prebuilt Report Configurations:

$lastMonth = Period::months(1);
$analytics->runReport(PrebuiltRunConfigurations::getMostVisitedPages($lastMonth));

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Submit a PR with passing tests.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固