![]() |
|
sfUrchinPlugin - 0.3.1Easily add Google Analytics. |
|
Easily adds tracking code for Google Analytics to your presentation layer.
sfUrchinActionMixin: Adds convenience methods to your actions.sfUrchinFilter: Adds necessary tracking code to the bottom of every HTML page.UrchinHelper: Helper functions for adding urchinTracker calls to links.Install the plugin:
./symfony plugin-install http://plugins.symfony-project.com/sfUrchinPlugin
Configure your Google Analytics account in app.yml:
prod: urchin: enabled: on uacct: xx-xxxxxxx-x # <-- put your site's account number here
all: urchin: enabled: off
Add sfUrchinFilter to filters.yml just after web_debug:
rendering: web_debug: urchin: class: sfUrchinFilter # etc...
Just by adding the filter and enabling the plugin in app.yml your site should begin tracking on your Google Analytics account. Beyond this, there are a few more pieces of functionality that allow you finer control over how your site interacts with Google Analytics.
// from inside an action
null $this->setUrchinParam(string $utParam)
If any of your actions call any of the forward methods, the action that actually renders will likely not be the action referenced in the browser's address bar. This mixed-in method allows you to specify a URI to send up to Google Analytics once the page is loaded other that what is in the address bar.
For example, if you want to track how many visitors land on your error_404_action, you could call this:
// from inside an action
$this->setUrchinParam('/error/404?page='.$this->getModuleName().'/'.$this->getActionName());
// from inside an action
null $this->addUrchinVar(string $name, string $value)
You can add a custom variable to the Javascript code that initializes Google Analytics using this method. For example, if you want to track an action as a different subdomain:
// from inside an action
$this->addUrchinVar('udn', 'domain.com');
This call will add a _udn variable to your initialization block:
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct="xx-xxxxxxx-x";
_udn="domain.com";
urchinTracker();
</script>
string urchin_link_to(string $name, string $internalUri[string $urchinUri[, array $options]](,))
You'll want to use this helper to track outbound links as well as those that go to a local file that doesn't have Google Analytics tracking code at the bottom (e.g. a PDF or image).
For example, if you want to track a link to the symfony site:
<?php use_helper('Urchin') ?>
<p>
For more information, please visit the
<?php echo urchin_link_to('symfony project site',
'http://www.symfony-project.com',
'/outbound/symfony') ?>.
</p>
Or to track downloads of a PDF:
<?php use_helper('Urchin') ?>
<p>
You can also download <?php echo urchin_link_to('the PDF version',
'/doc/the-book.pdf') ?>.
</p>
string urchin_link_to_function(string $name, string $function, string $urchinUri[array $options](,))
This helper function will send a call to Google Analytics when your user clicks a Javascript link. For example, if you want to track calls to a link that closes a popup window:
<?php use_helper('Urchin') ?>
<p><?php echo urchin_link_to_function('close window',
'window.close()',
'/popups/mom/close',
'id=closer') ?></p>
By changing the insertion configuration variable, you can specify where in the response content the tracking code should be placed. The plugin comes with two options pre-built, top and bottom.
prod:
urchin:
enabled: on
all:
urchin:
uacct: xx-xxxxxxx-x
insertion: top
These settings will place the tracking code just inside the response's opening <body> tag (in the prod environment). The plugin defaults to placing the tracking code just before the response's closing </body> tag.
Support for:
__utmLinker()__utmLinkPost()Kris Wallsmith