# HG changeset patch
# User Ricardo Velhote
# Date 1350898276 -3600
# Node ID b96a6d1e42ffe543479635ef222ede003b23a90c
# Parent  8ef7196a8ca93e3cbe67360efc8bf5d73487d8a4
add: google analytics support

diff -r 8ef7196a8ca9 -r b96a6d1e42ff link/link.module
--- a/link/link.module	Mon Oct 22 10:30:54 2012 +0100
+++ b/link/link.module	Mon Oct 22 10:31:16 2012 +0100
@@ -201,6 +201,56 @@
     '#field_suffix' => '"',
     '#size' => 20,
   );
+  
+  $form["enable_ganalytics"] = array(
+  	'#type' => 'checkbox',
+  	'#title' => t('Enable Google Analytics in this link'),
+  	'#default_value' => isset($instance['settings']['enable_ganalytics']) && ($instance['settings']['enable_ganalytics'] !== '') ? $instance['settings']['enable_ganalytics'] : TRUE,
+  	'#description' => t('If checked, the the user will be able to specify Google Analytics tracking settings when clicking in the URL.'),
+  );
+  
+  $form['attributes']['data-ga-category'] = array(
+  	'#type' => 'hidden',
+  	'#title' => t('Category'),
+  	'#default_value' => isset($instance['settings']['attributes']['data-ga-category']) ? $instance['settings']['attributes']['data-ga-category'] : "",
+  	'#description' => t('The general event category (e.g. "Videos")'),
+  );
+  
+  $form['attributes']['data-ga-action'] = array(
+  	'#type' => 'hidden',
+  	'#title' => t('Action'),
+  	'#default_value' => isset($instance['settings']['attributes']['data-ga-action']) ? $instance['settings']['attributes']['data-ga-action'] : "",
+  	'#description' => t('The action for the event (e.g. "Play").'),
+  );
+  
+  $form['attributes']['data-ga-label'] = array(
+  	'#type' => 'hidden',
+  	'#title' => t('Label'),
+  	'#default_value' => isset($instance['settings']['attributes']['data-ga-label']) ? $instance['settings']['attributes']['data-ga-label'] : "",
+  	'#description' => t('An optional descriptor for the event.'),
+  );
+  
+//   $form['attributes']['data_ga_value'] = array(
+//   	'#type' => 'hidden',
+//   	'#title' => t('Value'),
+//   	'#default_value' => isset($instance['settings']['attributes']['data_ga_value']) ? $instance['settings']['attributes']['data_ga_value'] : "",
+//   	'#description' => t('An optional value associated with the event. You can see your event values in the Overview, Categories, and Actions reports, where they are listed by event or aggregated across events, depending upon your report view.'),
+//   );
+  
+//   $form['attributes']['data_ga_noninteraction'] = array(
+//   	'#type' => 'hidden',
+//   	'#title' => t('Non-Interaction'),
+//   	'#default_value' => isset($instance['settings']['attributes']['data_ga_noninteraction']) ? $instance['settings']['attributes']['data_ga_noninteraction'] : "false",
+//   	'#options' => array("true" => t('True'), "false" => t('False')),
+//   	'#description' => t('Default value is false. By default, the event hit sent by _trackEvent() will impact a visitor\'s bounce rate. By setting this parameter to true, this event hit will not be used in bounce rate calculations. '),
+//   );
+  
   return $form;
 }
 
@@ -599,6 +649,14 @@
   if (!empty($element['attributes']['title'])) {
     $output .= '<div class="link-attributes">'. drupal_render($element['attributes']['title']) .'</div>';
   }
+
+  $output .= '<br /><div><div style="display:inline-block;margin-right:10px;">'. drupal_render($element['attributes']['data-ga-category']) .'</div>';
+  $output .= '<div style="display:inline-block;margin-right:10px;">'. drupal_render($element['attributes']['data-ga-action']) .'</div>';
+  $output .= '<div style="display:inline-block;margin-right:10px;">'. drupal_render($element['attributes']['data-ga-label']) .'</div></div><br />';
+
   return $output;
 }
 
@@ -677,6 +735,33 @@
       '#field_suffix' => '"',
     );
   }
+  
+	if (isset($settings['enable_ganalytics']) && $settings['enable_ganalytics']) {
+		$element['attributes']['data-ga-category'] = array(
+			'#type' => 'textfield',
+			'#title' => t('Category'),
+			'#default_value' => isset($attributes['data-ga-category']) ? $attributes['data-ga-category'] : '',
+			"#size" => 40
+		);
+		
+		$element['attributes']['data-ga-action'] = array(
+			'#type' => 'textfield',
+			'#title' => t('Action'),
+			'#default_value' => isset($attributes['data-ga-action']) ? $attributes['data-ga-action'] : '',
+			"#size" => 40
+		);
+		
+		$element['attributes']['data-ga-label'] = array(
+			'#type' => 'textfield',
+			'#title' => t('Label'),
+			'#default_value' => isset($attributes['data-ga-label']) ? $attributes['data-ga-label'] : '',
+			"#size" => 40
+		);
+	}
 
   // To prevent an extra required indicator, disable the required flag on the
   // base element since all the sub-fields are already required if desired.
