|
Project Information
Featured
Downloads
Links
|
Server-Side Google Analytics PHP Client
We 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 e.g. Ruby or Python 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 or Management APIs, although you can of course use them in combination. RequirementsRequires 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 FeaturesThe current release is based on version 5.2.5 of the official Javascript client library, see Changelog for details.
Roadmap
Gotchas
Caveats
Usage ExampleA 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);ArticlesThanks to Matt Clarke for two great articles:
DisclaimerGoogle Analytics is a registered trademark of Google Inc.
Made with love by United Prototype in Cologne, Germany. |