### Eclipse Workspace Patch 1.0
#P drupal-contrib-6--1
Index: modules/google_analytics/googleanalytics.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_analytics/googleanalytics.admin.inc,v
retrieving revision 1.2.2.11
diff -u -r1.2.2.11 googleanalytics.admin.inc
--- modules/google_analytics/googleanalytics.admin.inc	10 Feb 2008 13:20:53 -0000	1.2.2.11
+++ modules/google_analytics/googleanalytics.admin.inc	13 Feb 2008 20:25:02 -0000
@@ -134,6 +134,14 @@
     '#disabled' => (module_exists('search') ? FALSE : TRUE),
   );
 
+  $form['advanced']['googleanalytics_site_search'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Do Track Internal Search'),
+    '#description' => t('If checked, internal search keywords are tracked. You must configure your Google account to use the internal query parameter <em>search</em>. For more information see <a href="!url">How do I set up Site Search for my profile</a>.', array('!url' => 'http://www.google.com/support/analytics/bin/answer.py?hl='. $language->language .'&answer=75817')) . $site_search_dependencies,
+    '#default_value' => variable_get('googleanalytics_site_search', FALSE),
+    '#disabled' => (module_exists('search') ? FALSE : TRUE),
+  );
+
   $form['advanced']['googleanalytics_codesnippet'] = array(
     '#type' => 'textarea',
     '#title' => t('JavaScript Code'),
@@ -142,5 +150,16 @@
     '#description' => t('Paste <a href="!snippets">custom code snippets here</a>. These will be added to every page that Google Analytics appears on. For help with this feature see the <a href="!blog">cutroni.com blog</a>. <strong>Do not include the &lt;script&gt; tags</strong>, and always end your code with a semicolon (;).', array('!snippets' => 'http://drupal.org/node/39282', '!blog' => 'http://cutroni.com/blog/'))
   );
 
+  $form['advanced']['googleanalytics_js_scope'] = array(
+    '#type' => 'select',
+    '#title' => t('JavaScript scope'),
+    '#description' => t("<strong>Warning:</strong> Google recommends adding the external JavaScript files to footer for performance reasons."),
+    '#options' => array(
+      'footer' => t('Footer'),
+      'header' => t('Header'),
+    ),
+    '#default_value' => variable_get('googleanalytics_js_scope', 'footer'),
+  );
+
   return system_settings_form($form);
 }
Index: modules/google_analytics/googleanalytics.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_analytics/googleanalytics.install,v
retrieving revision 1.4.2.6
diff -u -r1.4.2.6 googleanalytics.install
--- modules/google_analytics/googleanalytics.install	9 Feb 2008 20:42:39 -0000	1.4.2.6
+++ modules/google_analytics/googleanalytics.install	13 Feb 2008 20:25:02 -0000
@@ -26,6 +26,7 @@
   variable_del('googleanalytics_cache');
   variable_del('googleanalytics_last_cache');
   variable_del('googleanalytics_site_search');
+  variable_del('googleanalytics_js_scope');
 }
 
 
Index: modules/google_analytics/googleanalytics.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_analytics/googleanalytics.module,v
retrieving revision 1.16.2.15
diff -u -r1.16.2.15 googleanalytics.module
--- modules/google_analytics/googleanalytics.module	12 Feb 2008 23:05:22 -0000	1.16.2.15
+++ modules/google_analytics/googleanalytics.module	13 Feb 2008 20:25:02 -0000
@@ -37,14 +37,33 @@
 
   // Use the old version of Google Analytics?
   $legacy_version = variable_get('googleanalytics_legacy_version', FALSE);
