Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
t0k4rt committed Jun 5, 2013
0 parents commit 15529f7
Show file tree
Hide file tree
Showing 8 changed files with 351 additions and 0 deletions.
29 changes: 29 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace GoogleAnalytics\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This is the class that validates and merges configuration from your app/config files
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('google_analytics');

// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
// more information on that topic.

return $treeBuilder;
}
}
28 changes: 28 additions & 0 deletions DependencyInjection/GoogleAnalyticsExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace GoogleAnalytics\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
* This is the class that loads and manages your bundle configuration
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class GoogleAnalyticsExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
}
9 changes: 9 additions & 0 deletions GoogleAnalyticsBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace GoogleAnalytics;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class GoogleAnalyticsBundle extends Bundle
{
}
100 changes: 100 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
Getting Started With Server-Side Google Analytics PHP Client
==================================

## Important
This package is directly based on this project from UnitedPrototype : http://code.google.com/p/php-ga/

This package is aimed at using php-ga in symfony 2 as a vendor and a service.


## Summary :
"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.

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.

## 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.

## Installation :

**In your composer file file :**

``` js
{
"require": {
"kairos/googleanalytics": "dev-master"
}
}
```

**Update your composer :**

``` bash
php composer.phar update kairos/googleanalytics
```

Composer will install the bundle to your project's vendor/kairos directory.

**Enable the bundle in the AppKernel file :**

``` php
<?php
// app/AppKernel.php

public function registerBundles()
{
$bundles = array(
// ...
new GoogleAnalytics\GoogleAnalyticsBundle(),
);
}
```

**In your parameters.yml**

``` yaml
parameters:
php_ga_accountID: UA-12345678-9
php_ga_domain: yourwebsite.com
```
## How To use :
**In your bundle :**
You now can include the class in your controller
``` php
use GoogleAnalytics;
```

And track page (or events etc.) :

``` php
// Initilize GA Tracker
$tracker = $this->get('googleanalytics');

// 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);
```

- [Read more](https://github.com/kairosagency/GoogleAnalyticsBundle/tree/master/Resources/doc/index.md)
- [Using Cookies](https://github.com/kairosagency/GoogleAnalyticsBundle/tree/master/Resources/doc/using_cookies.md)
7 changes: 7 additions & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:
google_analytics.class: Kairos\GoogleAnalytics\Tracker

services:
google_analytics:
class: %google_analytics.class%
arguments: [ %php_ga_accountID% , %php_ga_domain% ]
99 changes: 99 additions & 0 deletions Resources/doc/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
Getting Started With Server-Side Google Analytics PHP Client
==================================

## Important
This package is directly based on this project from UnitedPrototype : http://code.google.com/p/php-ga/

This package is aimed at using php-ga in symfony 2 as a vendor and a service.


## Summary :
"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.

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.

## 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.

## Installation :

**In your composer file file :**

``` js
{
"require": {
"kairos/googleanalytics": "dev-master"
}
}
```

**Update your composer :**

``` bash
php composer.phar update kairos/googleanalytics
```

Composer will install the bundle to your project's vendor/kairos directory.

**Enable the bundle in the AppKernel file :**

``` php
<?php
// app/AppKernel.php

public function registerBundles()
{
$bundles = array(
// ...
new GoogleAnalytics\GoogleAnalyticsBundle(),
);
}
```

**In your parameters.yml**

``` yaml
parameters:
php_ga_accountID: UA-12345678-9
php_ga_domain: yourwebsite.com
```
## How To use :
**In your bundle :**
You now can include the class in your controller
``` php
use GoogleAnalytics;
```

And track page (or events etc.) :

``` php
// Initilize GA Tracker
$tracker = $this->get('googleanalytics');

// 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);
```

- [Using Cookies](https://github.com/kairosagency/GoogleAnalyticsBundle/tree/master/Resources/doc/using_cookies.md)
51 changes: 51 additions & 0 deletions Resources/doc/using_cookies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Using cookies
==================================

**In your bundle :**

You now can include the class in your controller

``` php
use GoogleAnalytics;
```

And track page (or events etc.) :

``` php
// Init config
$config = new GoogleAnalytics\Lib\Config();

// Force ip anonymize, mandatory to get ip geolocation
$config->setAnonymizeIpAddresses(true);

// Initilize GA Tracker and set the config
$tracker = $this->get('googleanalytics');
$tracker->setConfig($config);

// Assemble Visitor information
$visitor = new GoogleAnalytics\Lib\Visitor();
// Get __utma info from cookie
$visitor->fromUtma($this->getRequest()->cookies->get('__utma'));

$visitor->fromServerVar($_SERVER);
$visitor->setScreenResolution('1024x768');

// Assemble Session information (could also get unserialized from PHP session)
$session = new GoogleAnalytics\Lib\Session();
// Get __utmb info from cookie
$session->fromUtmb($this->getRequest()->cookies->get('__utmb'));


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

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

// Set the cookies
$gaResponse = $tracker->setCookies($request);

// Send the response
$gaResponse->send();
```
28 changes: 28 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "kairos/googleanalyticsserversidebundle",
"type": "library",
"description": "Google analytics vendor for symfony2",
"keywords": ["php-ga","google-analytics"],
"homepage": "https://github.com/kairosagency/GoogleAnalyticsServerSideBundle.git",
"license": "",
"authors": [
{
"name": "t0k4rt",
"homepage": "https://github.com/t0k4rt",
"role": "Developer"
},
{
"name": "Matthiew",
"homepage": "https://github.com/Matthiew",
"role": "Developer"
}
],
"require": {
"php": ">=5.3.0",
"symfony/framework-bundle": ">=2.1,<2.3-dev"
},
"autoload": {
"psr-0": { "GoogleAnalyticsServerSide": "" }
},
"target-dir": "GoogleAnalyticsServerSIde"
}

0 comments on commit 15529f7

Please sign in to comment.