Index: googleanalytics.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_analytics/googleanalytics.admin.inc,v
retrieving revision 1.13.2.6
diff -u -p -r1.13.2.6 googleanalytics.admin.inc
--- googleanalytics.admin.inc	6 Jun 2010 11:13:51 -0000	1.13.2.6
+++ googleanalytics.admin.inc	7 Jul 2010 23:27:18 -0000
@@ -244,6 +244,53 @@ function googleanalytics_admin_settings_
     '#description' => t("Code in this textarea will be added <strong>after</strong> _gaq.push(['_trackPageview']). This is useful if you'd like to track a site in two accounts."),
   );
 
+  $form['advanced']['custom_var'] = array(
+   '#type' => 'fieldset',
+   '#title' => t('Custom Variables'),
+   '#collapsible' => TRUE,
+   '#collapsed' => TRUE,
+   '#description' => t('You can add Google Analytics <a href="@custom_var">Custom Variables</a> here. These will be added to every page that Google Analytics appears on.', array('@custom_var' => 'http://code.google.com/intl/zh-TW/apis/analytics/docs/tracking/gaTrackingCustomVariables.html'))
+  );
+  if (module_exists('token')) {
+   $form['advanced']['custom_var']['token_help'] = array(
+     '#title' => t('Replacement patterns'),
+     '#type' => 'fieldset',
+     '#collapsible' => TRUE,
+     '#collapsed' => TRUE,
+     );
+  
+   $form['advanced']['custom_var']['token_help']['help'] = array(
+     '#value' => theme('token_help', 'node'),
+     );
+  }
+  for ($i = 1; $i < 6; $i++) {
+    $form['advanced']['custom_var']['googleanalytics_custom_var_'. $i] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Variable %index', array('%index' => $i)),
+    );
+    $form['advanced']['custom_var']['googleanalytics_custom_var_'. $i]['googleanalytics_custom_var_'. $i .'_name'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Name'),
+      '#default_value' => variable_get('googleanalytics_custom_var_'. $i .'_name', ''),
+    );
+    $form['advanced']['custom_var']['googleanalytics_custom_var_'. $i]['googleanalytics_custom_var_'. $i .'_value'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Value'),
+      '#default_value' => variable_get('googleanalytics_custom_var_'. $i .'_value', ''),
+      '#description' => t('You may use tokens in this field.'),
+    );
+    $form['advanced']['custom_var']['googleanalytics_custom_var_'. $i]['googleanalytics_custom_var_'. $i .'_scope'] = array(
+      '#type' => 'select',
+      '#title' => t('Scope'),
+      '#default_value' => variable_get('googleanalytics_custom_var_'. $i .'_scope', 3),
+      '#options' => array(
+         3 => 'page', 
+         2 => 'session',
+         1 => 'visitor',
+      ),
+    );
+  }
+
   /* hook_footer() is not able to add code to head. Upgrade to D7 required.
   $form['advanced']['googleanalytics_js_scope'] = array(
     '#type' => 'select',
Index: googleanalytics.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_analytics/googleanalytics.install,v
retrieving revision 1.13.2.4
diff -u -p -r1.13.2.4 googleanalytics.install
--- googleanalytics.install	6 Jun 2010 11:13:51 -0000	1.13.2.4
+++ googleanalytics.install	7 Jul 2010 23:27:18 -0000
@@ -40,6 +40,11 @@ function googleanalytics_uninstall() {
   variable_del('googleanalytics_pages');
   variable_del('googleanalytics_tracker_anonymizeip');
   variable_del('googleanalytics_translation_set');
+  for ($i = 1; $i < 6; $i++) {
+    variable_del('googleanalytics_custom_var_'. $i .'_name');
+    variable_del('googleanalytics_custom_var_'. $i .'_value');
+    variable_del('googleanalytics_custom_var_'. $i .'_scope');
+  }
 }
 
 /**
Index: googleanalytics.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_analytics/googleanalytics.module,v
retrieving revision 1.36.2.8
diff -u -p -r1.36.2.8 googleanalytics.module
--- googleanalytics.module	6 Jun 2010 11:13:51 -0000	1.36.2.8
+++ googleanalytics.module	7 Jul 2010 23:27:18 -0000
@@ -137,6 +137,25 @@ function googleanalytics_footer($main = 
     $codesnippet_before = variable_get('googleanalytics_codesnippet_before', '');
     $codesnippet_after = variable_get('googleanalytics_codesnippet_after', '');
 
+    // Add custom variables.
+    $custom_var = '';
+    for ($i = 1; $i < 6; $i++) {
+     $custom_var_name = variable_get('googleanalytics_custom_var_'. $i .'_name', '');
+     if ($custom_var_name) {
+       $custom_var_value = variable_get('googleanalytics_custom_var_'. $i .'_value', '');
+       $custom_var_scope = variable_get('googleanalytics_custom_var_'. $i .'_scope', '');
+
+       if (module_exists('token')) {
+         $node = menu_get_object();
+         $custom_var_value = token_replace($custom_var_value, 'node', $node);
+       }
+
+       $custom_var_name = drupal_to_js($custom_var_name);
+       $custom_var_value = drupal_to_js($custom_var_value);
+       $custom_var .= "_gaq.push(['_setCustomVar', $i, $custom_var_name, $custom_var_value, $custom_var_scope]);";
+     }
+    }
+
     // Build tracker code.
     $script = 'var _gaq = _gaq || [];';
     $script .= '_gaq.push(["_setAccount", ' . drupal_to_js($id) . ']);';
@@ -149,6 +168,9 @@ function googleanalytics_footer($main = 
     if (!empty($codesnippet_before)) {
       $script .= $codesnippet_before;
     }
+    if (!empty($custom_var)) {
+      $script .= $custom_var;
+    }
     if (empty($url_custom)) {
       $script .= '_gaq.push(["_trackPageview"]);';
     }