+  $scope = variable_get('googleanalytics_js_scope', 'footer');
+
+  // Are we on a secure page?
+  $prefix = '://www';
+  if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) {
+    $prefix = 's://ssl';
+  }
+
+  // Should a local cached copy of urchin.js or ga.js be used?
+  $js_file = ($legacy_version) ? 'urchin.js' : 'ga.js';
+  $url = 'http'. $prefix .'.google-analytics.com/'. $js_file;
+
+  if (variable_get('googleanalytics_cache', 0) && (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC) && $source = _googleanalytics_cache($url)) {
+    drupal_add_js($source, 'module', $scope);
+  }
+  else {
+    $script .= 'document.write(unescape("%3Cscript src=\''. $source .'\' type=\'text/javascript\'%3E%3C/script%3E"));';
+    drupal_add_js($script, 'inline', $scope);
+  }
 
   // Add download tracking.
   $path = drupal_get_path('module', 'googleanalytics');
   if ($trackfiles = variable_get('googleanalytics_trackfiles', GA_TRACKFILES)) {
     drupal_add_js(array('googleanalytics' => array('trackDownload' => $trackfiles, 'LegacyVersion' => $legacy_version)), 'setting', 'header');
-    drupal_add_js($path .'/downloadtracker.js', 'module', 'footer');
+    drupal_add_js($path .'/downloadtracker.js', 'module', $scope);
   }
-
+  
 }
 
 /**
@@ -61,13 +80,6 @@
   // Don't track page views in the admin sections
   if ($id && (arg(0) != 'admin') && $track == TRUE) {
 
-    $prefix = '://www';
-
-    // Are we on a secure page?
-    if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) {
-      $prefix = 's://ssl';
-    }
-
     // Use the old version of Google Analytics?
     $legacy_version = variable_get('googleanalytics_legacy_version', FALSE);
 
@@ -102,27 +114,6 @@
     // Add any custom code snippets if specified.
     $codesnippet = variable_get('googleanalytics_codesnippet', '');
 
-    // Should a local cached copy of urchin.js or ga.js be used?
-    if (variable_get('googleanalytics_cache', 0) && (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC)) {
-      if ($legacy_version) {
-        $source = _googleanalytics_cache('http://www.google-analytics.com/urchin.js');
-      }
-      else {
-        $source = _googleanalytics_cache('http://www.google-analytics.com/ga.js');
-      }
-      if (!empty($source)) {
-        $source = base_path() . $source;
-      }
-    }
-    if (!isset($source)) {
-      if ($legacy_version) {
-        $source = 'http'. $prefix .'.google-analytics.com/urchin.js';
-      }
-      else {
-        $source = 'http'. $prefix .'.google-analytics.com/ga.js';
-      }
-    }
-
     // Site search tracking support.
     $url_custom = '';
     if (module_exists('search') && variable_get('googleanalytics_site_search', FALSE) && arg(0) == 'search') {
@@ -137,8 +128,6 @@
 
     // Should the legacy code be used?
     if ($legacy_version) {
-      $script = '<script type="text/javascript" src="'. $source ."\"></script>\n";
-      $script .= '<script type="text/javascript">';
       $script .= '_uacct = "'. $id .'";';
       if (!empty($segmentation)) {
         $script .= $segmentation;
@@ -147,13 +136,8 @@
         $script .= $codesnippet;
       }
       $script .= 'urchinTracker('. $url_custom .');';
-      $script .= "</script>\n";
     }
     else {
-      $script = '<script type="text/javascript">';
-      $script .= 'document.write(unescape("%3Cscript src=\''. $source .'\' type=\'text/javascript\'%3E%3C/script%3E"));';
-      $script .= "</script>\n";
-      $script .= '<script type="text/javascript">';
       $script .= 'var pageTracker = _gat._getTracker("'. $id .'");';
       $script .= 'pageTracker._initData();';
       if (!empty($segmentation)) {
@@ -163,10 +147,9 @@
         $script .= $codesnippet;
       }
       $script .= 'pageTracker._trackPageview('. $url_custom .');';
-      $script .= "</script>\n";
     }
 
-    return $script;
+    drupal_add_js($script, 'inline', 'footer');
   }
 }
 
@@ -202,6 +185,12 @@
 
     // New google analytics version.
     file_delete(file_directory_path() .'/googleanalytics/ga.js');
+
+    // Clear aggregated JS files.
+    if (variable_get('preprocess_js', 0)) {
+      drupal_clear_js_cache();
+    }
+
     variable_set('googleanalytics_last_cache', time());
   }
 }
