![]() |
|
sfGoogleAnalyticsPlugin - 1.1.3Easily add Google Analytics to your symfony project. |
|
![]() |
70
users
Sign-in
to change your status |
Easily add Google Analytics to your symfony project. |
| Name | Status | |
|---|---|---|
|
|
lead | moc.tcejorp-ynofmys <<ta>> htimsllaw.sirk |
Copyright (c) 2007 Kris Wallsmith
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
| Version | License | API | Released |
|---|---|---|---|
| 1.1.5stable | MIT license | 1.1.5stable | 17/10/2008 |
| 1.1.4stable | MIT license | 1.1.4stable | 16/10/2008 |
| Version | License | API | Released |
|---|---|---|---|
| 1.1.5stable | MIT license | 1.1.5stable | 17/10/2008 |
| 1.1.4stable | MIT license | 1.1.4stable | 16/10/2008 |
| 1.1.3stable | MIT license | 1.1.3stable | 06/07/2008 |
| 1.1.2stable | MIT license | 1.1.2stable | 16/06/2008 |
| 1.1.1stable | MIT license | 1.1.1stable | 04/06/2008 |
| 1.1.0stable | MIT license | 1.1.0stable | 26/04/2008 |
| Version | License | API | Released |
|---|---|---|---|
| 1.1.5stable | MIT license | 1.1.5stable | 17/10/2008 |
| 1.1.4stable | MIT license | 1.1.4stable | 16/10/2008 |
| 1.1.3stable | MIT license | 1.1.3stable | 06/07/2008 |
| 1.1.2stable | MIT license | 1.1.2stable | 16/06/2008 |
| 1.1.1stable | MIT license | 1.1.1stable | 04/06/2008 |
| 1.1.0stable | MIT license | 1.1.0stable | 26/04/2008 |
| 1.0.0beta | MIT license | 1.0.0beta | 19/03/2008 |
Easily add Google Analytics tracking code to your presentation layer.
This documentation is a work in progress. Thank you for your patience.
You can install using the plugin-install task:
php symfony plugin-install sfGoogleAnalyticsPlugin
You can also pull the code directly from the Subversion repository using a svn checkout or the svn:externals property on your project's /plugins directory.
Once the plugin code is accessible to your project, you need to add the sfGoogleAnalyticsFilter to your filter chain:
rendering: ~ security: ~ # insert your own filters here sf_google_analytics_plugin: class: sfGoogleAnalyticsFilter cache: ~ common: ~ execution: ~
NOTE: This is the symfony 1.1 filters.yml file. The equivalent symfony 1.0 file looks slightly different.
Basic configuration is done in your application's app.yml file:
all:
sf_google_analytics_plugin:
enabled: on
profile_id: XX-XXXXX-X
tracker: google
You'll have to copy the profile_id value out of the tracking code Google supplies for your site profile. This value typically starts with the letter U and ends with a single digit.
This plugin defaults to using the older urchin tracker. To take advantage of the latest featureset of Google Analytics, change the tracker value to google. This will insert the new ga.js tracking code into your project.
This plugin provides much more functionality than a simple insert of your tracking code. Here are some highlights:
If you would like to track a certain page as something other than what appears in the browser address bar, you can do so by modifying the page_name parameter in module.yml:
all:
myAction:
sf_google_analytics_plugin:
params:
page_name: something_else
For finer control over when the alternate page name is used, you can access the tracker object directly in your action. This also exposes additional funcionality.
use_flashFor example, if you want to track a successful form submission for a form that redirects to the same page on success and on error:
<?php class mainActions extends sfActions { public function executeContact() { // form submission logic... if ($success) { $this->getTracker()->setPageName('/contact/success', array( 'use_flash' => true, )); $this->setFlash('feedback', 'Thank you!'); $this->redirect('main/contact'); } } }
In this example, the request after the successful form post will be tracked as /contact/success.
is_routeOne more option available is the is_route option. When this flag is applied, the string provided for a page name will be passed through sfRouting before being added to the page. Using this option allows you to centralize all URLs, those real and for tracking purposes only, in your application's routing.yml file:
contact:
url: /contact
param: { module: main, action: contact }
# be sure the tracking rule comes AFTER the real rule so the application
# doesn't use it for any url_for('main/contact') calls
track_contact:
url: /contact/success
param: { module: main, action: contact }
[php]
<?php
class mainActions extends sfActions
{
public function executeContact()
{
// form submission logic...
if ($success)
{
$this->getTracker()->setPageName('@track_contact', array(
'use_flash' => true,
'is_route' => true,
));
$this->setFlash('feedback', 'Thank you!');
$this->redirect('@contact');
}
}
}
You can easily configure the tracking code for a single module or even a single action by using the module.yml configuration file:
all:
# disable tracking for this module...
sf_google_analytics_plugin:
params:
enabled off
# ...or for a single action
index:
sf_google_analytics_plugin:
params:
enabled off
Alternatively, you can access the tracker object directly from inside your action:
<?php class mainActions extends sfActions { public function executeIndex() { $this->getTracker()->setEnabled(false); } }
You can configure this in app.yml:
all:
sf_google_analytics_plugin:
profile_id: XX-XXXXX-X
insertion: top
You can expose whatever information you store on your users (that your privacy policy allows, of course) to Google Analytics. This is best done in your sign-in routine. For example, if you're using sfGuardPlugin:
<?php class myUser extends sfGuardSecurityUser { /** * Overload to add custom tracking variables to the current user. * * Variables are added using flash, assuming sign in will be followed by a * redirect. * * @see sfGuardSecurityUser */ public function signIn($user, $remember = false, $con = null) { parent::signIn($user, $remember, $con); // assign tracking variables if ($gender = $user->getProfile()->getGender()) { $this->getTracker()->setVar('gender/'.$gender, array( 'use_flash' => true, )); } if ($this->hasCredential('moderator')) { $this->getTracker()->setVar('userType/moderator', array( 'use_flash' => true, )); } } }
sfLogger interactions.ga.js).sfRouting.sfFlash storage (helpful for redirects).<body> tags with attributes.Kris Wallsmith
