diff --git a/README b/README
index 5e97389..3744904 100644
--- a/README
+++ b/README
@@ -1,3 +1,5 @@
+PATCHED as per http://drupal.org/node/1197744#comment-5428216
+
 Google Analytics Statistics - @author jcaldwell aka jec006
 
 A Drupal 7 module that provides views integration for the Google Analytics Data Export API.
@@ -5,4 +7,13 @@ A Drupal 7 module that provides views integration for the Google Analytics Data
 This allows you to use Google Analytics directly through views to do things like Most Popular, Most Read ect.  
 You can combine the statistics to create interesting results.
 
-After you install the module - go to /admin/config/ga_stats to configure your Google Analytics account information and begin pulling statistics.
\ No newline at end of file
+After you install the module - go to /admin/config/ga_stats to configure your Google Analytics account information and begin pulling statistics.
+
+
+ *  patched as per
+ *  http://drupal.org/node/1197744#comment-5428216
+ 
+ *  updates as per...
+ *  http://drupal.org/node/1332240
+ *  http://drupalcode.org/project/ga_stats.git/commit/3d31a6d
+ 
diff --git a/ga_stats.info b/ga_stats.info
old mode 100755
new mode 100644
index 45272f3..87dbc6c
--- a/ga_stats.info
+++ b/ga_stats.info
@@ -1,4 +1,11 @@
-core = "7.x"
+core = "6.x"
 description = "Allows you to pull in data that Google Analytics has gathered for your site and use it in Views."
 name = "Google Analytics Statistics"
 package = "Statistics"
+
+; Information added by drupal.org packaging script on 2011-10-12
+version = "6.x-1.0-beta1"
+core = "6.x"
+project = "ga_stats"
+datestamp = "1318453907"
+
diff --git a/ga_stats.install b/ga_stats.install
index 178eccc..fc16e87 100755
--- a/ga_stats.install
+++ b/ga_stats.install
@@ -39,10 +39,10 @@ function ga_stats_schema() {
       ),
     ),
     'indexes' => array(
-      'ga_stats_metric'=>array('metric'), 
-      'ga_stats_timeframe'=>array('timeframe'),
-      'ga_stats_nid'=>array('nid')
-    ) 
+      'ga_stats_metric' => array('metric'),
+      'ga_stats_timeframe' => array('timeframe'),
+      'ga_stats_nid' => array('nid')
+    )
   );
   return $schema;
 }
