| | 1 | = sfUrchinPlugin plugin = |
|---|
| | 2 | |
|---|
| | 3 | Easily adds tracking code for [http://www.google.com/analytics Google Analytics] to your presentation layer. |
|---|
| | 4 | |
|---|
| | 5 | == Features == |
|---|
| | 6 | |
|---|
| | 7 | * `sfUrchinFilter`: Adds necessary tracking code to the bottom of every HTML page. |
|---|
| | 8 | * `UrchinHelper`: Helper functions for adding `urchinTracker` calls to links. |
|---|
| | 9 | |
|---|
| | 10 | == Installation == |
|---|
| | 11 | |
|---|
| | 12 | * Install the plugin: |
|---|
| | 13 | |
|---|
| | 14 | {{{ |
|---|
| | 15 | ./symfony install-plugin http://plugins.symfony-project.com/sfUrchinPlugin |
|---|
| | 16 | }}} |
|---|
| | 17 | |
|---|
| | 18 | * Configure your Google Analytics account in `app.yml`: |
|---|
| | 19 | |
|---|
| | 20 | {{{ |
|---|
| | 21 | prod: |
|---|
| | 22 | urchin: |
|---|
| | 23 | enabled: on |
|---|
| | 24 | uacct: UA-XXXXXXX-X # <-- put your site's account number here |
|---|
| | 25 | |
|---|
| | 26 | all: |
|---|
| | 27 | urchin: |
|---|
| | 28 | enabled: off |
|---|
| | 29 | }}} |
|---|
| | 30 | |
|---|
| | 31 | * Add `sfUrchinFilter` to `filters.yml` just after `rendering`: |
|---|
| | 32 | |
|---|
| | 33 | {{{ |
|---|
| | 34 | rendering: ~ |
|---|
| | 35 | urchin: |
|---|
| | 36 | class: sfUrchinFilter |
|---|
| | 37 | web_debug: ~ |
|---|
| | 38 | # etc... |
|---|
| | 39 | }}} |
|---|
| | 40 | |
|---|
| | 41 | == Usage == |
|---|
| | 42 | |
|---|
| | 43 | 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 three more pieces of functionality that allow you finer control over how your site interacts with Google Analytics. |
|---|
| | 44 | |
|---|
| | 45 | === Track a page as a URI other than its own: `sfUrchinToolkit::setUtParam()` === |
|---|
| | 46 | |
|---|
| | 47 | {{{ |
|---|
| | 48 | null sfUrchinToolkit::setUtParam(string $utParam) |
|---|
| | 49 | }}} |
|---|
| | 50 | |
|---|
| | 51 | 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 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. |
|---|
| | 52 | |
|---|
| | 53 | For example, if you want to track how many visitors land on your `error_404_action`, you could call this from inside that action: |
|---|
| | 54 | |
|---|
| | 55 | {{{ |
|---|
| | 56 | sfUrchinToolkit::setUtParam('/error/404?page='.$this->getModuleName().'/'.$this->getActionName()); |
|---|
| | 57 | }}} |
|---|
| | 58 | |
|---|
| | 59 | === Track clicks on a link: `urchin_link_to()` === |
|---|
| | 60 | |
|---|
| | 61 | {{{ |
|---|
| | 62 | string urchin_link_to(string $name, string $internalUri[, string $urchinUri[, array $options]]) |
|---|
| | 63 | }}} |
|---|
| | 64 | |
|---|
| | 65 | 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). |
|---|
| | 66 | |
|---|
| | 67 | For example, if you want to track a link to the symfony site: |
|---|
| | 68 | |
|---|
| | 69 | {{{ |
|---|
| | 70 | <?php use_helper('Urchin') ?> |
|---|
| | 71 | |
|---|
| | 72 | <p> |
|---|
| | 73 | For more information, please visit the <?php echo urchin_link_to('symfony project site', 'http://www.symfony-project.com', '/outbound/symfony') ?>. |
|---|
| | 74 | </p> |
|---|
| | 75 | }}} |
|---|
| | 76 | |
|---|
| | 77 | Or to track downloads of a PDF: |
|---|
| | 78 | |
|---|
| | 79 | {{{ |
|---|
| | 80 | <?php use_helper('Urchin') ?> |
|---|
| | 81 | |
|---|
| | 82 | <p> |
|---|
| | 83 | You can also download <?php echo urchin_link_to('the PDF version', '/doc/the-book.pdf') ?>. |
|---|
| | 84 | </p> |
|---|
| | 85 | }}} |
|---|
| | 86 | |
|---|
| | 87 | === Track clicks on a Javascript link: `urchin_link_to_function()` === |
|---|
| | 88 | |
|---|
| | 89 | {{{ |
|---|
| | 90 | string urchin_link_to_function(string $name, string $function, string $urchinUri[, array $options]) |
|---|
| | 91 | }}} |
|---|
| | 92 | |
|---|
| | 93 | 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: |
|---|
| | 94 | |
|---|
| | 95 | {{{ |
|---|
| | 96 | <?php use_helper('Urchin') ?> |
|---|
| | 97 | |
|---|
| | 98 | <p><?php echo urchin_link_to_function('close window', 'window.close()', '/popups/mom/close', 'id=closer') ?></p> |
|---|
| | 99 | }}} |
|---|
| | 100 | |
|---|
| | 101 | == Changelog == |
|---|
| | 102 | |
|---|
| | 103 | === Version 0.1.0-beta === |
|---|
| | 104 | |
|---|
| | 105 | * Initial public release. |
|---|
| | 106 | |
|---|
| | 107 | == Maintainers == |
|---|
| | 108 | |
|---|
| | 109 | Kris Wallsmith |
|---|