PHPackages                             united-prototype/php-ga - 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. [API Development](/categories/api)
4. /
5. united-prototype/php-ga

ActiveLibrary[API Development](/categories/api)

united-prototype/php-ga
=======================

"ga.js in PHP" - Implementation of a generic server-side Google Analytics client in PHP that implements nearly every parameter and tracking feature of the original GA Javascript client.

191.4k↓50%1PHP

Since Oct 6Pushed 12y ago1 watchersCompare

[ Source](https://github.com/Fran6co/php-ga)[ Packagist](https://packagist.org/packages/united-prototype/php-ga)[ RSS](/packages/united-prototype-php-ga/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Server-Side Google Analytics Client
===================================

[](#server-side-google-analytics-client)

**Oct 5, 2013:** php-ga was ported from [Google Code](https://code.google.com/p/php-ga/)where it has 8,000+ downloads and 160+ stares.

---

**NOTE:** php-ga is no longer maintained as Google finally released an official server-side tracking API: [Measurement Protocol](https://developers.google.com/analytics/devguides/collection/protocol/v1/)! I couldn't find any well-implemented client library for PHP yet, so feel free to help make php-ga 2.0 a Measurement Protocol PHP client library.

---

You might also be interested in the companion project [php-gacx](https://github.com/thomasbachem/php-gacx)for Google Analytics Content Experiments.

About
-----

[](#about)

php-ga basically is ga.js in PHP: An implementation of a generic server-side Google Analytics client in PHP that implements nearly every parameter and tracking feature of the original GA Javascript client. That means you can send data directly from your servers to to Google Analytics – bypassing the user's browser.

I love Google Analytics and want to contribute to its community with this PHP client implementation. It is intended to be used stand-alone or in addition to an existing Javascript library implementation.

It's PHP, but porting it to other languages (see below for a Python port) should be easy. Building this library involved weeks of documentation reading, googling and testing - therefore its source code is thorougly well-documented.

The PHP client has nothing todo with the [Data Export](http://code.google.com/apis/analytics/docs/gdata/gdataDeveloperGuide.html)or [Management](http://code.google.com/apis/analytics/docs/mgmt/home.html) APIs, although you can of course use them in combination.

Requirements
------------

[](#requirements)

Requires PHP 5.3+ as namespaces and closures are used. Has no other dependencies and can be used independantly from any framework or whatsoever environment.

Supported Features
------------------

[](#supported-features)

The current release is based on version 5.2.5 of the official Javascript client library, see `CHANGELOG` file for details.

- Pageview Tracking
- Event Tracking
- Custom Variable Tracking
- Ecommerce Tracking
- Campaign Tracking
- Social Interaction Tracking
- Site Speed Tracking

Gotchas
-------

[](#gotchas)

- **100% namespaced OOP**As a matter of course.
- **Completely abstracted from any enviroment**Doesn't rely on any globals like $\_SERVER, PHP sessions or whatsoever - implement it the way you want.
- **High-Performance Tracking**Can be configured to enqueue requests via register\_shutdown\_function() and to use non-blocking requests.
- **Probably the most comprehensive technical documentation of GA**More than 50% of all source code lines are PHPDoc and inline comments!

Caveats
-------

[](#caveats)

- **Google Analytics' geo location functionalities won't work**Native geo location features like the worldmap view won't work anymore as they rely solely on the IP address of the GA client - which will always be the one of your server(s) when using this library.

Usage Example
-------------

[](#usage-example)

A very basic page view tracking example:

```
use UnitedPrototype\GoogleAnalytics;

// Initilize GA Tracker
$tracker = new GoogleAnalytics\Tracker('UA-12345678-9', 'example.com');

// Assemble Visitor information
// (could also get unserialized from database)
$visitor = new GoogleAnalytics\Visitor();
$visitor->setIpAddress($_SERVER['REMOTE_ADDR']);
$visitor->setUserAgent($_SERVER['HTTP_USER_AGENT']);
$visitor->setScreenResolution('1024x768');

// Assemble Session information
// (could also get unserialized from PHP session)
$session = new GoogleAnalytics\Session();

// Assemble Page information
$page = new GoogleAnalytics\Page('/page.html');
$page->setTitle('My Page');

// Track page view
$tracker->trackPageview($page, $session, $visitor);
```

Links
-----

[](#links)

- [Python port: PYGA](https://github.com/kra3/py-ga-mob)
- [php-ga questions on Stack Overflow](http://stackoverflow.com/search?q=%22php-ga%22)

Thanks to Matt Clarke for two great articles/tutorials:

- [TechPad: Developing a cookie-less Google Analytics implementation](http://techpad.co.uk/content.php?sid=205)
- [TechPad: Turn Google Analytics into an inventory profiling system](http://techpad.co.uk/content.php?sid=209)

Disclaimer
----------

[](#disclaimer)

Google Analytics is a registered trademark of Google Inc.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/726088?v=4)[Francisco Facioni](/maintainers/fran6co)[@fran6co](https://github.com/fran6co)

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

---

Top Contributors

[![thomasbachem](https://avatars.githubusercontent.com/u/231538?v=4)](https://github.com/thomasbachem "thomasbachem (47 commits)")

### Embed Badge

![Health badge](/badges/united-prototype-php-ga/health.svg)

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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