@@ -51,7 +51,7 @@ function ga_stats_schema() {
  * Implementation of hook_install
  */
 function ga_stats_install() {
- 
+  drupal_install_schema('ga_stats');
 }
 
 /*
diff --git a/ga_stats.module b/ga_stats.module
index a309b95..e1c61ce 100755
--- a/ga_stats.module
+++ b/ga_stats.module
@@ -1,17 +1,17 @@
 <?php
   require_once('inc/ga.inc');
-  
+
   define('GA_ABBR', 'ga');
 /**
  * pull data from a source
  * @param $source_name : then name of the source from which to pull data
  * @param $metrics : an array or string of the metrics to pull
- * @param $time_frame : a time_frame obj 
+ * @param $time_frame : a time_frame obj
  * @param $end_time : the end time from which data is pulled
- * @return : an array of obj ready for the ga_stats_count table 
+ * @return : an array of obj ready for the ga_stats_count table
  */
 function ga_stats_get_data($metric, $start_time, $end_time, $timeframe='') {
-  $data_array = ga_stats_ga_data($metric,$start_time,$end_time);
+  $data_array = ga_stats_ga_data($metric, $start_time, $end_time);
   $metrics = ga_stats_ga_metrics();
   $counts = array();
   foreach ($data_array as $d) {
@@ -19,31 +19,31 @@ function ga_stats_get_data($metric, $start_time, $end_time, $timeframe='') {
     $count->url = $d['url'];
     $count->count = $d[$metric];
     $count->metric = $metric;
-    $count->nid = false;
+    $count->nid = FALSE;
     $count->timeframe = $timeframe;
-    $alias = preg_replace('/^\//','',$count->url);
-    if( !preg_match('/^node\/([0-9]*)/',$alias,$matches) ){
-      $alias = drupal_lookup_path('source',$alias);
+    $alias = preg_replace('/^\//', '', $count->url);
+    if (!preg_match('/^node\/([0-9]*)/', $alias, $matches) ) {
+      $alias = drupal_lookup_path('source', $alias);
     }
-    if( preg_match('/^node\/([0-9]*)/',$alias,$matches)  ){
+    if (preg_match('/^node\/([0-9]*)/', $alias, $matches)  ) {
       $count->nid = $matches[1];
     }
 
     // only log nodes
-    if($count->nid) {
+    if ($count->nid) {
       $counts[] = $count;
     }
   }
-  
+
   return $counts;
 }
 
 /**
  *  Implementation of hook_view_api
  */
-function ga_stats_views_api(){
+function ga_stats_views_api() {
   return array(
-    'api' => 2,
+    'api' => 3,
   );
 }
 
@@ -53,17 +53,18 @@ function ga_stats_views_api(){
  * TODO: May want to hook this up another way (drush?)
  */
 function ga_stats_cron() {
-  
-  if(!cache_get('ga_stats_data')){
+
+  if (!cache_get('ga_stats_data')) {
     $data = ga_stats_update_counts();
     //save the data for 10 or 30 minutes (based on whether hourly data is enabled
     $times = variable_get('ga_stats_enabled_timeframes', array('today', 'month'));
-    if(in_array('hour', $times)){
+    if (in_array('hour', $times)) {
       $add = 60*10;
-    } else {
+    }
+    else {
       $add = 60 * 30;
     }
-    
+
     cache_set('ga_stats_data', $data, 'cache', time()+$add);
   }
 }
@@ -80,24 +81,25 @@ function ga_stats_update_counts() {
   $user = variable_get('ga_stats_email', '');
   $password = variable_get('ga_stats_password', '');
   $aid = variable_get('ga_stats_profile', '');
-  
-  if($user && $password){
-    foreach ($metrics as $metric=>$title) {
-      foreach ($timeframes as $key=>$time){
-        $filter = isset($time['filter']) ? $time['filter'] : null;
+
+  if ($user && $password) {
+    foreach ($metrics as $metric => $title) {
+      foreach ($timeframes as $key => $time) {
+        $filter = isset($time['filter']) ? $time['filter'] : NULL;
         $new_data = ga_stats_get_data($metric, time()-$time['secsToSub'], time(), $key, $filter);
         $data= array_merge($data, $new_data);
       }
     }
-  
+
     db_query('DELETE FROM {ga_stats_count}');
     foreach ($data as $obj) {
       ga_stats_write_count($obj);
     }
-    drupal_set_message('Counts Successfully Updated');
+    drupal_set_message(t('Counts Successfully Updated'));
     return $data;
-  } else {
-    drupal_set_message('Google Analytics email and password not set.', 'error');
+  }
+  else {
+    drupal_set_message(t('Google Analytics email and password not set.'), 'error');
   }
 }
 
@@ -108,7 +110,7 @@ function ga_stats_update_counts() {
  */
 
 function ga_stats_menu() {
-  $items['admin/config/system/ga_stats'] = array(
+  $items['admin/settings/ga_stats'] = array(
     'title' => 'Google Analytics Statistics',
     'description' => 'Configuration for Google Analytics Statistics',
     'page callback' => 'drupal_get_form',
@@ -124,43 +126,47 @@ function ga_stats_menu() {
  */
 function ga_stats_admin_settings() {
   $form = array();
-  
+
   $form['ga_stats_login'] = array(
     '#type' => 'fieldset',
     '#title' => t('Google Analytics Login Information'),
     '#collapsible' => TRUE
   );
+  if (variable_get('ga_stats_email', FALSE)) {
+    $form['ga_stats_login']['#collapsed'] = TRUE;
+  }
+
   $form['ga_stats_login']['ga_stats_email'] = array(
     '#type' => 'textfield',
     '#title' => t('Account Email'),
     '#description' => t('The email account you use to log in to Google Analytics'),
     '#default_value' => variable_get('ga_stats_email', '')
   );
+
   $form['ga_stats_login']['ga_stats_password'] = array(
     '#type' => 'password',
     '#title' => t('Account Password'),
     '#description' => t('The password you use to log in to Google Analytics'),
-    '#default_value' => variable_get('ga_stats_password', '')
   );
-  
   $form['ga_stats_accounts'] = array(
     '#type' => 'fieldset',
     '#title' => t('Google Analytics Tracking Accounts'),
     '#collapsible' => TRUE
   );
-  if(variable_get('ga_stats_email', false) && variable_get('ga_stats_password', false)){
+  if (variable_get('ga_stats_email', FALSE) && variable_get('ga_stats_password', FALSE)) {
     $account = ga_stats_ga_get_accounts();
-  } else {
-    $account = false;
+  }
+  else {
+    $account = FALSE;
   }
   $options = array();
-  if(is_array($account)){
-    foreach($account as $id=>$value){
-      $acc = $value->getProperties();    
+  if (is_array($account)) {
+    foreach ($account as $id => $value) {
+      $acc = $value->getProperties();
       $options[$acc['profileId']] = $acc['title'];
     }
   }
-  if($options){
+  if ($options) {
     $form['ga_stats_accounts']['ga_stats_profile'] = array(
       '#type' => 'select',
       '#title' => t('Google Analytics Profile to Use'),
@@ -168,44 +174,45 @@ function ga_stats_admin_settings() {
       '#options' => $options,
       '#default_value' => variable_get('ga_stats_profile', '')
     );
-    
-  } else {
+
+  }
+  else {
     $form['ga_stats_accounts']['ga_stats_profile'] = array(
       '#type' => 'markup',
-      '#markup' => '<div class="messages warning">'.t('Email and Pasword not set or invalid.  Please set the login information and save this form. You will then be able to view and configure account information.').'</div>'
+      '#markup' => '<div class="messages warning">' . t('Email and Pasword not set or invalid. Please set the login information and save this form. You will then be able to view and configure account information.') . '</div>'
     );
   }
-  
+
   $form['enabled_stats'] = array(
     '#type' => 'fieldset',
     '#title' => t('Enabled Statistics'),
     '#description' => t('Make sure to clear the Drupal cache after changing this setting in order to inform Views of the new settings. <br/><em><b>WARNING:</b> Do not disable a setting which is currently in use in Views.</em>')
   );
-  
+
   $form['enabled_stats']['ga_stats_enabled_metrics'] = array(
-    '#type'=>'checkboxes',
-    '#default_value'=> variable_get('ga_stats_enabled_metrics', array('pageviews')),
+    '#type' => 'checkboxes',
+    '#default_value' => variable_get('ga_stats_enabled_metrics', array('pageviews')),
     '#options' => ga_stats_ga_metrics(true),
     '#title' => t('Metrics'),
     '#description' => t('The metrics that will be available from Google Analytics in Views.')
   );
-  
+
   $form['enabled_stats']['ga_stats_enabled_timeframes'] = array(
-    '#type'=>'checkboxes',
-    '#default_value'=> variable_get('ga_stats_enabled_timeframes', array('today', 'month')),
-    '#options' => ga_stats_ga_timeframes(true, true),
+    '#type' => 'checkboxes',
+    '#default_value' => variable_get('ga_stats_enabled_timeframes', array('today', 'month')),
+    '#options' => ga_stats_ga_timeframes(TRUE, TRUE),
     '#title' => t('Time Frames'),
     '#description' => t('The timeframes that will be available from Google Analytics in Views.')
   );
-  
+
   $form['ga_stats_max_results'] = array(
     '#type' => 'textfield',
     '#title' => t('Max Results per Metric/Timeframe'),
     '#description' => t('The max results that a call (a metric/timeframe combination) can return. MUST be a number.'),
     '#default_value' => variable_get('ga_stats_max_results', '100')
   );
-  
-  if(variable_get('ga_stats_profile', false)){
+
+  if (variable_get('ga_stats_profile', FALSE)) {
     $form['actions']['ga_stats_update'] = array(
       '#type' => 'button',
       '#value' => t('Update Counts'),
@@ -214,10 +221,19 @@ function ga_stats_admin_settings() {
       '#submit' => array('ga_stats_update_counts'),
     );
   }
-
+  $form['#validate'][] = 'ga_stats_form_validate';
   return system_settings_form($form);
 }
 
-function ga_stats_write_count($count){
+/**
+ *  Just set the password if we already have one and the form field was ignored.
+ */
+function ga_stats_form_validate($form, &$form_state) {
+  if (!$form_state['values']['ga_stats_password']) {
+    $form_state['values']['ga_stats_password'] = variable_get('ga_stats_password', '');
+  }
+}
+
+function ga_stats_write_count($count) {
   drupal_write_record('ga_stats_count', $count);
 }
\ No newline at end of file
diff --git a/ga_stats.views.inc b/ga_stats.views.inc
index 2d80507..6946802 100755
--- a/ga_stats.views.inc
+++ b/ga_stats.views.inc
@@ -12,18 +12,22 @@ function ga_stats_views_data() {
   $metrics = ga_stats_ga_metrics();
   
   foreach($metrics as $mk=>$mv){
+    
+    //this is used because views currently lowercases field names but we're getting camelCase from google.
+    $mkl = strtolower($mk); 
+    
     foreach($times as $tk=>$tv){
-      $data['ga_stats_count_'.$mk.'_'.$tk]['table']['group']  = t('Statistics');
-      $data['ga_stats_count_'.$mk.'_'.$tk]['table']['join']  = array(
+      $data['ga_stats_count_'.$mkl.'_'.$tk]['table']['group']  = t('Statistics');
+      $data['ga_stats_count_'.$mkl.'_'.$tk]['table']['join']  = array(
         'node' => array(
           'table' => 'ga_stats_count',
           'left_field' => 'nid',
           'field' => 'nid',
           'type' => 'LEFT OUTER',
-          'extra' => 'ga_stats_count_'.$mk.'_'.$tk.'.metric=\''.$mk.'\' AND ga_stats_count_'.$mk.'_'.$tk.'.timeframe=\''.$tk.'\''
+          'extra' => 'ga_stats_count_'.$mkl.'_'.$tk.'.metric=\''.$mk.'\' AND ga_stats_count_'.$mkl.'_'.$tk.'.timeframe=\''.$tk.'\''
         )
       );
-      $data['ga_stats_count_'.$mk.'_'.$tk]['count'] = array(
+      $data['ga_stats_count_'.$mkl.'_'.$tk]['count'] = array(
         'title' => t("$mv $tv"),
         'help' => t('Information retrieved from Google Analytics'),
         'field' => array(
@@ -40,4 +44,4 @@ function ga_stats_views_data() {
   }
    
   return $data;
-}
\ No newline at end of file
+}
diff --git a/inc/ga.inc b/inc/ga.inc
index d6b022b..f5b0edc 100755
--- a/inc/ga.inc
+++ b/inc/ga.inc
@@ -8,7 +8,7 @@
  *  @return : and array of external_statistics_count db obj
  *
  */
-function ga_stats_ga_data($metrics, $start_date = 0, $end_date = 0, $filter=false) {
+function ga_stats_ga_data($metrics, $start_date = 0, $end_date = 0, $filter=FALSE) {
   $url_dim = 'pagePath';
   if (!is_array($metrics)) {
    $metrics = array($metrics);
@@ -16,26 +16,26 @@ function ga_stats_ga_data($metrics, $start_date = 0, $end_date = 0, $filter=fals
   $request['dimensions'] = array($url_dim);
   $request['metrics'] = $metrics;
   
-  if($start_date)
+  if ($start_date)
     $request['start_date'] = date('Y-m-d', $start_date);
   else
-    $request['start_date'] = null;
+    $request['start_date'] = NULL;
     
-  if($end_date)
+  if ($end_date)
     $request['end_date'] = date('Y-m-d', $end_date);
   else
-    $request['end_date'] = null;
+    $request['end_date'] = NULL;
   
-  $request['sort_metric'] = "-".$metrics[0];
+  $request['sort_metric'] = "-" . $metrics[0];
   $request['max_results'] = variable_get('ga_stats_max_results', "100");
   
-  if($filter){
+  if ($filter) {
     $request['filter'] = $filter;
   }
   
   $data_raw = ga_stats_query_data($request);
   $data_array = ga_stats_ga_data_array($data_raw);
-  foreach($data_array as $k=>$d) {
+  foreach ($data_array as $k => $d) {
     $data_array[$k]['url'] = $d[$url_dim];
   }
   
@@ -45,19 +45,19 @@ function ga_stats_ga_data($metrics, $start_date = 0, $end_date = 0, $filter=fals
 /*
  * Helper function to list metrics with plugin names and google analytics names
  */
-function ga_stats_ga_metrics($all=false) {
+function ga_stats_ga_metrics($all=FALSE) {
   
   $metrics = array(
-    'pageviews'=>'Page Views',
-    'uniquePageviews'=>'Unique Page Views',
-    'avgTimeOnPage'=>'Average Time on Page',
-    'entrances'=>'Entrance Page'
+    'pageviews' => 'Page Views',
+    'uniquePageviews' => 'Unique Page Views',
+    'avgTimeOnPage' => 'Average Time on Page',
+    'entrances' => 'Entrance Page'
   );
   
-  if(!$all){
+  if (!$all) {
     $enabled = variable_get('ga_stats_enabled_metrics', array('pageviews'));
-    foreach($metrics as $k=>$v){
-      if(!$enabled[$k]){
+    foreach ($metrics as $k => $v) {
+      if (!isset($enabled[$k]) || !$enabled[$k]) {
         unset($metrics[$k]);
       }
     }
@@ -65,33 +65,37 @@ function ga_stats_ga_metrics($all=false) {
   
   return $metrics;
 }
+
 /**
  *  @param $just_keys : whether we should return all the data or just the keys->values array
  *  TODO: add forever
  */
-function ga_stats_ga_timeframes($just_keys=false, $all=false){
-  if($just_keys){
+function ga_stats_ga_timeframes($just_keys=FALSE, $all=FALSE) {
+  if ($just_keys) {
     $timeframes = array(
       'hour' => 'in the past hour',
       'today' => 'in the past 24 hours',
+      '2days' => 'in the past 48 hours',
       'week' => 'in the past 7 days',
       'month' => 'in the past 31 days',
       'forever' => 'for all time'
     );
-  } else {
+  }
+  else {
     $timeframes = array(
-      'hour'=>array('secsToSub'=>(60*60), 'filter'=>'hour=='+date('G'), 'title'=>'in the past hour'),
-      'today'=>array('secsToSub'=>(60*60*24), 'filter'=>'day=='+date('j'), 'title'=>'in the past 24 hours'),
-      'week'=>array('secsToSub'=>(60*60*24*7), 'title'=>'in the past 7 days'),
-      'month'=>array('secsToSub'=>(60*60*24*31), 'title'=>'in the past 31 days'),
-      'forever'=>array('secsToSub'=>time() - strtotime('2005-01-01'), 'title'=>'for all time')
+      'hour' => array('secsToSub' => (60*60), 'filter' => 'hour=='+date('G'), 'title' => 'in the past hour'),
+      'today' => array('secsToSub' => (60*60*24), 'filter' => 'day=='+date('j'), 'title' => 'in the past 24 hours'),
+      '2days' => array('secsToSub' => (60*60*24*2), 'title' => 'in the past 48 hours'),
+      'week' => array('secsToSub' => (60*60*24*7), 'title' => 'in the past 7 days'),
+      'month' => array('secsToSub' => (60*60*24*31), 'title' => 'in the past 31 days'),
+      'forever' => array('secsToSub' => time() - strtotime('2005-01-01'), 'title' => 'for all time')
     );
   }
   
-  if(!$all){
+  if (!$all) {
     $enabled = variable_get('ga_stats_enabled_timeframes', array('today', 'month'));
-    foreach($timeframes as $k=>$v){
-      if(!$enabled[$k]){
+    foreach ($timeframes as $k => $v) {
+      if (!isset($enabled[$k]) || !$enabled[$k]) {
         unset($timeframes[$k]);
       }
     }
@@ -112,25 +116,26 @@ function ga_stats_ga_data_array($data_in) {
   return $data_all;
 }
 
-function ga_stats_ga_get_accounts(){
+function ga_stats_ga_get_accounts() {
   require_once 'gapi.class.php';
   
   $user = variable_get('ga_stats_email', '');
   $password = variable_get('ga_stats_password', '');
     
-  if($user && $password){
+  if ($user && $password) {
     try{
       $ga = new gapi($user, $password);
-      $accounts = $ga->requestAccountData(); 
+      $accounts = $ga->requestAccountData(1, 5000); 
       return $accounts;
     } catch (Exception $e) {
-      drupal_set_message('Invalid Google Analytics login.', 'error');
+      drupal_set_message(t('Invalid Google Analytics login.'), 'error');
       watchdog('ga_stats', 'Invalid Google Analytics login.');
       return;
     }    
-  } else {
+  }
+  else {
     drupal_set_message(t('Google Analytics Email and password not set - Could not retrieve Account Information.'), 'error');
-    watchdog('ga_stats', t('Google Analytics email and password not set.'));
+    watchdog('ga_stats', 'Google Analytics email and password not set.');
   }
 }
 
@@ -139,7 +144,7 @@ function ga_stats_ga_get_accounts(){
  *  $report_id, $dimensions, $metrics, $sort_metric=null, $filter=null, $start_date=null, $end_date=null, $start_index=1, $max_results=30
  */
 
-function ga_stats_query_data($request){
+function ga_stats_query_data($request) {
   //this is really a waste I think because this shit is preprocessed
   require_once 'gapi.class.php';
   
@@ -147,18 +152,19 @@ function ga_stats_query_data($request){
   $password = variable_get('ga_stats_password', '');
   $aid = variable_get('ga_stats_profile', '');
   
-  if($user && $password){
+  if ($user && $password) {
     try{
       $ga = new gapi($user, $password);
-      $data = $ga->requestReportData($aid, $request['dimensions'], $request['metrics'], $request['sort_metric'], null, $request['start_date'], $request['end_date'], 1, $request['max_results']);
+      $data = $ga->requestReportData($aid, $request['dimensions'], $request['metrics'], $request['sort_metric'], NULL, $request['start_date'], $request['end_date'], 1, $request['max_results']);
     } catch (Exception $e) {
-      drupal_set_message('Invalid Google Analytics login.', 'error');
+      drupal_set_message(t('Invalid Google Analytics login.'), 'error');
       watchdog('ga_stats', 'Invalid Google Analytics login.');
       return array();
     }    
     return $data;    
-  } else {
-    drupal_set_message('Google Analytics Email and password not set.', 'error');
+  }
+  else {
+    drupal_set_message(t('Google Analytics Email and password not set.'), 'error');
     watchdog('ga_stats', 'Google Analytics email and password not set.');
   }
 }
\ No newline at end of file
diff --git a/inc/gapi.class.php b/inc/gapi.class.php
index 61a0377..cc1e0f7 100755
--- a/inc/gapi.class.php
+++ b/inc/gapi.class.php
@@ -400,14 +400,22 @@ class gapi
    */
   protected function authenticateUser($email, $password)
   {
+	// Updated by jec006 to handle apps accounts also
+	if( stristr($email, 'gmail.com') || stristr($email, 'mail.google.com') ) {
+		$type = 'GOOGLE';
+	} else {
+		$type = 'HOSTED';
+	}
+	
     $post_variables = array(
-      'accountType' => 'GOOGLE',
+      'accountType' => $type,
       'Email' => $email,
       'Passwd' => $password,
       'source' => gapi::interface_name,
       'service' => 'analytics'
     );
-    
+    // end jec006 mod
+
     $response = $this->httpRequest(gapi::client_login_url,null,$post_variables);
     
     //Convert newline delimited variables into url format then import to array
