sfExternalLinkTracker plugin
The sfExternalLinkTrackerPlugin offers the possibility to track when a user activates a link to an external website.
Features
- enable/disable link tracking
- configure redirection behaviour
Installation
Install the plugin
$ symfony plugin-install http://plugins.symfony-project.com/sfExternalLinkTrackerPlugin
Alternatively, if you don't have PEAR installed, you can download the latest package attached to this plugin's wiki page and extract it under your project's plugins/ directory
Rebuild your model
symfony propel-build-all
Clear the cache to enable the autoloading of the classes and helper
$ symfony cc
Enable one or more modules in your settings.yml
- For your backend application: sfExternalLinkTracker (optional)
- For your frontend application: sfExternalLink
Example:
all:
.settings:
enabled_modules: [..., sfExternalLink](default,)
Add the following routing rules to routing.yml
The new route is mandatory, because the ExternalLink helper of this plugin
needs this route
sf_external_link:
url: /external_link/:url
param: {module: sfExternalLink, action: link}
Add a extra method to your myUser
The plugin calls the getId method of the myUser class.
myapp/lib/myUser.class.php
When you do not have implemented this method yet, you have to add it, according to your used user management.
When you for example use the sfGuardPlugin, this method is only a wrapper method and looks like this
public function getId(){
return $this->getGuardUser()->getId();
}
When you do not use a user management at all, add a dummy method like this:
public function getId(){
return 0;
}
Configuration
The redirection behaviour can be configured in the sfExternalLink module
/plugins/sfExternalLinkTrackerPlugin/modules/sfExternalLink/config/module.yml
Through the greate configuration cascade of symfony, you can overwrite this configuration file and configure your redirection settings.
all:
.settings:
external_link_mode: 0 # 0 for a html redirection page, 1 for immediate redirect
redirect_time: 5 # in seconds
enable_tracking: 1 # 0 for disabling tracking, 1 for enabling
Tutorials
Usage
In a template:
Custom Tracking
To be able to do custom tracking actions, there was introduced the sfExternalLinkTrackerController, which is extendable and called in the sfExternalLink module.
So, with the help of the great sfMixer, one can know do whatever you want without modifying anything of the plugin itself.
One only need a extra class , which could look like this:
<?php
class MyExternalLinkTrackerController{
/**
* custom tracking
*
* @param sfExternalLinkTrackerController $trackController
* @param string $url
*/
public function doMyCustomTrack($trackController, $url)
{
// do your custom tracking here, e.g:
sfContext::getInstance()->getLogger()->info('clicked url: '.$url.', user_id: '.sfContext::getInstance()->getUser()->getId());
}
}
The last thing one have to do, is to register this extra class to the sfMixer:
sfMixer::register('sfExternalLinkTrackerController:doCustomTrack', array('MyExternalLinkTrackerController', 'doMyCustomTrack'));
Demo
With this plugin comes an additionally module, where the linking behaviour is demonstrated.
Enable demo module in your settings.yml
all:
.settings:
enabled_modules: [..., sfExternalLinkTrackerDemo](default,)
Call this module from the web:
http://www.mydomain.com/sfExternalLinkTrackerDemo
Changelog
2007-04-15 | 0.8.1 Beta
- FrankStelzer: added sfExternalLinkTrackerController for custom tracking possibility
2007-04-15 | 0.8.0 Beta
- FrankStelzer: Initial release