PHPackages                             kitbrennan90/php-ga-measurement-protocol - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. kitbrennan90/php-ga-measurement-protocol

ActiveLibrary

kitbrennan90/php-ga-measurement-protocol
========================================

PHP package for interacting with Google Analytics measurement protocol (eg. send page views and events to Google Analytics using your server side).

v1.0.3(7y ago)02.4kMITPHPPHP &gt;=7.1

Since Mar 11Pushed 7y ago1 watchersCompare

[ Source](https://github.com/kitbrennan90/php-ga-measurement-protocol)[ Packagist](https://packagist.org/packages/kitbrennan90/php-ga-measurement-protocol)[ RSS](/packages/kitbrennan90-php-ga-measurement-protocol/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (3)Versions (5)Used By (0)

GA Measurement Protocol PHP Library
===================================

[](#ga-measurement-protocol-php-library)

This simple library lets you send server side track events to Google Analytics.

Installation
------------

[](#installation)

This library is best installed via composer. Via the command line: `composer require kitbrennan90/php-ga-measurement-protocol`

If you are using PSR-4 (or a modern framework), simply import the client at the top of your script:

```
use GaMeasurementProtocol\Client;
```

If you are not using PSR-4, you should require the composer autoloader: `require_once('vendor/autoload.php');`

Using the library
-----------------

[](#using-the-library)

### Initialise the Client

[](#initialise-the-client)

```
$trackingId = 'GA-123456-1'; // Take the tracking/property ID from your Google Analytics account
$client = new Client($trackingId);
```

### Sending a pageview

[](#sending-a-pageview)

The library defaults to firing pageviews.

```
$trackingId = 'GA-123456-1'; // Take the tracking/property ID from your Google Analytics account
$client = new Client($trackingId);

$params = [
    'dl' => 'http://foo.com/home?a=b' // Document location, required for a 'pageview' type
];

$client->request()
   ->setParameters($params)
   ->send();
```

**Not working?** The Measurement Protocol will not raise any errors by default, please explore the debug section below if your results are not showing in Google Analytics the issue.

### Sending other hit types (eg. event, screenview)

[](#sending-other-hit-types-eg-event-screenview)

The library supports every tracking type (available as constants):

- GaMeasurementProtocol\\Enums\\HitType::PAGEVIEW
- GaMeasurementProtocol\\Enums\\HitType::SCREENVIEW
- GaMeasurementProtocol\\Enums\\HitType::EVENT
- GaMeasurementProtocol\\Enums\\HitType::TRANSACTION
- GaMeasurementProtocol\\Enums\\HitType::ITEM
- GaMeasurementProtocol\\Enums\\HitType::SOCIAL
- GaMeasurementProtocol\\Enums\\HitType::EXCEPTION
- GaMeasurementProtocol\\Enums\\HitType::TIMING

Just call `setHitType($type)` on the request:

```
$trackingId = 'GA-123456-1'; // Take the tracking/property ID from your Google Analytics account
$client = new Client($trackingId);

$params = [
    'dl' => 'http://foo.com/home?a=b' // Document location, required for a 'pageview' type
];

$client->request()
   ->setParameters($params)
   ->setHitType(GaMeasurementProtocol\Enums\HitType::EVENT)
   ->send();
```

### Sending additional parameters

[](#sending-additional-parameters)

The full supported parameter list can be found here:

Add all your optional parameters to an array, and call `setParameters($params)` on the request object:

```
$trackingId = 'GA-123456-1'; // Take the tracking/property ID from your Google Analytics account
$client = new Client($trackingId);

$params = [
    'dl' => 'http://foo.com/home?a=b', // Document location, required for a 'pageview' type
    'ul' => 'en-us' // User language
];

$client->request()
   ->setParameters($params)
   ->send();
```

### Debugging

[](#debugging)

The Measurement Protocol always returns 200, even if parameters are invalid. You instead need to enable debug mode, which will var\_dump the debug results to your view.

**Note** If debug mode is turned on, the results will NOT appear in your Google Analytics.

Once debug mode says your hit is valid, you should turn debug mode off and send your request again.

```
$trackingId = 'GA-123456-1'; // Take the tracking/property ID from your Google Analytics account
$client = new Client($trackingId);

$params = [
    'dl' => 'http://foo.com/home?a=b' // Document location, required for a 'pageview' type
];

$client->setDebug(true)
   ->request()
   ->setParameters($params)
   ->send();
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

4

Last Release

2615d ago

PHP version history (3 changes)v1.0.0PHP &gt;=7.2.0

v1.0.1PHP &gt;=7.1.0

v1.0.2PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/b20b074813a9caaa48ad142152597051abe161caffc4d1182f967a35eb6409e4?d=identicon)[kitbrennan](/maintainers/kitbrennan)

---

Top Contributors

[![kitbrennan90](https://avatars.githubusercontent.com/u/1593605?v=4)](https://github.com/kitbrennan90 "kitbrennan90 (7 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/kitbrennan90-php-ga-measurement-protocol/health.svg)

```
[![Health](https://phpackages.com/badges/kitbrennan90-php-ga-measurement-protocol/health.svg)](https://phpackages.com/packages/kitbrennan90-php-ga-measurement-protocol)
```

###  Alternatives

[neuron-core/neuron-ai

The PHP Agentic Framework.

1.8k245.3k21](/packages/neuron-core-neuron-ai)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
