Index: simplenews_statistics.install
===================================================================
--- simplenews_statistics.install	(revision 50)
+++ simplenews_statistics.install	(working copy)
@@ -132,6 +132,9 @@
  */
 function simplenews_statistics_uninstall() {
   drupal_uninstall_schema('simplenews_statistics');
+  variable_del('simplenews_statistics_ga_utm_source');
+  variable_del('simplenews_statistics_ga_utm_medium');
+  variable_del('simplenews_statistics_ga_utm_campaign');
 }
 
 /**
Index: simplenews_statistics.module
===================================================================
--- simplenews_statistics.module	(revision 50)
+++ simplenews_statistics.module	(working copy)
@@ -38,6 +38,15 @@
     'access callback' => 'simplenews_statistics_access',
     'access arguments' => array(4),
   );
+  $items['admin/settings/simplenews/google_analytics'] = array(
+    'title' => 'Google Analytics tags',
+    'description' => 'Add google Analytics tags to newsletter links.',
+    'type' => MENU_NORMAL_ITEM,
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('simplenews_statistics_ga'),
+    'access arguments' => array('administer newsletter statistics'),
+    'weight' => -7.9,
+  );
   $items['simplenews/statistics/view'] = array(
     'type' => MENU_CALLBACK,
     'page callback' => 'simplenews_statistics_view',
@@ -56,6 +65,7 @@
  */
 function simplenews_statistics_perm() {
   $perms = array(
+    'administer newsletter statistics',
     'view newsletters statistics',
   );
   return $perms;
@@ -92,10 +102,47 @@
     case 'admin/content/simplenews/statistics/%/clicks':
       $help = '<p>'. t('Listing of all clicks for the newsletter.') ."<p>\n";
       return $help;
+    case 'admin/settings/simplenews/google_analytics':
+      $help = '<p>'. t('See <a href="!ga_url">Google Analytics URL builder</a> for tag information and examples.', array('!ga_url' => 'http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&answer=55578')) ."</p>\n";
+      return $help;
   }
 }
 
+
 /**
+ * Simplenews Google Analytics settings
+ */
+function simplenews_statistics_ga(&$form_state) {
+  $form['simplenews_statistics_ga_utm_source'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Campaign source'),
+    '#required' => TRUE,
+    '#size' => 60,
+    '#maxlength' => 128,
+    '#default_value' => variable_get('simplenews_statistics_ga_utm_source', 'newsletter'),
+  );
+  $form['simplenews_statistics_ga_utm_medium'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Campaign medium'),
+    '#required' => TRUE,
+    '#size' => 60,
+    '#maxlength' => 128,
+    '#default_value' => variable_get('simplenews_statistics_ga_utm_medium', 'email'),
+  );
+  $form['simplenews_statistics_ga_utm_campaign'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Campaign name'),
+    '#required' => TRUE,
+    '#size' => 60,
+    '#maxlength' => 128,
+    '#default_value' => variable_get('simplenews_statistics_ga_utm_campaign', '!newsletter_name'),
+    '#description' => t('Newsletter name, product, promo code, or slogan. Use <em>!newsletter_name</em> to use the name of the newsletter series.'),
+  );
+
+  return system_settings_form($form);
+}
+
+/**
  * simplenews_statistics_view.
  *
  * Gathers the opens
@@ -317,7 +364,7 @@
 /**
  * Helper functions
  */ 
- 
+
 /**
 * Alter link to go through statistics
 */
@@ -327,6 +374,7 @@
 
   require_once drupal_get_path('module', 'simplenews_statistics') . '/rc4.inc';
   $pars = 'nid=' . check_plain($nid) .'&mail='. check_plain($mail) .'&url=' . check_url($match);
+  $pars = _simplenews_statistics_add_ga($pars, $nid);
   $pars = rc4Encrypt(simplenews_private_key(), $pars);
   $pars_hash = md5($pars);
   
@@ -337,6 +385,26 @@
   return $shortened_url;
 }
 
+/**
+ * Add Google Analytics codes to a raw encoded/encrypted URL
+ */
+function _simplenews_statistics_add_ga($pars, $nid) {
+  global $language;
+
+  $campagin = variable_get('simplenews_analytics_utm_campaign', '!newsletter_name');
+  if ($campagin == '!newsletter_name')
+  {
+    $node = node_load($nid);
+    $campaign = $node->title;
+  }
+
+  $pars .= '&utm_source='.drupal_urlencode(variable_get('simplenews_analytics_utm_source', 'newsletter'));
+  $pars .= '&utm_medium='.drupal_urlencode(variable_get('simplenews_analytics_utm_medium', 'email'));
+  $pars .= '&utm_campaign='.drupal_urlencode($campaign);
+
+  return $pars;
+}
+
  /**
  * Decode a request
  */
