Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Ga4 Laravel Package

alexwestergaard/php-ga4

A lightweight PHP client for Google Analytics 4 that sends server-side events through the GA4 Measurement Protocol. Build and dispatch events with a simple, fluent API—great for tracking purchases, signups, and conversions from Laravel or any PHP backend, no client-side JavaScript required.

Deep Wiki
Context7

alexwestergaard/php-ga4 is a lightweight PHP library for sending server-side events to Google Analytics 4 via the Measurement Protocol. It lets you track conversions, purchases, and custom events from your backend—ideal for order confirmations, webhooks, and actions that client-side tracking can't capture.

  • Simple fluent API for building and dispatching events
  • Support for e-commerce items, transactions, and custom parameters
  • Built-in client ID and session handling
  • PSR-compatible and framework-agnostic, easy to drop into Laravel or any PHP app
Frequently asked questions about Php Ga4
What is alexwestergaard/php-ga4 used for?
It is a lightweight PHP client for the Google Analytics 4 Measurement Protocol, letting you send server-side events, ecommerce payloads, and user properties to GA4 from Laravel or any PHP application. The main value is measurement that does not depend on frontend JavaScript, so events still arrive when visitors use ad blockers or when tracking happens in background jobs. Treat it as an event delivery adapter rather than a reporting or analytics platform, since GA4 itself remains the system of record for reporting.
How do I install alexwestergaard/php-ga4 in a Laravel application?
Installation is a standard Composer require, followed by publishing any package configuration if the package ships one and setting your GA4 measurement ID and API secret through environment variables. Keep credentials out of source control and out of client-side code, since the Measurement Protocol secret allows arbitrary event submission. Wrap the client in your own service class or bind it in a service provider so your domain code does not depend on the package directly.
Which PHP and Laravel versions does alexwestergaard/php-ga4 support?
The exact PHP and Laravel version constraints should be confirmed from the package's composer.json before adoption, because that information is not guaranteed by the overview alone. Check that its HTTP client requirements, such as Guzzle or PSR-18 implementations, are compatible with the versions already locked in your application. Run a short Composer spike in a staging branch to catch dependency conflicts early rather than discovering them during a release.
Does alexwestergaard/php-ga4 require a Google Tag Manager server container?
Based on the package description, it appears to call the GA4 Measurement Protocol directly rather than requiring a full server-side GTM container. That distinction matters for infrastructure cost and operational complexity, so verify the actual request endpoint in the source before you plan around it. If you already run a server-side GTM container, confirm whether you should point the client at the container endpoint or at GA4 directly.
How do I send ecommerce or purchase events to GA4 from Laravel with this package?
Send purchase and refund events from a domain event listener or queued job rather than directly inside a controller, so failures never break checkout. Build the GA4 items array from your own order model and keep a vendor-neutral event contract so the payload shape is defined in your codebase, not scattered across controllers. Validate the payload against GA4's expected schema in a sandbox property before enabling it for production traffic.
Does alexwestergaard/php-ga4 support Measurement Protocol validation and debug mode?
GA4 offers a validation endpoint and a debug flag that surface payload errors, but you should confirm whether this package exposes them or whether you must send the raw request yourself. Use validation during development against a sandbox property so malformed events fail loudly instead of being silently dropped. Make sure debug mode is disabled in production, since debug requests do not count as normal hits and can pollute your property.
Can I send GA4 events through Laravel queues instead of synchronously?
Yes, and you generally should. Dispatch a queued job from your application events or listeners and let the queue absorb latency and transient failures instead of calling GA4 on the request path. Add sensible retry and backoff settings and a dead-letter or logging path for permanently failed events. Watch for retry storms and rate limiting during traffic spikes, and make sure your jobs are idempotent so duplicates do not inflate conversions.
How should I handle consent and PII when sending GA4 events server-side?
Server-side tracking does not remove your consent obligations, so gate event delivery on your consent management record before the job runs. Avoid sending email addresses, names, or other personal data in event parameters, and prefer hashed identifiers or internal user IDs where GA4 supports them. Add a redaction layer in your own wrapper so that PII filtering does not depend solely on the package's behavior.
Is alexwestergaard/php-ga4 actively maintained, and what are the alternatives?
It has modest adoption and an Unlicense with no warranty or support commitment, so treat it as a low-ceremony dependency with a real abandonment risk. Confirm the repository is public and auditable and check the release and test cadence before betting production traffic on it. Because the package is small, the fallback can be a minimal internal HTTP client that posts to the Measurement Protocol, or another PHP GA4 SDK, so keep your wrapper thin enough to swap.
How do I test GA4 server-side events in Laravel before production?
Start with a sandbox GA4 property and a non-critical event stream, dual-running alongside any existing client-side or server-side tracking. Mock the HTTP layer in automated tests so payload structure, consent filtering, and retry behavior are asserted without hitting Google. Compare event counts and parameter values in GA4 debug views, then feature-flag production traffic and migrate high-value events only after deduplication and failure handling are proven.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons