quadcompanies/google-analytics
最新稳定版本:v1.1.0
Composer 安装命令:
composer require quadcompanies/google-analytics
包简介
A simple Laravel package to integrate Google Analytics gtag.js
README 文档
README
A simple and easy-to-use Laravel package for integrating Google Analytics (gtag.js) into your application.
Installation
You can install the package via composer:
composer require quadcompanies/google-analytics
php artisan vendor:publish --provider="QuadCompanies\GoogleAnalytics\GoogleAnalyticsServiceProvider" --tag="config"
This is the contents of the published config file:
return [ /* * The Google Analytics Measurement ID (usually starts with 'G-') */ 'measurement_id' => env('GOOGLE_ANALYTICS_MEASUREMENT_ID'), /* * Whether or not to enable Google Analytics. */ 'enabled' => env('GOOGLE_ANALYTICS_ENABLED', true), /* * Additional Tag IDs that should be loaded. */ 'tag_ids' => [], ];
Usage
Environment Setup
Add your Google Analytics Measurement ID to your .env file:
GOOGLE_ANALYTICS_MEASUREMENT_ID=G-XXXXXXXXXX
Blade Directive
To add the Google Analytics script to every page, add the @googleAnalytics directive to the <head> section of your main layout file (e.g., resources/views/layouts/app.blade.php):
<!DOCTYPE html> <html> <head> @googleAnalytics() ... </head> ... </html>
Dynamic Parameters
You can also pass a custom measurement ID and additional tag IDs directly through the directive:
@googleAnalytics('G-CUSTOM-ID', ['G-TAG-1', 'G-TAG-2'])
Testing
Coming soon...
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 137
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-28