Great mod, thanks much!

I noticed that the Google analytics code is inserted in the $closure in the webform. On submission however, the $closure is empty.

Comments

jdblank’s picture

Version: 5.x-2.0 » 6.x-2.x-dev

I also noticed that the GA tag is missing on the form submission page so our goals in Google Analtyics do not work. Is there a fix in the works?

quicksketch’s picture

That's strange, I wonder what Webform could be doing to cause such a problem. I don't have time currently to look into this specific problem. Any patches or suggestions would be appreciated.

izkreny’s picture

quicksketch’s picture

Status: Active » Closed (won't fix)

Unless a patch is provided, this problem will remain unfixed. I'm moving to won't fix as I have no intention of correcting it. Patches accepted of course.

mrfelton’s picture

pgilmore’s picture

I've encountered the same problem and found that the drupal_get_js() is called twice the first time before the html is rendered on submission, thus not printing out the _trackEvent method.

I solved it this way, but it fells a bit like a hack so if someone has a better solution please enlighten me.

function mymodule_add_form_safe_js($data = NULL, $type = 'module', $scope = 'header', $defer = FALSE, $cache = TRUE, $preprocess = TRUE) {
  $javascripts = array();
  if(isset($_SESSION['mymodule']['javascripts'])) {
    $javascripts = json_decode($_SESSION['mymodule']['javascripts']);
  } 
  
  $javascripts[] = array('data' => $data, 'type' => $type, 'scope' => $scope, 'defer' => $defer, 'cache' => $cache, 'preprocess' => $preprocess);

  $_SESSION['mymodule']['javascripts'] = json_encode($javascripts);
}
function mymodule_get_form_safe_js() {
  if(isset($_SESSION['mymodule']['javascripts'])) {
    $javascripts = json_decode($_SESSION['mymodule']['javascripts']);
    foreach($javascripts as $javascript) {
     drupal_add_js($javascript->data,$javascript->type,$javascript->scope,$javascript->defer,$javascript->cache,$javascript->preprocess); 
    }
    unset($_SESSION['mymodule']['javascripts']);
  }
}
/**
* @see hook_init
*/
function mymodule_init() {
  mymodule_get_form_safe_js();
}

This stores the js-call in a session that is the printed out once the hook_init is called which it is on loading of the form.

Thanks!

lane.angelique’s picture

In the Google Analytics settings (/admin/settings/googleanalytics)
Under "Page specific tracking settings", node/*/* is being excluded.
This is why the $closure variable is blank.

mo6’s picture

Please note that the Piwik analytics module has the same default configuration for "Page specific tracking settings", so webform confirmation pages are not tracked by default by Piwik. Removing the offending line 'node/*/*' enables tracking of webform confirmation pages, which is useful for tracking goals.