Index: googleanalytics.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_analytics/googleanalytics.install,v
retrieving revision 1.2
diff -U3 -r1.2 googleanalytics.install
--- googleanalytics.install	21 Nov 2006 14:17:54 -0000	1.2
+++ googleanalytics.install	9 May 2007 21:03:48 -0000
@@ -5,13 +5,35 @@
   $result = db_query('SELECT * FROM {role} ORDER BY name');

   while ($role = db_fetch_object($result)) {
-    $role_varname = $string = str_replace(" ", "_", $role->name);
-    $ga_role = "googleanalytics_track_{$role_varname}";
+    $ga_role = "googleanalytics_track_".  $role->rid;

     //check if variable is not already set from a previous install
     if(strpos(variable_get($ga_role, 'new'), 'new') !== FALSE) {
-      variable_set($ga_role, TRUE);
+      variable_set($ga_role, FALSE);
       drupal_set_message(t('Role %rolename is now being tracked by Google Analytics', array('%rolename' => $role->name)));
     }
   }
+}
+
+function googleanalytics_uninstall() {
+  $result = db_query("SELECT rid FROM {role}");
+  while ($role = db_fetch_object($result)) {
+    variable_del("googleanalytics_track_".  $role->rid);
+  }
+  variable_del("googleanalytics_account");
+  variable_del("googleanalytics_codesnippet");
+  variable_del("googleanalytics_filetypes");
+  variable_del("googleanalytics_segmentation");
+  variable_del("googleanalytics_track__user1");
+}
+
+function googleanalytics_update_1() {
+  $result = db_query("SELECT * FROM {role}");
+  while ($role = db_fetch_object($result)) {
+     // can't use empty spaces in varname
+    $role_varname = str_replace(" ", "_", $role->name);
+    variable_set("googleanalytics_track_".  $role->rid,   !variable_get("googleanalytics_track_{$role_varname}", FALSE));
+    variable_del("googleanalytics_track_{$role_varname}");
+  }
+  variable_set("googleanalytics_track__user1", TRUE);
 }
\ No newline at end of file
Index: googleanalytics.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_analytics/googleanalytics.module,v
retrieving revision 1.14.2.3
diff -U3 -r1.14.2.3 googleanalytics.module
--- googleanalytics.module	3 May 2007 10:58:17 -0000	1.14.2.3
+++ googleanalytics.module	9 May 2007 21:03:48 -0000
@@ -43,14 +43,14 @@
   $id = variable_get('googleanalytics_account', '');

   // Check if we should track the currently active user's role
-  $track = 0;
-  foreach($user->roles as $role) {
-    $role = str_replace(' ', '_', $role);
-    $track += variable_get("googleanalytics_track_{$role}", FALSE);
+  $track = TRUE;
+  foreach(array_keys($user->roles) as $role) {
+    if (variable_get("googleanalytics_track_". $role, FALSE)) {$track = FALSE;}
   }
+  if ($user->uid == 1 and variable_get("googleanalytics_track__user1", FALSE)) {$track = FALSE;}

   // Don't track page views in the admin sections
-  if($id && (arg(0) != 'admin') && $track > 0) {
+  if($id && (arg(0) != 'admin') && $track == TRUE) {

     $prefix = '://www';

@@ -74,15 +74,22 @@

         $fields[$field] = $value;
       }
-      $segmentation = "__utmSetVar('".implode(':', $fields)."');";
 		}

 		// Add any custom code snippets if specified
 		$codesnippet = variable_get('googleanalytics_codesnippet', '');
-
-    $script = '<script type="text/javascript" src="http' . $prefix . ".google-analytics.com/urchin.js\"></script>\n";
-    $script .= '<script type="text/javascript">' . "<!--\n_uacct = \"".$id."\";{$segmentation}{$codesnippet}urchinTracker();\n// --></script><noscript></noscript>\n";
-    return $script;
+    // Include the GoogleAnalytics javascript
+    // since drupal_add_js dont allow external files, the old style is used
+    drupal_set_html_head("<script type='text/javascript' src='http". $prefix .".google-analytics.com/urchin.js'></script>");
+//     drupal_add_js("http". $prefix .".google-analytics.com/urchin.js");
+    // Include variables needed
+    drupal_add_js("ga_basepath='". base_path() ."'", "inline");
+    drupal_add_js("_uacct='$id'", "inline");
+    drupal_add_js("ga_filetypes='". variable_get("googleanalytics_filetypes", "pdf|doc|xls|ppt|jpeg|jpg|gif|png|mp3|ogg|avi|mpg|rm|wav") ."'", "inline");
+    if (!empty($fields)) {drupal_add_js("__utmSetVar='". implode(":", $fields) ."'", "inline");}
+    // Custom Snippet
+    if (!empty($codesnippet)) {return "<script type='text/javascript'><!--\n{$codesnippet}\n// --></script><noscript></noscript>\n";}
+    return;
   }
 }

@@ -113,16 +120,19 @@
         '#type' => 'fieldset',
         '#title' => t('User Role Tracking'),
         '#collapsible' => TRUE,
-        '#description' => t('Define what user roles should be tracked by Google Analytics.')
+        '#description' => t('Define what user roles should not be tracked by Google Analytics.')
+  );
+  $form['roles']["googleanalytics_track__user1"] = array(
+    '#type' => 'checkbox',
+    '#title' => t("Admin (user 1)"),
+    '#default_value' => variable_get("googleanalytics_track__user1", TRUE)
   );

   while ($role = db_fetch_object($result)) {
-     // can't use empty spaces in varname
-    $role_varname = $string = str_replace(' ', '_', $role->name);
-    $form['roles']["googleanalytics_track_{$role_varname}"] = array(
+    $form['roles']["googleanalytics_track_". $role->rid] = array(
       '#type' => 'checkbox',
       '#title' => t($role->name),
-      '#default_value' => variable_get("googleanalytics_track_{$role_varname}", FALSE),
+      '#default_value' => variable_get("googleanalytics_track_". $role->rid, FALSE),
     );
   }

@@ -132,7 +142,12 @@
         '#collapsible' => TRUE,
         '#description' => t('If your users have profile fields completed, you can track your logged in users based on a defined profile field.')
   );
-
+  $form['filetypes'] = array(
+        '#type' => 'fieldset',
+        '#title' => t('Track Downloads'),
+        '#default_value' => variable_get("googleanalytics_filetypes", "pdf|doc|xls|ppt|jpeg|jpg|gif|png|mp3|ogg|avi|mpg|rm|wav"),
+        '#description' => t('GoogleAnalytics has the ability to track downloads from your side. List here all types os files (separated by | ).')
+  );
   if(!module_exists('profile')) {
     $form['segmentation']['profile'] = array(
       '#type' => 'markup',
