/**
  * Insert tracking code for applicable web requests.
  * 
  * @param   sfFilterChain $filterChain
  */
 public function execute($filterChain)
 {
     $prefix = 'app_sf_google_analytics_plugin_';
     $user = $this->context->getUser();
     $request = $this->context->getRequest();
     $response = $this->context->getResponse();
     if ($this->isFirstCall()) {
         $classes = array_merge(array('urchin' => 'sfGoogleAnalyticsTrackerUrchin', 'google' => 'sfGoogleAnalyticsTrackerGoogle'), sfConfig::get($prefix . 'classes', array()));
         $class = $classes[sfConfig::get($prefix . 'tracker', 'urchin')];
         $tracker = new $class($this->context);
         // pull callables from session storage
         $callables = $user->getAttribute('callables', array(), 'sf_google_analytics_plugin');
         foreach ($callables as $callable) {
             list($method, $arguments) = $callable;
             call_user_func_array(array($tracker, $method), $arguments);
         }
         $request->setTracker($tracker);
     }
     $filterChain->execute();
     $tracker = $request->getTracker();
     // apply module- and action-level configuration
     $module = $this->context->getModuleName();
     $action = $this->context->getActionName();
     $moduleParams = sfConfig::get('mod_' . strtolower($module) . '_sf_google_analytics_plugin_params', array());
     $tracker->configure($moduleParams);
     $actionConfig = sfConfig::get('mod_' . strtolower($module) . '_' . $action . '_sf_google_analytics_plugin', array());
     if (isset($actionConfig['params'])) {
         $tracker->configure($actionConfig['params']);
     }
     // insert tracking code
     if ($this->isTrackable() && $tracker->isEnabled()) {
         if (sfConfig::get('sf_logging_enabled')) {
             sfGoogleAnalyticsToolkit::logMessage($this, 'Inserting tracking code.');
         }
         $tracker->insert($response);
     } elseif (sfConfig::get('sf_logging_enabled')) {
         sfGoogleAnalyticsToolkit::logMessage($this, 'Tracking code not inserted.');
     }
     $user->getAttributeHolder()->removeNamespace('sf_google_analytics_plugin');
     $tracker->shutdown($user);
 }
/**
 * Confirm the tracker is configured correctly to support a linker.
 * 
 * @param   sfGoogleAnalyticsTracker $tracker
 */
function _check_linker_settings(sfGoogleAnalyticsTracker $tracker)
{
    if ($tracker->getDomainName() !== 'none' || $tracker->getLinkerPolicy() !== true) {
        sfGoogleAnalyticsToolkit::logMessage(basename(__FILE__), 'If tracking multiple domain names on one profile, the app.yml "domain_name" setting should be "off" and the "linker_policy" setting should be "on".', 'notice');
    }
}
 /**
  * Update storage with callables for the next tracker.
  * 
  * @param   sfUser $user
  */
 public function shutdown($user)
 {
     if (sfConfig::get('sf_logging_enabled')) {
         sfGoogleAnalyticsToolkit::logMessage($this, 'Copying callables to session storage.');
     }
     $user->getAttributeHolder()->set('callables', $this->parameterHolder->getAll('flash', array()), 'sf_google_analytics_plugin');
 }