### Eclipse Workspace Patch 1.0
#P drupal-contrib-6--1
Index: modules/google_analytics/googleanalytics.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_analytics/googleanalytics.module,v
retrieving revision 1.16.2.46
diff -u -r1.16.2.46 googleanalytics.module
--- modules/google_analytics/googleanalytics.module	26 Jun 2008 17:29:07 -0000	1.16.2.46
+++ modules/google_analytics/googleanalytics.module	28 Jun 2008 18:10:32 -0000
@@ -176,8 +176,10 @@
       if (!empty($codesnippet)) {
         $script .= $codesnippet;
       }
+      $script .= _googleanalytics_get_tracking_code('preprocess');
       $script .= 'pageTracker._initData();';
       $script .= 'pageTracker._trackPageview('. $url_custom .');';
+      $script .= _googleanalytics_get_tracking_code('process');
     }
 
     drupal_add_js($script, 'inline', 'footer');
@@ -378,3 +380,53 @@
   }
   return $page_match;
 }
+
+/**
+ * Builds the tracking code for variables from hook_googleanalytics.
+ */
+function _googleanalytics_get_tracking_code($hook, $prefix = 'pageTracker.') {
+  $output = '';
+  $array = module_invoke_all('googleanalytics', $hook);
+
+  foreach ($array['methods'] as $key => $methods) {
+    foreach ($methods as $method => $value) {
+      $output .= $prefix . $method .'('. _googleanalytics_to_tracking($value) .');';
+    }
+  }
+  return $output;
+}
+
+/**
+ * Converts arrays from hook_googleanalytics into Google Analytics 
+ * friendly tracking code values.
+ * 
+ * Modified version of drupal_to_js().
+ */
+function _googleanalytics_to_tracking($var) {
+
+  switch (gettype($var)) {
+    case 'boolean':
+      return $var ? 'true' : 'false'; // Lowercase necessary!
+    case 'integer':
+    case 'double':
+      return $var;
+    case 'resource':
+    case 'string':
+      return '"'. str_replace(array("\r", "\n", "<", ">", "&"),
+                              array('\r', '\n', '\x3c', '\x3e', '\x26'),
+                              addslashes($var)) .'"';
+    case 'array':
+      // Arrays in JSON can't be associative. If the array is empty or if it
+      // has sequential whole number keys starting with 0, it's not associative
+      // so we can go ahead and convert it as an array.
+      if (empty ($var) || array_keys($var) === range(0, sizeof($var) - 1)) {
+        $output = array();
+        foreach ($var as $v) {
+          $output[] = _googleanalytics_to_tracking($v);
+        }
+        return implode(', ', $output);
+      }
+    default:
+      return 'null';
+  }
+}
