Index: googleanalytics.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_analytics/googleanalytics.module,v
retrieving revision 1.14.2.22
diff -u -p -r1.14.2.22 googleanalytics.module
--- googleanalytics.module	30 Dec 2007 01:48:30 -0000	1.14.2.22
+++ googleanalytics.module	8 Jan 2008 00:40:38 -0000
@@ -118,26 +118,28 @@ function googleanalytics_footer($main = 
     // Add any custom code snippets if specified
     $codesnippet = variable_get('googleanalytics_codesnippet', '');
 
-    // Should a local cached copy of Urchin.js be used?
-    if (variable_get('googleanalytics_cache', 0) && (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC)) {
-      $source = googleanalytics_cache();
-      if ($source) {
-        $source = base_path() . $source;
+    // Add the .js file. Prefer a locally cached copy urchin.js/ga.js?
+    // TODO: googleanalytics_cache() should be updated to also cache ga.js!
+    if (variable_get('googleanalytics_cache', 0) && (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC) && $source = googleanalytics_cache()) {
+      drupal_add_js($source, 'module', 'footer');
+    }
+    else {
+      if ($legacy_version) {
+        $script = '<script type="text/javascript" src="http'. $prefix .".google-analytics.com/urchin.js\"></script>\n";
+      }
+      else {
+        $script = '<script type="text/javascript">
+                      document.write("\<script src=\'http" + "'. $prefix .'" + ".google-analytics.com/ga.js\' type=\'text/javascript\'>\<\/script>" );
+                    </script>';
       }
-    }
-    if (!isset($source)) {
-      $source = 'http'. $prefix .'.google-analytics.com/urchin.js';
     }
 
-    // Should the legacy code be used?
+    // Add Javascript code to set parameters and start the tracking.
     if ($legacy_version) {
-      $script = '<script type="text/javascript" src="' . $source . "\"></script>\n";
       $script .= '<script type="text/javascript">' . "<!--\n_uacct = \"".$id."\";{$segmentation}{$codesnippet}urchinTracker();\n// --></script><noscript></noscript>\n";
-    } else {
-      $script ='<script type="text/javascript">
-                  document.write("\<script src=\'http" + "' . $prefix . '" + ".google-analytics.com/ga.js\' type=\'text/javascript\'>\<\/script>" );
-                </script>
-                <script type="text/javascript">
+    }
+    else {
+      $script .='<script type="text/javascript">
                   var pageTracker = _gat._getTracker("'.$id.'");
                   pageTracker._initData();
                   '.$segmentation.$codesnippet.'
