定制 ronald2wing/laravel-ga4 二次开发

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

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

ronald2wing/laravel-ga4

最新稳定版本:1.0.0

Composer 安装命令:

composer require ronald2wing/laravel-ga4

包简介

Drop-in Google Analytics 4 (gtag) snippet for Laravel Blade.

README 文档

README

Latest Version License PHPStan CI

A small Laravel package that drops the Google Analytics 4 tracking snippet into your Blade layout. One directive, one env var, no ceremony.

Requirements

  • PHP 8.3+
  • Laravel 10.x, 11.x, 12.x, or 13.x

Installation

composer require ronald2wing/laravel-ga4

The service provider is auto-registered.

Configuration

Add your measurement ID to .env:

GA4_MEASUREMENT_ID=G-XXXXXXXXXX

Optionally publish the config:

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

gtag parameters

Forwarded as the third argument to gtag('config', id, parameters):

// config/ga4.php
'parameters' => [
    'send_page_view' => true,
    'anonymize_ip'   => true,
],

Usage

Place @ga4 in your layout's <head>:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>{{ config('app.name') }}</title>
    @ga4
</head>
<body>
    @yield('content')
</body>
</html>

The directive renders the tracking snippet, or nothing at all if no measurement ID is configured — so it's safe to drop into any layout unconditionally.

Conditional rendering

Ga4Tag::isEnabled() lets you guard analytics-aware UI:

@use(Ronald2Wing\LaravelGa4\Ga4Tag)

@if(app(Ga4Tag::class)->isEnabled())
    <button data-track="sign_up">Sign Up</button>
@endif

Ga4Tag implements Htmlable and Stringable, so {{ $tag }} and {!! $tag !!} both work if you'd rather inject the instance directly.

Composer scripts

composer test          # run tests
composer check         # lint + test
composer lint          # Pint dry-run
composer pint          # Pint fix
composer analyse       # PHPStan

License

MIT © Ronald2Wing

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固