2017 © Pedro Peláez
 

library googleanalyticsserversidebundle

Symfony 2 bundle, push your google analytics hits from the server

image

kairos/googleanalyticsserversidebundle

Symfony 2 bundle, push your google analytics hits from the server

  • Monday, July 6, 2015
  • by kairosagency
  • Repository
  • 3 Watchers
  • 2 Stars
  • 6,570 Installations
  • HTML
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 12 Versions
  • 5 % Grown

The README.md

Getting Started With Server-Side Google Analytics PHP Client

Scrutinizer Code Quality Build Status, (*1)

Important

Your bundle might not work any more after major changes to the master branch. To solve that problem, please update your composer.json and set your bundle version to ~1.0.0 :, (*2)

``` js { "require": { "kairos/googleanalyticsserversidebundle": "~1.0.0" } }, (*3)


This bundle has been updated to support universal analytics which is a far better solution than the php-ga library. ## Summary : Google Analytics Server Side Bundle is aimed at sending google analytics hits from a server. This can be very usefull for an app, or in case google analytics is blocked. This bundle made originally use of the great project from UnitedPrototype : http://code.google.com/p/php-ga/ But now use the new google universal analytics which is more efficient and robust. ## Requirements Requires PHP 5.3 as namespaces and closures are used, Symfony 2 framework ## Installation : **In your composer file file :** ``` js { "require": { "kairos/googleanalyticsserversidebundle": "~2.0.0" } }

Update your composer :, (*4)

``` bash php composer.phar update kairos/googleanalyticsserversidebundle, (*5)


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 Kairos\GoogleAnalyticsServerSideBundle\KairosGoogleAnalyticsServerSideBundle(), ); }

In your config.yml, (*6)

``` yaml kairos_google_analytics_server_side: account_id: UA-XXXXXXXX-XX domain: your.domain async: true|false // use register shutdown function to send "async" hits to google analytics ssl: true|false localhost: true|false // set to true if you want js code to push analytics on localhost timeout: 10 // value in seconds if you don't want your php script to block in case ga dos not respond connect_timeout: 2 // same thing as above, (*7)


**To enable js tracking** ``` yaml twig: globals: gajs: "@ga_js_tracker"

How To use :

Universal analytics :

Super mega cool tip ! You can use both serverside and client side ! The session will be synched between your serverside and client side code so no doubles, (*8)

Serverside usage :

You can use directly the documentation given by google at the address : https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters, (*9)

``` php, (*10)

// Call tracker from container
$this->container->get('ga_mp_tracker')->track('pageview',
    array(
        'dp' => 'your.address.com',
        'dt' => 'your title'
    )
);

// Track event
$this->container->get('ga_mp_tracker')->track('event',
    array(
        'dp' => 'your.address.com',
        'dt' => 'your title',
        'ec' => 'event category',
        'ea' => 'event action',
        'el' => 'event label',
    )
);

#### Client side usage : To use ga.js on client side, you have to register the ga_js_tracker service in your twig config, then you'll be able to call it this way :
{{ gajs.getGAjs()|raw }}

You can override trackingId and Domain by calling the function with these parameters :
{{ gajs.getGAjs('trackingID','domain')|raw }}

Don't forget the raw if you don't want the tag to be escaped bu twig. Your ga.js session will be automatically synched with your server side session (client id is shared in the cookies). #### With an old google analytics account : **Warning** This is deprecated and not supported any more ``` php // Initilize GA Tracker $tracker = $this->get('google_analytics'); // 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);

Thanks

This package is directly based on this project from UnitedPrototype : http://code.google.com/p/php-ga/, (*11)

The Versions

06/07 2015

dev-master

9999999-dev https://github.com/kairosagency/GoogleAnalyticsServerSideBundle.git

Symfony 2 bundle, push your google analytics hits from the server

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

google-analytics measurement protocol php-ga server-side-analytics

06/07 2015

2.0.6

2.0.6.0 https://github.com/kairosagency/GoogleAnalyticsServerSideBundle.git

Symfony 2 bundle, push your google analytics hits from the server

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

google-analytics measurement protocol php-ga server-side-analytics

13/10 2014

2.0.5

2.0.5.0 https://github.com/kairosagency/GoogleAnalyticsServerSideBundle.git

Symfony 2 bundle, push your google analytics hits from the server

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

google-analytics measurement protocol php-ga server-side-analytics

13/10 2014

dev-develop

dev-develop https://github.com/kairosagency/GoogleAnalyticsServerSideBundle.git

Google analytics vendor for symfony2

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

google-analytics measurement protocol php-ga server-side-analytics

13/08 2014

dev-1.0.x-dev

dev-1.0.x-dev https://github.com/kairosagency/GoogleAnalyticsServerSideBundle.git

Google analytics vendor for symfony2

  Sources   Download

LGPL-3.0

The Requires

 

google-analytics php-ga server-side-analytics

13/08 2014

1.0.3

1.0.3.0 https://github.com/kairosagency/GoogleAnalyticsServerSideBundle.git

Google analytics vendor for symfony2

  Sources   Download

LGPL-3.0

The Requires

 

google-analytics php-ga server-side-analytics

13/08 2014

2.0.4

2.0.4.0 https://github.com/kairosagency/GoogleAnalyticsServerSideBundle.git

Symfony 2 bundle, push your google analytics hits from the server

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

google-analytics measurement protocol php-ga server-side-analytics

12/08 2014

2.0.3

2.0.3.0 https://github.com/kairosagency/GoogleAnalyticsServerSideBundle.git

Google analytics vendor for symfony2

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

google-analytics measurement protocol php-ga server-side-analytics

08/08 2014

2.0.2

2.0.2.0 https://github.com/kairosagency/GoogleAnalyticsServerSideBundle.git

Google analytics vendor for symfony2

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

google-analytics measurement protocol php-ga server-side-analytics

08/08 2014

2.0.1

2.0.1.0 https://github.com/kairosagency/GoogleAnalyticsServerSideBundle.git

Google analytics vendor for symfony2

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

google-analytics measurement protocol php-ga server-side-analytics

08/08 2014

2.0.0

2.0.0.0 https://github.com/kairosagency/GoogleAnalyticsServerSideBundle.git

Google analytics vendor for symfony2

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

google-analytics measurement protocol php-ga server-side-analytics

17/07 2013

1.0.0

1.0.0.0 https://github.com/kairosagency/GoogleAnalyticsServerSideBundle.git

Google analytics vendor for symfony2

  Sources   Download

LGPL-3.0

The Requires

 

google-analytics php-ga server-side-analytics