承接 jeffersongoncalves/laravel-gtag 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

jeffersongoncalves/laravel-gtag

Composer 安装命令:

composer require jeffersongoncalves/laravel-gtag

包简介

This Laravel package provides a straightforward integration of Google Analytics using Gtag into your Blade templates. It enables you to easily track website visits and user engagement, offering valuable insights into your site's performance. With minimal setup, you can leverage Gtag's powerful analy

README 文档

README

Laravel Gtag

Laravel Google Analytics

Latest Version on Packagist GitHub Code Style Action Status Total Downloads

This Laravel package provides a straightforward integration of Google Analytics using Gtag into your Blade templates. It enables you to easily track website visits and user engagement, offering valuable insights into your site's performance. With minimal setup, you can leverage Gtag's powerful analytics features to better understand your audience and improve your website's effectiveness.

Settings are stored in the database using spatie/laravel-settings, allowing dynamic management via admin panels or code.

Installation

You can install the package via composer:

composer require jeffersongoncalves/laravel-gtag

Publish and run the settings migrations:

php artisan vendor:publish --provider="Spatie\LaravelSettings\LaravelSettingsServiceProvider" --tag="migrations"
php artisan vendor:publish --tag=gtag-settings-migrations
php artisan migrate

Usage

Add the script tag to your Blade layout (typically in the <head>):

@include('gtag::script')

Configuration via Code

You can update settings at any time using the GtagSettings class, the gtag_settings() helper, or the Gtag facade:

use JeffersonGoncalves\Gtag\Settings\GtagSettings;

// Via container
$settings = app(GtagSettings::class);
$settings->gtag_id = 'G-XXXXXXXXXX';
$settings->enabled = true;
$settings->save();

// Via helper
gtag_settings()->gtag_id = 'G-XXXXXXXXXX';
gtag_settings()->save();

// Via Facade
use JeffersonGoncalves\Gtag\Facades\Gtag;

$gtag = Gtag::getFacadeRoot();
$gtag->gtag_id = 'G-XXXXXXXXXX';
$gtag->save();

Available Properties

Property Type Default Description
gtag_id ?string null Google Tag ID (e.g., G-XXXXXXXXXX)
enabled bool true Enable/disable script rendering
anonymize_ip bool false Anonymize visitor IPs (GDPR compliance)
additional_config array [] Extra parameters for gtag('config', ...)

Additional Config Example

$settings = gtag_settings();
$settings->additional_config = [
    'send_page_view' => false,
    'cookie_domain' => 'example.com',
];
$settings->save();

Upgrading from v1

Version 2 replaces the config/gtag.php configuration file with database settings via spatie/laravel-settings. This is a breaking change.

  1. Remove the old config file: config/gtag.php
  2. Remove the GTAG_ID environment variable (no longer used)
  3. Publish and run the settings migration
  4. Set your Google Tag ID via code (see Usage above)

Testing

composer test

Changelog

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

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固