- How do I install and configure theiconic/php-ga-measurement-protocol in Laravel?
- Install it with Composer using composer require theiconic/php-ga-measurement-protocol, then bind a configured tracker instance in a service provider or config file. Store the tracking ID in config/services.php or .env and inject the tracker behind an AnalyticsClient interface so application code does not depend on the package directly. Keep configuration cached and avoid instantiating the tracker per request unnecessarily.
- Does this package support GA4 Measurement Protocol?
- No, not directly. It implements Universal Analytics measurement-protocol hits, and Universal Analytics properties stopped processing standard hits in 2023, so it is not a GA4 client. For GA4 you need a separate adapter using measurement_id and api_secret plus GA4 payload shapes, then retire this package or fork it.
- Can I send server-side pageviews and events from Laravel without client-side JavaScript?
- Yes, the package builds pageview and event payloads and sends them over HTTP from PHP, so backend events such as signup, checkout, or webhook-triggered conversions can be recorded without gtag.js. Dispatch from a queued job or service so analytics calls do not slow user requests. Validate the payload and consent requirements before sending.
- How do I send ecommerce transactions with this package?
- Build an ecommerce hit using the package's transaction and item payload builders, including transaction ID, affiliation, revenue, and item arrays. Send it from a queued job after your order is committed so retries do not duplicate records. Add deduplication at the application layer because the measurement protocol does not guarantee idempotency.
- What is the batch hit feature in v2.9.0 and how should I use it?
- v2.9.0 added batch hit support, which lets you accumulate multiple hits and dispatch them together instead of making one HTTP call per hit. It fits high-volume fan-out such as nightly backfills or bulk conversion syncs, but it is a newer code path, so review payload limits, partial-failure semantics, and rate limits. Encapsulate batching in a BatchedAnalyticsClient decorator rather than building batches ad hoc at call sites.
- Is this package maintained, and which Laravel versions does it support?
- The project had a long gap between releases, but v2.9.0 with named external contributors suggests it is not fully abandoned; activity is still low. Verify PHP version constraints, dependency requirements, and Laravel container compatibility before adopting, and pin the package version rather than floating ^2.x. Add contract tests around single and batch payloads because batching may have introduced new dependencies or raised minimum versions.
- How do I queue Google Analytics hits in Laravel to avoid blocking requests?
- Create a job that builds and sends the hit, dispatch it after the business transaction commits, and configure retries and backoff. Use a dedicated queue for analytics so a Google endpoint outage does not block critical work. Keep the tracker behind an interface and pass only scalar IDs into the job, resolving configuration inside the job.
- How can I test Measurement Protocol hits without sending real data?
- Inject a fake HTTP client or swap the package's transport with a test double, then assert the generated payload shape and endpoint parameters. Add contract tests for single and batch hits, including error and partial-failure paths. Avoid pointing tests at a production Universal Analytics property, and use a local stub endpoint if you need end-to-end HTTP behavior.
- What are the alternatives to this package for server-side Google Analytics in Laravel?
- For GA4, implement a small adapter around the GA4 Measurement Protocol using measurement_id and api_secret, or use a maintained GA4-specific client library. Spatie's laravel-analytics is for reading reports, not for sending server-side hits, so it solves a different problem. The safest long-term approach is a replaceable AnalyticsClient interface with package-backed and GA4-backed implementations.
- Does the package support custom dimensions, client IDs, and consent handling?
- It supports measurement-protocol parameters including custom dimensions and metrics, and you can set a client ID so hits stitch to a user session. Consent and PII handling are not automatic; you must gate hit construction and sending on your consent rules and avoid sending personal data. For batching, apply consent checks per hit before adding it to a batch.