forked from kairosagency/GoogleAnalyticsServerSideBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 15529f7
Showing
8 changed files
with
351 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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% ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |