2017 © Pedro Peláez

li3-libraries li3_analytics

Analytic Plugin for Lithium PHP



Analytic Plugin for Lithium PHP

  • Tuesday, September 18, 2012
  • by joseym
  • Repository
  • 1 Watchers
  • 2 Stars
  • 146 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown


Analytic Plugin for Lithium PHP

A plugin to assist with the assignment of Analytical services, AB tests and click tracking., (*1)

Currently supports Google Analytics, Optimizely, Webtrends Analytics 9 & 10, Chartbeat, and comScore Direct, (*2)

Build Status, (*3)


__Composer__ (best option), (*4)

Modify your projects composer.json file, (*5)

~~~ json { "require": { ... "joseym/li3_analytics": "dev-master" ... } }, (*6)

Run `php composer.phar install` (or `php composer.phar update`) and, aside from adding it to your Libraries, you should be good to go. *** __Submodule__ (If you feel like it) From the root of your app run `git submodule add git://github.com/joseym/li3_analytics.git libraries/li3_analytics` *** __Clone Directly__ (meh) From your apps `libraries` directory run `git clone git://github.com/joseym/li3_analytics.git` ## Usage ### Load the plugin Add the plugin to be loaded with Lithium's autoload magic In `app/config/bootstrap/libraries.php` add: ~~~ php <?php Libraries::add('li3_analytics'); ?>

Add your Trackers

There is a tracker template file in li3_analytics/config/trackers.php.template, (*7)

Like connections you'll need to add the trackers into the bootstrap process, the easiest way to do this is to copy trackers.php.template to your apps config/bootstrap directory as, say, config/bootstrap/trackers.php., (*8)

Add this file into your config/boostrap.php file, (*9)

~~~ php , (*10)

Modify the trackers to meet your needs: __Here's an example for each tracker__ ~~~ php 'GoogleAnalytics', // The Adapter 'account' => 'UA-999999-1', // your GA account // 'section' => 'append_head', // What helper section to load tracking in your template `append_head | prepend_head | append_body | prepend_body` // 'domain' => 'dev.com', // set if you are using with multiple sub domains, ignore otherwise // 'manyTopLevel' => true, // set if you are using GA with multiple top level domains )); Trackers::add('Optimizely', array( 'adapter' => 'Optimizely', // The Adapter 'project' => 'xxx123' // the optimizely project id // 'views' => array('prepend_body' => 'optimizely'), // What helper section to load tracking in your template `append_head | prepend_head | append_body | prepend_body` )); Trackers::add('Webtrends', array( 'adapter' => 'Webtrends', // The Adapter 'DCSID' => 'dcsXXXXXXXXXXXX_XXXX', // Webtrends ID 'domain' => $_SERVER['SERVER_NAME'], // Domain // 'version' => '9.4.0', // Analytics 9 by default // 'script' => '/js/webtrends.js', // location of webtrends script (relative to webroot) // 'section' => 'append_body' // Section to build script block into )); Trackers::add('Chartbeat', array( 'adapter' => 'Chartbeat', // The Adapter 'uid' => 3479, // Your account user ID 'domain' => $_SERVER['SERVER_NAME'], // website domain /** * Chartbeat Configuration Variables * Links to info provided */ // 'config' => array( // 'path' => '/some/path', // @link: http://chartbeat.com/docs/configuration_variables#path // 'title' => 'Krusty is back', // @link: http://chartbeat.com/docs/configuration_variables#title // 'useCanonical' => true, // @link: http://chartbeat.com/docs/configuration_variables#useCanonical // 'sections' => "US Politics", // @link: http://chartbeat.com/docs/configuration_variables#groups // 'authors' => "Bob Johnson", // @link: http://chartbeat.com/docs/configuration_variables#groups // 'noCookies' => true // @link: http://chartbeat.com/docs/configuration_variables#nocookies // ) )); Trackers::add('comScore', array( 'adapter' => 'ComScore', // The Adapter 'account' => '123456789' // comScore Account ID )); ?>

Webtrends - You will still need to build your webtrends.js file from webtrends.com, this plugin just places the scripts with this configuration. Note - I am working on a way to include automated click tracking with webtrends., (*11)

Set in your template

The plugin comes with a helper (go figure!) that should be used to load your trackers, (*12)

Currently both the supported trackers are to be loaded in the head of your template, Optimizely should be loaded at the beginning of the <head/> block, Google Analytics at the end., (*13)

~~~ php , (*14)

analytics->head('prepend'); ?> Magic Tracking #ftw analytics->head('append'); ?> analytics->body('prepend'); ?> ... analytics->body('append'); ?>

The trackers will automatically be loaded into the proper sections, however you can override the trackers sections by changing the `section` key in the `Trackers::add()` adapter. #### Load a single tracker Remember that name you gave your tracker in `Trackers::add()`, well you can manually call that tracker and put it whereever you'd like! __You're welcome!__ Here's how: ~~~ php analytics->google('position'); ?>

Replace 'position' with any of the four view types listed below or none for the first view., (*15)

  • append_body
  • prepend_body
  • append_head
  • prepend_head

Wait, what? That's it?!, (*16)

Yes., (*17)

While you can name the tracker whatever you'd like you should be aware that the name is slugified and converted to lowercase before it actually gets added. This means that if you name a tracker "Google Analytics Mang" it will be converted to google-analytics-mang; this is the name you'd need to call with the helper., (*18)

Body helpers

A helper for $this->analytics->body('prepend') and $this->analytics->body('append') will be added as tracker adapters that need that support are included., (*19)


That's it! the proper code for your tracker should now be rendered into your template, no more hassle., (*20)


Future Trackers

Here is a list of trackers I would like to add support for., (*21)


Have an idea for a tracker? Wanna take point on one of the trackers listed above? Please do!, (*22)

Fork and submit a pull request, lets make this awesome., (*23)


Original plugin written by Yoan Blanc - He laid the foundation, give him props., (*24)

Vitals.com - (my previous employer) - Thanks for supporting the OSS community and allowing your engineers to give back to the projects we depend on., (*25)

The Versions

18/09 2012


9999999-dev https://github.com/joseym/li3_analytics/blob/master/README.md

Analytic Plugin for Lithium PHP

  Sources   Download

MIT License

The Requires


analytics js google analytics lithium li3 chartbeat optimizely webtrends comscore